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

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.

WIP: migration not yet impleemnted and coverage failing.
  • Loading branch information
surli committed Dec 27, 2023
1 parent aa8d704 commit fc6dd5f
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public class DocumentMovedListener extends AbstractEventListener
@Inject
private EntityReferenceSerializer<String> serializer;

@Inject
private NotificationFilterPreferenceConfiguration filterPreferenceConfiguration;

@Inject
private Logger logger;

Expand Down Expand Up @@ -97,24 +94,16 @@ public void onEvent(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 : 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.notifications.filters.migration;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.query.QueryFilter;
import org.xwiki.query.QueryManager;

import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.store.migration.DataMigrationException;
import com.xpn.xwiki.store.migration.XWikiDBVersion;
import com.xpn.xwiki.store.migration.hibernate.AbstractHibernateDataMigration;

/**
* Migrate old WatchListClass xobjects to save them as proper notification filters. The migration doesn't directly
* remove the xobjects but asks {@link WatchListObjectsRemovalTaskConsumer} to do it.
*
* @version $Id$
* @since 16.0.0RC1
*/
@Component
@Named("R160000000XWIKI17243")
@Singleton
public class R160000001XWIKI21738DataMigration extends AbstractHibernateDataMigration
{
private static final int BATCH_SIZE = 100;

@Inject
private QueryManager queryManager;

@Inject
@Named("unique")
private QueryFilter uniqueFilter;

@Inject
private DocumentReferenceResolver<String> documentReferenceResolver;

@Inject
private Logger logger;

@Override
public String getDescription()
{
return "Migrate filters next to users.";
}

@Override
public XWikiDBVersion getVersion()
{
return new XWikiDBVersion(160000000);
}

@Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException
{
// This migration only needs to be performed on main wiki: if we have filters on local wikis it's because
// local filters was enabled.
// Migration steps:
// - Retrieve all filters from main wiki where owner belongs to a subwiki
// - Store that filter on the subwiki DB and remove it from main wiki

String statement = "from doc.object(XWiki.WatchListClass) as user";
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
org.xwiki.notifications.filters.internal.CachedModelBridgeInvalidatorListener
org.xwiki.notifications.filters.internal.DefaultFilterPreferencesModelBridge
org.xwiki.notifications.filters.internal.DocumentMovedListener
org.xwiki.notifications.filters.internal.NotificationFilterPreferenceConfiguration
org.xwiki.notifications.filters.internal.NotificationFilterPreferenceStore
org.xwiki.notifications.filters.internal.ToggleableFilterPreferenceDocumentInitializer
org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayer
Expand Down
Loading

0 comments on commit fc6dd5f

Please sign in to comment.