cogReplace some content string with another string
Developed by

Vincent Massol

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

{{velocity}}
#set ($search = "some word")
#set ($replacement = "other word")
#set ($xwql = "where doc.content like :search and doc.fullName <> :current")
#foreach ($item in $services.query.xwql($xwql).bindValue('search', "%${search}%").bindValue('current', $doc.fullName).execute())
  #if ($request.confirm == "1")
    #set ($itemDoc = $xwiki.getDocument($item))
    $itemDoc.setContent($itemDoc.getContent().replaceAll($search, $replacement))
    $itemDoc.save("Replaced '${search}' by '${replacement}'")
    * [[$item>>$item]] replaced!
  #else
    * [[$item>>$item]]
  #end
#end

[[Replace "$search" by "$replacement">>||queryString='confirm=1']]
{{/velocity}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Tags:
Created by Vincent Massol on 2019/03/28 11:01
     

Get Connected