|
23 | 23 | import org.jsoup.nodes.Element; |
24 | 24 | import org.slf4j.Logger; |
25 | 25 | import org.slf4j.LoggerFactory; |
| 26 | +import org.structr.api.graph.PropertyContainer; |
26 | 27 | import org.structr.api.util.Iterables; |
27 | 28 | import org.structr.common.error.FrameworkException; |
28 | 29 | import org.structr.common.helper.CaseHelper; |
| 30 | +import org.structr.core.GraphObject; |
29 | 31 | import org.structr.core.Services; |
30 | 32 | import org.structr.core.app.App; |
31 | 33 | import org.structr.core.app.StructrApp; |
@@ -183,7 +185,7 @@ public static void execute() { |
183 | 185 | migrateFolderMountTarget(); |
184 | 186 | migrateEventActionMapping(); |
185 | 187 | updateSharedComponentFlag(); |
186 | | - warnAboutRestQueryRepeaters(); |
| 188 | + migrateRestQueryRepeaters(); |
187 | 189 | warnAboutWrongNotionProperties(); |
188 | 190 | } |
189 | 191 | } |
@@ -995,7 +997,36 @@ private static void warnAboutWrongNotionProperties() { |
995 | 997 | } |
996 | 998 | } |
997 | 999 |
|
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 | + } |
999 | 1030 |
|
1000 | 1031 | /* |
1001 | 1032 | final PropertyKey<String> key = Traits.of(StructrTraits.DOM_ELEMENT).key(DOMNodeTraitDefinition.REST_QUERY_PROPERTY); |
|
0 commit comments