Reinitialize Sandbox Application

Last modified by Pascal Bastien on 2021/03/17 21:43

cogReinitializes the SandBox space by using a SandBox space template
TypeXAR
Category
Developed by

Pascal Bastien

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

Provides an application to reinitialize periodically the SandBox space by overwriting it with clean pages located in another space.

This application provides the following:

  • A page to launch manually (and/or by scheduler) the SandBox reinitialisation, in SandboxTemplate.ReinitSandboxMacro
  • A template space of Sandbox (i.e. list of clean Sandbox pages):
    • SandboxTemplate.WebHome (all languages are present)
    • SandboxTemplate.TestPage1
    • SandboxTemplate.TestPage2
    • SandboxTemplate.TestPage3
  • Configured to forbid access to the SandboxTemplate space for XWikiAllGroup and Unregistered Users (SandboxTemplate.WebPreferences)
  • A Scheduler job to launch automatically the reinitialisation, in Scheduler/Reinit Sandbox from SandboxTemplate

If you click on "Reinitialisation of Sandbox space (without confirmation)" in SandboxTemplate.ReinitSandboxMacro, the macro will

  • erase ALL Sandbox space pages
  • overwrite Sandbox by this space SandboxTemplate
  • and unhide Sandbox space

Of course, it is recommended to backup your Sandbox space before and test with this link: "Mode Debug: 'Reinitialisation of Sandbox space' (without modification)"

With 1.1 version, it is possible to reinitialize periodically another space (rather than Sandbox) by overwriting it with an another space (rather than SandboxTemplate): to manipulate with caution!.

ReinitSandbox_main.png

Addon:

To empty old Sandbox pages deleted from Trash bin, you can add this piece of code in scheduler task:
// set to 1 if you want to empty the trash bin for the whole wiki
def emptybin = 1
// Empty old Sandbox pages deleted from Trash bin
def query = "select distinct ddoc.fullName from XWikiDeletedDocument as ddoc where ddoc.fullName like 'Sandbox.%'"

def trashed = xwiki.search(query)
if(trashed.size() > 0) {
 def deleted = 0
 println "<strong>Trashed documents:</strong>\n"
for(trash in trashed) {
   println "" + trash + " (" + xwiki.getDeletedDocuments(trash, "").size() + " versions)"
  if (emptybin == 1)
      xwiki.getDeletedDocuments(trash, "").each{
        xwiki.getXWiki().getRecycleBinStore().deleteFromRecycleBin(
            xwiki.getDocument(it.fullName).document,
            it.getId(),
            context,
           true);
        deleted++;
       }
  }
if (emptybin == 1) println "\nDeleted <strong>" + deleted + "</strong> trashed document. Trash bin is now empty."
}
else println "Everything's clean. No trashed document found."

Know bugs:

  • English translation to be improved... :-)
  • copy from SanboxTemplate.WebHome copies only one language (because of copyDocument function limitation) (fixed by 1.0 version)

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

By default the macro is not scheduled. You must schedule it and choose periodicity in ... scheduler.

Release Notes

v1.1

Version 1.1: Add source (name of template space) and target (name of space to overwrite) parameter + copy all documents languages of Sandbox
Version 1.0 (fixing multilingual problem and missing attachments and use xwiki 2.1 syntax)
Version 0.9 (Initial version)

Get Connected