@Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { // Context, XWiki XWikiContext context = getXWikiContext(); XWiki xwiki = context.getWiki(); // Current wiki String currentWikiId = wikiDescriptorManager.getCurrentWikiId(); // Get the old wiki descriptor DocumentReference oldWikiDescriptorReference = new DocumentReference( wikiDescriptorManager.getMainWikiId(), XWiki.SYSTEM_SPACE, String.format("XWikiServer%s", StringUtils.capitalize(currentWikiId))); XWikiDocument oldWikiDescriptor = xwiki.getDocument(oldWikiDescriptorReference, context); // Try to get the old workspace object DocumentReference oldClassDocument = new DocumentReference( wikiDescriptorManager.getMainWikiId(), WORKSPACE_CLASS_SPACE, WORKSPACE_CLASS_PAGE); BaseObject oldObject = oldWikiDescriptor.getXObject(oldClassDocument); // Upgrade depending of the type if (oldObject != null || isWorkspaceTemplate(currentWikiId)) { // It's a workspace upgradeWorkspace(oldObject, currentWikiId, oldWikiDescriptor); } else { // It's a regular subwiki upgradeRegularSubwiki(currentWikiId); } }
@Override public boolean shouldExecute(XWikiDBVersion startupVersion) { // We migrate only subwikis return !wikiDescriptorManager.getCurrentWikiId().equals(wikiDescriptorManager.getMainWikiId()); }