Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-10175

Installing an extension programatically and preserving xar author causes author to be set to guest for overwritten documents

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    Description

      My purpose is to install an extension programatically, non-interactive and synchronous. So I use the following groovy code, which sleeps in a loop, waking up from time to time and answering EM questions with "install new version of the page" for all pages where there is conflict.

      Everything works fine for new pages (authors of pages from the xar are preserved), but when a page actually gets overwritten (it exists before the install and should get completely overwritten with the extension version after), the page's author and contentAuthor after the install are XWiki.XWikiGuest.

      Code is here (extensionManager is previously set to $services.extension from the velocity calling this groovy):

            String extensionNamespace = 'wiki:' + wikiname;
            def installJobStatus = null;
            // prepare the install request
            def installRequest = extensionManager.createInstallRequest(extensionId, extensionVersion, extensionNamespace);
            // preserve the author of the documents in the extension
            installRequest.removeProperty('user.reference');
            // start the install
            def installJob = extensionManager.install(installRequest);
            installJobStatus = installJob.getStatus();
            // sleep loop to wake up and check if there are questions from time to time, to answer them with the default answer
            while (installJobStatus.getState() != JobStatus.State.FINISHED) {
              // sleep 1 second
              sleep(1000);
              // if the state is waiting, answer the question and continue
              if (installJobStatus.getState() == JobStatus.State.WAITING) {
                def question = installJobStatus.getQuestion();
                log('INFO', "Extension " + extensionId + " on namespace " + extensionNamespace + " has stopped in state Waiting with question " + question.class.getName() + " for document " + question.getNextDocument().getPrefixedFullName());
                // answer the question and set always
                installJobStatus.getQuestion().setGlobalAction(ConflictQuestion.GlobalAction.NEXT);
                // answer this for all documents from now on
                installJobStatus.getQuestion().setAlways(true);
                // and continue running the job
                installJobStatus.answered();
              }
            }
      

      Attachments

        Activity

          People

            tmortagne Thomas Mortagne
            lucaa Anca Luca
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: