Skip to content

Commit

Permalink
XWIKI-21738: Remove uselocastore/usemainstore configurations for bett…
Browse files Browse the repository at this point in the history
…er maintenance (#2745)

Start refactoring by removing entirely
NotificationFilterPreferenceConfiguration since it's now useless. Remove
also calls to useMainStore/useLocalStore where needed and fix tests.
Started to define migration but not implemted yet.

  * Provide migration of filters
  * Remove options from configuration
  * Fix migration issue
  * Bulletproof a bit the migration
  * Fix property file
  * Provide unit test for the migration

Co-authored-by: Manuel Leduc <[email protected]>
  • Loading branch information
surli and manuelleduc authored Feb 15, 2024
1 parent 2bda306 commit 7e1d14c
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,12 @@
<artifactId>javax.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-oldcore</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public class DocumentMovedListener extends AbstractLocalEventListener
@Inject
private EntityReferenceSerializer<String> serializer;

@Inject
private NotificationFilterPreferenceConfiguration filterPreferenceConfiguration;

@Inject
private Logger logger;

Expand Down Expand Up @@ -97,24 +94,16 @@ public void processLocalEvent(Event event, Object source, Object data)
DocumentReference targetLocation = renamedEvent.getTargetReference();

try {
if (filterPreferenceConfiguration.useMainStore()) {
namespaceContextExecutor.execute(new WikiNamespace(wikiDescriptorManager.getMainWikiId()), () -> {
// Filters are stored in the DB of the users, since each wiki could possibly contain a user
// we need to iterate over all DB to ensure we properly migrate the filters.
// We could have checked the configuration of the wiki to see if they are allowed to store user or not
// but this config might have changed over time...
for (String wikiId : this.wikiDescriptorManager.getAllIds()) {
namespaceContextExecutor.execute(new WikiNamespace(wikiId), () -> {
updatePreferences(sourceLocation, targetLocation);
return null;
});
} else if (filterPreferenceConfiguration.useLocalStore()) {
// Filters are stored in the DB of the users, since each wiki could possibly contain a user
// we need to iterate over all DB to ensure we properly migrate the filters.
// We could have checked the configuration of the wiki to see if they are allowed to store user or not
// but this config might have changed over time...
for (String wikiId : wikiDescriptorManager.getAllIds()) {
namespaceContextExecutor.execute(new WikiNamespace(wikiId), () -> {
updatePreferences(sourceLocation, targetLocation);
return null;
});
}
}

} catch (Exception e) {
logger.error("Failed to update the notification filter preference when [{}] has been moved to [{}].",
renamedEvent.getSourceReference(), renamedEvent.getTargetReference(), e);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public class NotificationFilterPreferenceStore
{
private static final String FILTER_PREFIX = "NFP_";

@Inject
private NotificationFilterPreferenceConfiguration filterPreferenceConfiguration;

@Inject
private EntityReferenceSerializer<String> entityReferenceSerializer;

Expand Down Expand Up @@ -462,11 +459,7 @@ private <T, E extends Throwable> T configureContextWrapper(WikiReference wikiRef
{
XWikiContext context = this.contextProvider.get();
WikiReference currentWiki = context.getWikiReference();
if (this.filterPreferenceConfiguration.useMainStore()) {
context.setWikiId(context.getMainXWiki());
} else if (wikiReference != null) {
context.setWikiReference(wikiReference);
}
context.setWikiReference(wikiReference);
try {
return supplier.get();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import javax.inject.Singleton;

import org.xwiki.component.annotation.Component;
import org.xwiki.configuration.ConfigurationSource;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
import org.xwiki.model.reference.WikiReference;
import org.xwiki.notifications.NotificationException;
import org.xwiki.notifications.filters.internal.DefaultNotificationFilterPreference;
import org.xwiki.notifications.filters.internal.NotificationFilterPreferenceConfiguration;
import org.xwiki.notifications.filters.internal.NotificationFilterPreferenceStore;
import org.xwiki.query.Query;
import org.xwiki.query.QueryException;
Expand Down Expand Up @@ -94,9 +94,6 @@ public class R140401000XWIKI15460DataMigration extends AbstractHibernateDataMigr
@Named("local")
private EntityReferenceSerializer<String> entityReferenceSerializer;

@Inject
private NotificationFilterPreferenceConfiguration filterPreferenceConfiguration;

@Inject
private QueryManager queryManager;

Expand All @@ -107,6 +104,9 @@ public class R140401000XWIKI15460DataMigration extends AbstractHibernateDataMigr
@Inject
private UserManager userManager;

@Inject
private ConfigurationSource configurationSource;

@Override
public XWikiDBVersion getVersion()
{
Expand Down Expand Up @@ -139,13 +139,18 @@ protected void hibernateMigrate() throws DataMigrationException
// Stop the execution early if the configuration uses the main store and we are not upgrading the main wiki.
// This check cannot be done in #shouldExecute because possibly missing columns are not yet added to the
// database.
if (this.filterPreferenceConfiguration.useMainStore() && !isMainWiki) {
if (useMainStore() && !isMainWiki) {
return;
}

internalHibernateMigrate(isMainWiki);
}

private boolean useMainStore()
{
return this.configurationSource.getProperty("eventstream.usemainstore", true);
}

private void internalHibernateMigrate(boolean isMainWiki) throws DataMigrationException
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import org.xwiki.cache.CacheManager;
import org.xwiki.cache.config.LRUCacheConfiguration;
import org.xwiki.component.annotation.Component;
import org.xwiki.configuration.ConfigurationSource;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
import org.xwiki.notifications.filters.internal.NotificationFilterPreferenceConfiguration;
import org.xwiki.query.Query;
import org.xwiki.query.QueryException;
import org.xwiki.query.QueryFilter;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class R151002000XWIKI21448DataMigration extends AbstractHibernateDataMigr
private WikiDescriptorManager wikiDescriptorManager;

@Inject
private NotificationFilterPreferenceConfiguration filterPreferenceConfiguration;
private ConfigurationSource configurationSource;

@Inject
private QueryManager queryManager;
Expand Down Expand Up @@ -112,13 +112,18 @@ protected void hibernateMigrate() throws DataMigrationException, XWikiException
// Stop the execution early if the configuration uses the main store, and we are not upgrading the main wiki.
// This check cannot be done in #shouldExecute because possibly missing columns are not yet added to the
// database.
if (this.filterPreferenceConfiguration.useMainStore() && !isMainWiki) {
if (useMainStore() && !isMainWiki) {
return;
}

internalHibernateMigrate();
}

private boolean useMainStore()
{
return this.configurationSource.getProperty("eventstream.usemainstore", true);
}

private void internalHibernateMigrate() throws DataMigrationException
{
// Cache of boolean: true if the documents exists, false if it's missing.
Expand Down
Loading

0 comments on commit 7e1d14c

Please sign in to comment.