Skip to content
Snippets Groups Projects
Unverified Commit 036a4980 authored by Simon Urli's avatar Simon Urli Committed by GitHub
Browse files

XWIKI-22101: WatchListClass is not properly migrated for subwiki users (#3070)

  * Ensure to use proper WikiReference when resolving user document
    reference
  * Provide some more logs to perform migration of users
  * Move the migration so that it's executed in recent version of XS
  * Put forgotten unstable annotations on migrations
parent 8c322f1a
No related branches found
No related tags found
No related merge requests found
Showing
with 76 additions and 27 deletions
...@@ -138,7 +138,19 @@ ...@@ -138,7 +138,19 @@
Single justification example: Single justification example:
--> -->
<revapi.differences>
<justification>
This should have been internal or at least marked unstable. Also, this class was only moved.
</justification>
<criticality>allowed</criticality>
<differences>
<item>
<ignore>true</ignore>
<code>java.class.removed</code>
<old>class org.xwiki.notifications.filters.migration.R160000000XWIKI17243DataMigration</old>
</item>
</differences>
</revapi.differences>
......
...@@ -27,6 +27,6 @@ ...@@ -27,6 +27,6 @@
<suppressions> <suppressions>
<suppress checks="FanOutComplexity" files="NotificationFilterPreferenceStore.java"/> <suppress checks="FanOutComplexity" files="NotificationFilterPreferenceStore.java"/>
<suppress checks="FanOutComplexity" files="R140401000XWIKI15460DataMigration.java"/> <suppress checks="FanOutComplexity" files="R140401000XWIKI15460DataMigration.java"/>
<suppress checks="FanOutComplexity" files="R160000000XWIKI17243DataMigration.java"/> <suppress checks="FanOutComplexity" files="R160300000XWIKI17243DataMigration.java"/>
<suppress checks="FanOutComplexity" files="NotificationCustomFiltersLiveDataEntryStore.java"/> <suppress checks="FanOutComplexity" files="NotificationCustomFiltersLiveDataEntryStore.java"/>
</suppressions> </suppressions>
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
import org.xwiki.query.QueryException; import org.xwiki.query.QueryException;
import org.xwiki.query.QueryFilter; import org.xwiki.query.QueryFilter;
import org.xwiki.query.QueryManager; import org.xwiki.query.QueryManager;
import org.xwiki.stability.Unstable;
import org.xwiki.wiki.descriptor.WikiDescriptorManager; import org.xwiki.wiki.descriptor.WikiDescriptorManager;
import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.XWikiException;
...@@ -60,6 +61,7 @@ ...@@ -60,6 +61,7 @@
@Component @Component
@Named("R151002000XWIKI21448") @Named("R151002000XWIKI21448")
@Singleton @Singleton
@Unstable
public class R151002000XWIKI21448DataMigration extends AbstractHibernateDataMigration public class R151002000XWIKI21448DataMigration extends AbstractHibernateDataMigration
{ {
private static final int BATCH_SIZE = 100; private static final int BATCH_SIZE = 100;
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
import org.xwiki.query.Query; import org.xwiki.query.Query;
import org.xwiki.query.QueryException; import org.xwiki.query.QueryException;
import org.xwiki.query.QueryManager; import org.xwiki.query.QueryManager;
import org.xwiki.stability.Unstable;
import org.xwiki.wiki.descriptor.WikiDescriptorManager; import org.xwiki.wiki.descriptor.WikiDescriptorManager;
import org.xwiki.wiki.manager.WikiManagerException; import org.xwiki.wiki.manager.WikiManagerException;
...@@ -60,6 +61,7 @@ ...@@ -60,6 +61,7 @@
@Component @Component
@Named("R160100000XWIKI21738") @Named("R160100000XWIKI21738")
@Singleton @Singleton
@Unstable
public class R160100000XWIKI21738DataMigration extends AbstractHibernateDataMigration public class R160100000XWIKI21738DataMigration extends AbstractHibernateDataMigration
{ {
private static final int BATCH_SIZE = 100; private static final int BATCH_SIZE = 100;
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
import org.xwiki.query.QueryException; import org.xwiki.query.QueryException;
import org.xwiki.query.QueryFilter; import org.xwiki.query.QueryFilter;
import org.xwiki.query.QueryManager; import org.xwiki.query.QueryManager;
import org.xwiki.stability.Unstable;
import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.XWikiException;
...@@ -70,12 +71,13 @@ ...@@ -70,12 +71,13 @@
* remove the xobjects but asks {@link WatchListObjectsRemovalTaskConsumer} to do it. * remove the xobjects but asks {@link WatchListObjectsRemovalTaskConsumer} to do it.
* *
* @version $Id$ * @version $Id$
* @since 16.0.0RC1 * @since 16.3.0RC1
*/ */
@Component @Component
@Named("R160000000XWIKI17243") @Named("R160300000XWIKI17243")
@Singleton @Singleton
public class R160000000XWIKI17243DataMigration extends AbstractHibernateDataMigration @Unstable
public class R160300000XWIKI17243DataMigration extends AbstractHibernateDataMigration
{ {
private static final String WATCHLIST_CLASSNAME = "WatchListClass"; private static final String WATCHLIST_CLASSNAME = "WatchListClass";
...@@ -99,6 +101,10 @@ public class R160000000XWIKI17243DataMigration extends AbstractHibernateDataMigr ...@@ -99,6 +101,10 @@ public class R160000000XWIKI17243DataMigration extends AbstractHibernateDataMigr
@Named("unique") @Named("unique")
private QueryFilter uniqueFilter; private QueryFilter uniqueFilter;
@Inject
@Named("count")
private QueryFilter countFilter;
@Inject @Inject
private NotificationFilterPreferenceStore notificationFilterPreferenceStore; private NotificationFilterPreferenceStore notificationFilterPreferenceStore;
...@@ -120,33 +126,60 @@ public String getDescription() ...@@ -120,33 +126,60 @@ public String getDescription()
@Override @Override
public XWikiDBVersion getVersion() public XWikiDBVersion getVersion()
{ {
return new XWikiDBVersion(160000000); return new XWikiDBVersion(160300000);
} }
@Override @Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException protected void hibernateMigrate() throws DataMigrationException, XWikiException
{ {
String statement = "from doc.object(XWiki.WatchListClass) as watchListDoc"; String statement = "from doc.object(XWiki.WatchListClass) as watchListDoc";
int offset = 0; long numberOfEntries;
List<String> results; try {
do { List<Long> countResult = this.queryManager
try { .createQuery(statement, Query.XWQL)
results = this.queryManager.createQuery(statement, Query.XWQL) .addFilter(countFilter).execute();
.addFilter(uniqueFilter) numberOfEntries = countResult.get(0);
.setOffset(offset) } catch (QueryException e) {
.setLimit(BATCH_SIZE).execute(); throw new DataMigrationException("Error while performing query to count users with WatchList objects",
e);
this.logger.info("Found [{}] users with WatchListClass objects... migrating them.", results.size()); }
for (String result : results) { if (numberOfEntries > 0) {
DocumentReference watchListDoc = this.documentReferenceResolver.resolve(result); WikiReference currentWiki = getXWikiContext().getWikiReference();
this.migrateWatchListDoc(watchListDoc); long loops = (numberOfEntries / BATCH_SIZE);
} if (numberOfEntries % BATCH_SIZE > 0) {
offset += BATCH_SIZE; loops += 1;
} catch (QueryException e) {
throw new DataMigrationException("Error while performing query to find users with WatchList objects",
e);
} }
} while (results.size() == BATCH_SIZE); this.logger.info(
"Found a total number of [{}] users with WatchListClass objects. Migration will operate [{}]"
+ " loops of [{}] entries.", numberOfEntries, loops, BATCH_SIZE);
int loopIndex = 1;
int offset = 0;
List<String> results;
do {
try {
results = this.queryManager.createQuery(statement, Query.XWQL)
.addFilter(uniqueFilter)
.setOffset(offset)
.setLimit(BATCH_SIZE).execute();
this.logger.info("(loop [{}] on [{}]) Migrating [{}] users with WatchListClass objects...",
loopIndex, loops, results.size());
for (String result : results) {
DocumentReference watchListDoc = this.documentReferenceResolver.resolve(result, currentWiki);
this.migrateWatchListDoc(watchListDoc);
}
offset += BATCH_SIZE;
} catch (QueryException e) {
throw new DataMigrationException(
"Error while performing query to find users with WatchList objects",
e);
}
loopIndex++;
} while (results.size() == BATCH_SIZE);
} else {
this.logger.info("No users have been found with WatchListClass object. Migration skipped.");
}
} }
private void migrateWatchListDoc(DocumentReference watchListDocReference) private void migrateWatchListDoc(DocumentReference watchListDocReference)
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
/** /**
* Task for removing WatchListClass xobjects from page. This task should only be triggered when * Task for removing WatchListClass xobjects from page. This task should only be triggered when
* {@link R160000000XWIKI17243DataMigration} has been done. * {@link R160300000XWIKI17243DataMigration} has been done.
* Note that this task might also create an autowatch xobject to get the new property if it's not defined, as we use * Note that this task might also create an autowatch xobject to get the new property if it's not defined, as we use
* to fallback on the autowatch property defined in the WatchListClass xobject. * to fallback on the autowatch property defined in the WatchListClass xobject.
* *
......
...@@ -24,6 +24,6 @@ org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayerComponen ...@@ -24,6 +24,6 @@ org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayerComponen
org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayerDocumentInitializer org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayerDocumentInitializer
org.xwiki.notifications.filters.migration.R140401000XWIKI15460DataMigration org.xwiki.notifications.filters.migration.R140401000XWIKI15460DataMigration
org.xwiki.notifications.filters.migration.R151002000XWIKI21448DataMigration org.xwiki.notifications.filters.migration.R151002000XWIKI21448DataMigration
org.xwiki.notifications.filters.migration.R160000000XWIKI17243DataMigration org.xwiki.notifications.filters.migration.R160300000XWIKI17243DataMigration
org.xwiki.notifications.filters.migration.R160100000XWIKI21738DataMigration org.xwiki.notifications.filters.migration.R160100000XWIKI21738DataMigration
org.xwiki.notifications.filters.migration.WatchListObjectsRemovalTaskConsumer org.xwiki.notifications.filters.migration.WatchListObjectsRemovalTaskConsumer
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment