@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); } }
@Test public void extractWhenWikiDescriptorButEmptyServerName() throws Exception { setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI); WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); when(wikiDescriptorManager.getByAlias("someWiki")) .thenReturn(new WikiDescriptor("", "someWiki")); testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "xwiki"); }
@Before public void setUp() throws Exception { WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki"); }
@Override public boolean shouldExecute(XWikiDBVersion startupVersion) { // We migrate only subwikis return !wikiDescriptorManager.getCurrentWikiId().equals(wikiDescriptorManager.getMainWikiId()); }