@Override public void installOrUpgradeWikiMacroClasses() throws Exception { XWikiContext xcontext = getContext(); // Install or Upgrade XWiki.WikiMacroClass XWikiDocument doc = xcontext.getWiki().getDocument(this.wikiMacroInitializer.getDocumentReference(), xcontext); if (this.wikiMacroInitializer.updateDocument(doc)) { update(doc); } // Install or Upgrade XWiki.WikiMacroParameterClass doc = xcontext.getWiki().getDocument(WIKI_MACRO_PARAMETER_CLASS, xcontext); if (this.wikiMacroParameterInitializer.updateDocument(doc)) { update(doc); } }
@Override public void onEvent(Event event, Object source, Object data) { DocumentReference annotationClassReference = this.configuration.getAnnotationClassReference(); try { if (!this.configuration.isInstalled()) { // If the Annotations Application is not installed on the current wiki, do nothing. return; } XWikiContext deprecatedContext = this.xcontextProvider.get(); XWikiDocument annotationClassDocument = deprecatedContext.getWiki().getDocument(annotationClassReference, deprecatedContext); if (this.initializer.updateDocument(annotationClassDocument)) { deprecatedContext.getWiki().saveDocument(annotationClassDocument, "Automatically added missing annotation class fields required by the Annotation Application.", deprecatedContext); } } catch (Exception e) { this.logger.error("Failed to update the configured annotation class [{}]", annotationClassReference, e); } } }
/** * @param context the context to use. Since everything happens in the same thread, it's safe to assume that this is * the request's context and not a synthetic one. */ private void reinitializeWatchListClass(XWikiContext context) { String currentWikiId = context.getWikiId(); try { // Reinitialize on all wikis. for (String wikiId : wikiDescriptorManager.getAllIds()) { try { context.setWikiId(wikiId); XWikiDocument document = context.getWiki().getDocument(watchListClassInitializer.getDocumentReference(), context); if (watchListClassInitializer.updateDocument(document)) { context.getWiki().saveDocument(document, context); } } catch (XWikiException e) { logger.error("Failed to re-initialize mandatory document [{}] on wiki [{}]", WatchListClassDocumentInitializer.DOCUMENT_FULL_NAME, wikiId, e); } } } catch (Exception e) { logger.error("Failed to re-initialize mandatory document [{}]", WatchListClassDocumentInitializer.DOCUMENT_FULL_NAME, e); } finally { // Restore the contex wiki. context.setWikiId(currentWikiId); } }