On 11/05/2010 05:33 PM, Caleb James DeLisle wrote:
> Yes, Hibernate disallows the update keyword in a search, it would be a pretty 
> big security hole if I
> could just use a searchDocuments command to update the admin group to add 
> myself.
> The way to do this is either get the document, make the change and then save 
> the document, or if you
> need to do a lot of documents really fast then you can get updates if you 
> have programming right.
>
> Caleb
>
> On 11/05/2010 12:20 PM, tapaya wrote:
>>
>> I can't use 'update' in HQL expressions in Velocity scripts. Stack trace:
>>
>>
>> org.xwiki.rendering.macro.MacroExecutionException: Failed to evaluate
>> Velocity Macro for content [{{html wiki="true"}}
>>
>> {{velocity filter="indent"}}
>> #set($searchDocumentsQuery="update XWikiDocument doc set doc.title='asdf
>> poiu quer' where doc.fullName='tst-2010-11-03-lIqw'")
>> #set($results=$xwiki.search($searchDocumentsQuery))
>> {{/velocity}}
>>
>>
>> Am I missing something?

As Caleb said, search and searchDocuments can only be used for read 
operations. If you really want to do update operations, you can get hold 
of a real database connection going through 
$xwiki.getXWiki().getNotCacheStore(), or through Groovy scripting, but 
it is really, really not recommended. If you want to update the standard 
XWiki data model (documents, objects, classes...), then you should use 
the public APIs for manipulating them, and then call the safe 
$doc.save() method. If you want to update other data than the XWiki 
standard tables, you should use the sql plugin (see 
http://code.xwiki.org/xwiki/bin/view/Plugins/XWikiSqlPlugin for more 
details).

In your example you're trying to set a document's parent, and this can 
be simply done as:

#set($someDoc = $xwiki.getDocument('tst-2010-11-03-lIqw'))
$someDoc.setTitle('asd poiu quer')
$someDoc.save()

-- 
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to