From 5c4eb36b12677d5768a7bbbd3691f8728c1030f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Fri, 15 Nov 2019 17:18:12 +0100 Subject: [PATCH] Get db manipulation script running --- ...ed_relationship_to_decided_relationship.sh | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/neo4j/change_disabled_relationship_to_decided_relationship.sh b/neo4j/change_disabled_relationship_to_decided_relationship.sh index efd711b95..21c7b0094 100755 --- a/neo4j/change_disabled_relationship_to_decided_relationship.sh +++ b/neo4j/change_disabled_relationship_to_decided_relationship.sh @@ -21,38 +21,35 @@ MATCH (moderator:User)-[disabled:DISABLED]->(disabledResource) WHERE disabledResource:User OR disabledResource:Comment OR disabledResource:Post DELETE disabled CREATE (moderator)-[review:REVIEWED]->(case:Case)-[:FLAGGED]->(disabledResource) -SET review.updatedAt = toString(datetime()), review.createdAt = review.updatedAt, review.disable = true -SET case.id = randomUUID(), case.updatedAt = toString(datetime()), case.createdAt = case.updatedAt, case.disable = true, case.closed = false +SET review.createdAt = toString(datetime()), review.updatedAt = review.createdAt, review.disable = true +SET case.id = randomUUID(), case.createdAt = toString(datetime()), case.updatedAt = case.createdAt, case.disable = true, case.closed = false // if disabledResource has no report, then create a moderators default report WITH moderator, disabledResource, case -//, review -//OPTIONAL MATCH (noReporterDisabledResource:User)-[:REPORTED]->(disabledResource) -//WHERE noReporterDisabledResource IS NULL -//OPTIONAL MATCH (:User)-[notExistingReport:REPORTED]->(disabledResource) -//WHERE notExistingReport IS NULL -OPTIONAL MATCH (noReporterDisabledResource:User)-[notExistingReport:REPORTED]->(disabledResource) -WHERE NOT (noReporterDisabledResource)-[notExistingReport]->(disabledResource) -CREATE (moderator)-[addModeratorReport:REPORTED]->(case) -SET addModeratorReport.createdAt = toString(datetime()), addModeratorReport.reasonCategory = 'other', addModeratorReport.reasonDescription = 'Old DISABLED relation had no now mandatory report !!! Created automatically to ensure database consistency! Creation date is when the database manipulation happened.' +OPTIONAL MATCH (disabledResourceReporter:User)-[existingReport:REPORTED]->(disabledResource) +FOREACH(disabledResource IN CASE WHEN existingReport IS NULL THEN [1] ELSE [] END | + CREATE (moderator)-[addModeratorReport:REPORTED]->(case) + SET addModeratorReport.createdAt = toString(datetime()), addModeratorReport.reasonCategory = 'other', addModeratorReport.reasonDescription = 'Old DISABLED relation had no now mandatory report !!! Created automatically to ensure database consistency! Creation date is when the database manipulation happened.' +) +FOREACH(disabledResource IN CASE WHEN existingReport IS NOT NULL THEN [1] ELSE [] END | + CREATE (disabledResourceReporter)-[moveModeratorReport:REPORTED]->(case) + SET moveModeratorReport = existingReport + DELETE existingReport +) -// if disabledResource has reports, then convert them -WITH disabledResource, case -//, review -MATCH (reporterDisabledResource:User)-[existingReport:REPORTED]->(disabledResource) -DELETE existingReport -CREATE (reporterDisabledResource)-[reportDisabledResource:REPORTED]->(case) -SET reportDisabledResource = existingReport - -// for REPORTED resources without DISABLED relation which are handled above, create new REPORTED-Case-FLAGGED structure -WITH -MATCH (reporter:User)-[oldReport:REPORTED]->(noDisabledResource) -WHERE noDisabledResource:User OR noDisabledResource:Comment OR noDisabledResource:Post -DELETE oldReport -CREATE (reporter)-[report:REPORTED]->(case:Case) -MERGE (case)-[:FLAGGED]->(noDisabledResource) -SET report = oldReport -SET case.id = randomUUID(), case.updatedAt = toString(datetime()), case.createdAt = case.updatedAt, case.disable = false, case.closed = false - -RETURN disabledResource, noDisabledResource, review, report, addModeratorReport; +RETURN disabledResource; " | cypher-shell + +echo " +// for REPORTED resources without DISABLED relation which are handled above, create new REPORTED-Case-FLAGGED structure +MATCH (reporter:User)-[oldReport:REPORTED]->(notDisabledResource) +WHERE notDisabledResource:User OR notDisabledResource:Comment OR notDisabledResource:Post +CREATE (reporter)-[report:REPORTED]->(case:Case) +MERGE (case)-[:FLAGGED]->(notDisabledResource) +ON CREATE SET case.id = randomUUID(), case.createdAt = toString(datetime()), case.updatedAt = case.createdAt, case.disable = false, case.closed = false +SET report = oldReport +DELETE oldReport + +RETURN notDisabledResource; +" | cypher-shell +