Change Content Author

Version 14.1 by Eduard Moraru on 2018/07/12 14:35

user_goModifies all existing documents in the current wiki that have set the old user as content author and use the new user as content author instead.
TypeXAR
CategoryApplication
Developed by

Eduard Moraru

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

Modifies all existing documents in the current wiki that have set the old user as content author and use the new user as content author instead.

This will remove from the modified documents the rights of the old user and grant them the rights of the new user instead. This is mostly applicable for Programming and Script rights.

Note: To list the content author users you can use the List Deleted Content Author Users application.

Requires Programming Rights to function.

Step1:
changeContentAuthorStep1.png

Step2:
changeContentAuthorStep2.png

Step3:
changeContentAuthorStep3.png

Source

Below is the source to copy/paste in a new document in your XWiki instance, in case you can/will not use Extension Manager or direct XAR import to install it.

{{velocity}}
#if ("$!request.oldContentAuthorUser" != '' && "$!request.newContentAuthorUser" != '')
  #set ($documentsToUpdateQuery = "where doc.contentAuthor=:oldContentAuthorUser")
  #set ($documentsToUpdate = $services.query.xwql($documentsToUpdateQuery).bindValue('oldContentAuthorUser', $request.oldContentAuthorUser).execute())
  #set ($newContentAuthorUserReference = $services.model.resolveDocument($request.newContentAuthorUser))

  #if ($request.confirm == 'true')
    #foreach ($documentToUpdate in $documentsToUpdate)
      #set ($document = $xwiki.getDocument($documentToUpdate))
      #set ($discard = $document.document.setContentAuthorReference($newContentAuthorUserReference))
      #set ($discard = $xwiki.xWiki.saveDocument($document.document, "Changed content author", $xcontext.context))
     * [[$documentToUpdate]] ($documentToUpdate) - (/)
    #end
   
   Done.

    {{html}}
   <a class='button' href="$doc.getURL()">Back to main screen</a>
    {{/html}}
  #else
   Documents to update ($documentsToUpdate.size() total) using [[$newContentAuthorUserReference]] ($request.newContentAuthorUser) as new content author:
    #foreach ($documentToUpdate in $documentsToUpdate)
     * [[$documentToUpdate]] ($documentToUpdate)
    #end

    {{html}}
   <form class='xform'>
     <dl>
       <dt>
         <input type='hidden' name='oldContentAuthorUser' value="$escapetool.xml($request.oldContentAuthorUser)" />
         <input type='hidden' name='newContentAuthorUser' value="$escapetool.xml($request.newContentAuthorUser)" />
         <input type='hidden' name='confirm' value='true' />
          #if ($documentsToUpdate.size() > 0)
           <input class='button' type='submit' value='Confirm' />
          #end
         <a class='button secondary' href="$doc.getURL()">Cancel</a>
       </dt>
     </dl>
   </form>
    {{/html}}
  #end
#else
Modify all existing documents in the current wiki that have set the old user as content author and use the new user as content author instead.

This will remove from the modified documents the rights of the old user and grant them the rights of the new user instead. This is mostly applicable for Programming and Script rights.

The next step displays the list of documents that will be modified and will ask for confirmation.

This page requires Programming Rights to function.

 {{html}}
<form class='xform'>
  <dl>
    <dt><label>Old content author user</label></dt>
    <dd><input type='text' name='oldContentAuthorUser' value="#if($request.oldContentAuthorUser)$escapetool.xml($request.oldContentAuthorUser)#end" /></dd>
    <dt><label>New content author user</label></dt>
    <dd><input class='suggestUsers' type='text' name='newContentAuthorUser' value="#if($request.newContentAuthorUser)$escapetool.xml($request.newContentAuthorUser)#{else}$xcontext.user#end" /></dd>
    <dt>
      <input type='submit' class='button' value='Change...' />
    </dt>
   </dl>
</form>
 {{/html}}
#end
{{/velocity}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v1.2

  • Fixed yet another bug when saving the document for which the contentAuthor field was changed.

v1.1

  • Fixed a bug in the published version when the document was saved.
Tags:
    

Get Connected