createDocument() overwrites XWiki.WebHome?????

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

createDocument() overwrites XWiki.WebHome?????

Esbach, Brandon
createDocument() overwrites XWiki.WebHome?????

Hi,

I've had a request from one of my users to create a script on our hosted wiki that will create all the needed wiki content for one of their lists. 

  • Problem 1, there is over 2000 xwiki documents to create from this list
  • Problem 2, they're a little anxious to get it going

I've tried using the $xwiki.createDocument in the underneath code (most likely more saves than necessary). 
What seems to be happening is this:

  • Does not create a new document, attaches instead to XWiki.WebHome
  • All following changes occur to XWiki.Webhome - including rename.

Origionally had it saving after each change, no difference.

#set($seedForUnique=$xwiki.formatDate($xwiki.currentDate, "HHmmssddMMyyyy"))
#set($userUnique=$context.user.replace("XWiki.", ""))
#set($generatedUnique="${userUnique}${seedForUnique}")
#set($baseAVLClass='XWiki.AVLEntryClass')
#set($baseSupplierClass='XWiki.VendorClass')
#set($newSupplierPartClass='XWiki.AVLVendorClass')

#set($newDocument=$xwiki.createDocument())
$newDocument.rename($generatedUnique)
$newDocument.setContent('#includeForm("AVL.VendorClassSheet")')
$newDocument.createNewObject('${baseSupplierClass}')
$newDocument.save()
#set($docObj=$newDocument.getObject('${baseSupplierClass}', 0))
$docObj.set('name', 'Samsung')
$docObj.set('email', '')
$newDocument.save()

I would guess I'm not doing a crucial step (or doing that step wrong)?
Better suggestions welcome too :)


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: createDocument() overwrites XWiki.WebHome?????

Sergiu Dumitriu-2
Esbach, Brandon wrote:

> Hi,
>
> I've had a request from one of my users to create a script on our hosted
> wiki that will create all the needed wiki content for one of their lists.
>
>     * Problem 1, there is over 2000 xwiki documents to create from this list
>     * Problem 2, they're a little anxious to get it going
>
> I've tried using the $xwiki.createDocument in the underneath code (most
> likely more saves than necessary).
> What seems to be happening is this:
>
>     * Does not create a new document, attaches instead to XWiki.WebHome
>     * All following changes occur to XWiki.Webhome - including rename.
>
> Origionally had it saving after each change, no difference.
>
> #set($seedForUnique=$xwiki.formatDate($xwiki.currentDate,
> "HHmmssddMMyyyy"))
> #set($userUnique=$context.user.replace("XWiki.", ""))
> #set($generatedUnique="${userUnique}${seedForUnique}")
> #set($baseAVLClass='XWiki.AVLEntryClass')
> #set($baseSupplierClass='XWiki.VendorClass')
> #set($newSupplierPartClass='XWiki.AVLVendorClass')
>
> #set($newDocument=$xwiki.createDocument())
> $newDocument.rename($generatedUnique)
> $newDocument.setContent('#includeForm("AVL.VendorClassSheet")')
> $newDocument.createNewObject('${baseSupplierClass}')
> $newDocument.save()
> #set($docObj=$newDocument.getObject('${baseSupplierClass}', 0))
> $docObj.set('name', 'Samsung')
> $docObj.set('email', '')
> $newDocument.save()
>
> I would guess I'm not doing a crucial step (or doing that step wrong)?
> Better suggestions welcome too :)
>
>

You never need to createDocuments in XWiki. The Javadoc for that method
is wrong. Just replace:

#set($newDocument=$xwiki.createDocument())
$newDocument.rename($generatedUnique)

with:

#set($newDocument = $xwiki.getDocument($generatedUnique)

Even better, you can use $xwiki.generateRandomString(int size)

(this method was deprecated in 1.3M2, as it has moved to
$util.generateRandomString(int size)

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