Hi all,
I’m starting with a new xwiki installation, I’m newbie with scripting and I have to add to a number of selected document a tag; trying with velocity I’ve done this, but it’s non making the job:
{{velocity}}
#set ($query = "My document name")
#set ($hql = "select doc.fullName from XWikiDocument as doc where lower(doc.title) like lower(:title)")
#set ($results = $services.query.hql($hql).bindValue("title", "%$query%").execute())
#set ($tagToAdd = "Updated")
#set ($updatedCount = 0)
#set ($skippedCount = 0)
#if ($results.size() > 0)
<ul>
#foreach ($docFullName in $results)
#set ($doc = $xwiki.getDocument($docFullName))
#set ($tags = $doc.getTags())
#if (!$tags.contains($tagToAdd))
#set ($update = $wiki.tag.addTagToDocument($tagToAdd, $doc))
#set ($saved = $xwiki.saveDocument($doc, "TAG $tagToAdd added"))
#set ($updatedCount = $updatedCount + 1)
$doc.getTitle() - Tag added
#else
#set ($skippedCount = $skippedCount + 1)
$doc.getTitle() - Tag is present
#end
#end
</ul>
<p>Updated $updatedCount</p>
<p>Jumped: $skippedCount</p>
#else
<p>No pages found with "$query"</p>
#end
{{/velocity}}
Any suggestion?