From d95893e148f20d3a527d1c076381c1323519581b Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 23 Feb 2022 14:48:13 +0100 Subject: [PATCH] fixed deleting flagging collections with duplicate relatedflag --- cleanflaglist.script | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/cleanflaglist.script b/cleanflaglist.script index e1ce676..b1a2e39 100755 --- a/cleanflaglist.script +++ b/cleanflaglist.script @@ -63,7 +63,7 @@ foreach ($fcfd_result as $fc) { $conf_result = $flag_query->execute(); $count = $flag_query->countQuery()->execute()->fetchField(); if(!$count){ - $this->output()->writeln($count . " relatedflag"); + $this->output()->writeln($fc->id . ' flagging_collection has ' . $count . " relatedflag"); $fc_missing_relatedflag ++; delete_flagingcollection($fc, $database, $delete); } @@ -73,22 +73,40 @@ $this->output()->writeln($fc_missing_relatedflag .' flagging_collection with mis // searching for duplicates relatedflags $this->output()->writeln(""); $this->output()->writeln("Duplicate relatedflag flagging_collection cleaning"); -$fcfd_query = $database->select('flagging_collection_field_data', 'fcfd') - ->fields('fcfd', ['id', 'relatedflag']) +$dup_query = $database->select('flagging_collection_field_data', 'fcfd') + ->fields('fcfd', ['relatedflag']) ->groupBy('fcfd.relatedflag') ->having('COUNT(*) > 1'); -$fcfd_query->addExpression('COUNT(*)', 'count'); +$dup_query->addExpression('COUNT(*)', 'count'); // $results = $query->execute()->fetchAll(); -$fcfd_result = $fcfd_query->execute(); -$this->output()->writeln($fcfd_query->countQuery()->execute()->fetchField() . " duplicate related flags"); +$dup_result = $dup_query->execute(); +$this->output()->writeln($dup_query->countQuery()->execute()->fetchField() . " duplicate related flags"); + +foreach ($dup_result as $dup){ + // $this->output()->writeln($dup->relatedflag . " is dup"); + $fcfd_query = $database->select('flagging_collection_field_data', 'fcfd') + ->condition('fcfd.relatedflag', $dup->relatedflag) + ->fields('fcfd', ['id', 'relatedflag']); + $fcfd_result = $fcfd_query->execute(); + $count = $fcfd_query->countQuery()->execute()->fetchField(); + + $this->output()->writeln($dup->relatedflag . ' relatedflag has ' . $count . ' flagging collection'); + + foreach ($fcfd_result as $fc) { + delete_flagingcollection($fc, $database, $delete); + } -foreach ($fcfd_result as $dup){ - $this->output()->writeln($dup->relatedflag . " of " . $dup->id . " is dup"); - delete_flagingcollection($dup, $database, $delete); } + + + + + + + // MAIN DELETE FUNCTION function delete_flagingcollection($fc, $database, $delete){ if($delete){