Skip to content

Commit 7203422

Browse files
committed
Implements migration of restQuery to functionQuery.
1 parent 5d65693 commit 7203422

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

structr-base/src/main/java/org/structr/core/graph/MigrationService.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import org.jsoup.nodes.Element;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
26+
import org.structr.api.graph.PropertyContainer;
2627
import org.structr.api.util.Iterables;
2728
import org.structr.common.error.FrameworkException;
2829
import org.structr.common.helper.CaseHelper;
30+
import org.structr.core.GraphObject;
2931
import org.structr.core.Services;
3032
import org.structr.core.app.App;
3133
import org.structr.core.app.StructrApp;
@@ -183,7 +185,7 @@ public static void execute() {
183185
migrateFolderMountTarget();
184186
migrateEventActionMapping();
185187
updateSharedComponentFlag();
186-
warnAboutRestQueryRepeaters();
188+
migrateRestQueryRepeaters();
187189
warnAboutWrongNotionProperties();
188190
}
189191
}
@@ -995,7 +997,36 @@ private static void warnAboutWrongNotionProperties() {
995997
}
996998
}
997999

998-
private static void warnAboutRestQueryRepeaters() {
1000+
private static void migrateRestQueryRepeaters() {
1001+
1002+
final App app = StructrApp.getInstance();
1003+
1004+
try (final Tx tx = app.tx()) {
1005+
1006+
final List<GraphObject> objects = Iterables.toList(app.query("MATCH (n:DOMNode) WHERE n.restQuery IS NOT null RETURN n", Map.of()));
1007+
1008+
for (final GraphObject object : objects) {
1009+
1010+
final PropertyContainer propertyContainer = object.getPropertyContainer();
1011+
final String restQuery = (String) propertyContainer.getProperty("restQuery");
1012+
final String functionQuery = (String) propertyContainer.getProperty("functionQuery");
1013+
1014+
if (StringUtils.isEmpty(functionQuery) && StringUtils.isNotEmpty(restQuery)) {
1015+
1016+
logger.info("MIGRATING rest QUERY in {} {} to functionQuery.", object.getType(), object.getUuid());
1017+
propertyContainer.setProperty("functionQuery", "{\n\t/* Migrated REST query, please fix! */\n\t/* " + restQuery + " */\n\n\t$.log('Repeater in ', $.this.type, ' with UUID ', $.this.id, ' needs manual migration of restQuery to functionQuery!');\n}");
1018+
1019+
} else {
1020+
1021+
logger.info("NOT migrating rest QUERY in {} {} because functionQuery is non-empty!", object.getType(), object.getUuid());
1022+
}
1023+
}
1024+
1025+
tx.success();
1026+
1027+
} catch (FrameworkException fex) {
1028+
logger.warn("Unable to migrate REST query repeaters: {}", fex.getMessage());
1029+
}
9991030

10001031
/*
10011032
final PropertyKey<String> key = Traits.of(StructrTraits.DOM_ELEMENT).key(DOMNodeTraitDefinition.REST_QUERY_PROPERTY);

0 commit comments

Comments
 (0)