Delete Space Snippet

Code that lists all spaces in a wiki and provides links to delete each space.

Warning: The deletion of a space cannot be reverted. Use this at your own risk. Note that since XWiki 1.2 it's possible to revert page deletions, but one by one only.

Code

1 Delete Space

#if ($request.space)
  #if ($request.confirm == "1")
    #foreach ($item in $xwiki.getSpaceDocsName($request.space))
      * Deleting $item $xwiki.getDocument("${request.space}.${item}").delete()
    #end
  #else
    [Confirm delete space ${request.space}>$doc.fullName?space=${request.space}&confirm=1]

    1.1 List of docs that will be deleted

    #foreach ($item in $xwiki.getSpaceDocsName($request.space))
      * $item
    #end
  #end
#else
  {table}
    Space | Action
    #foreach($space in $xwiki.spaces)
      $space | [Index>Main.SpaceIndex?space=${space}] - [Delete>$doc.fullName?space=${space}]
    #end
  {table}
#end

Result

deletespaces.png deletespaces2.png

Version 5.8 last modified by VincentMassol on 17/12/2007 at 13:19

Comments 7

melv | 26.01.2007 at 02:08 PM
Hi,

I've tested this script in the Sandbox, but it doesn't work. I get a NPE when trying to delete the space ToBeDeleted: http://sandbox.xwiki.org/xwiki/bin/view/MyTestSpace/


VincentMassol | 26.01.2007 at 09:39 PM
Melv, you'll need the delete right to be allowed to delete a page. However it shouldn't return a NPE, that's a bug. Please raise a bug on JIRA. Thanks

melvng | 27.01.2007 at 03:33 PM
Done. BTW, I was logged in as 'Admin'. It's all in the jira issue :)

XWiki is very cool and I'm looking forward to the next beta. Keep up the great work :)


thelwyn | 21.05.2007 at 05:53 PM
Hello,

I've tried to use this snippet (a bit modified) to delete a few hundreds pages and i get an NPE too, which causes that in my "delete loop" only the first item is deleted. The loop then stops and throws the exception.

Do you see any trick i can still use to delete lots of pages in a loop?


VincentMassol | 21.05.2007 at 09:40 PM
Hi,

I've just tried it. It worked for me. I'm logged as Admin. You have to be careful when you copy paste as new lines are removed. That's an issue we need to fix.

Thanks -Vincent


thelwyn | 22.05.2007 at 11:40 AM
Hi,

By the way the snippet is working for me too.

I've just modified the code to delete pages got from an sql request. It has worked to delete pages from a space (get with some doc.web="something" request and some others conditions) but it doesn't in another case when trying to delete XWikiServer pages (in a virtualization case). Yet my sql request is ok (i display the result without problem), but the deletion fails.

Could it come from the nature of the pages (from XWikiServerClass)? At the moment I don't understand why i get the NPE only in the second case. And I wrote the code, didn't copy-paste it in the 2 cases.

I'm of course doing it as admin, but on an 0.9** version..

Thanks! Nicolas


DieterStrecker | 17.12.2007 at 09:12 AM
Hi

Using the snippet I get an error message while executing the delete statement. The reference to the item that has to be deleted is not valid.

Can anybody help?

Thank you, Dieter

Attachments 2

Image
deletespaces2.png 1.1
PostedBy: VincentMassol on 09/12/2007 (29kb )
Image
deletespaces.png 1.1
PostedBy: VincentMassol on 09/12/2007 (29kb )

Creator: VincentMassol on 2007/01/12 17:31
This wiki is licensed under a Creative Commons license
1.4.1.10194