From a635696e2bc224ded95acc3d32b08cbe4916cac9 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 23 Feb 2022 13:59:27 +0100 Subject: [PATCH] added deleting flagging collections with duplicate relatedflag --- cleanflaglist.script | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cleanflaglist.script b/cleanflaglist.script index d09baea3..e1ce6762 100755 --- a/cleanflaglist.script +++ b/cleanflaglist.script @@ -70,6 +70,26 @@ foreach ($fcfd_result as $fc) { } $this->output()->writeln($fc_missing_relatedflag .' flagging_collection with missing related_flag'); +// 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']) + ->groupBy('fcfd.relatedflag') + ->having('COUNT(*) > 1'); +$fcfd_query->addExpression('COUNT(*)', 'count'); + +// $results = $query->execute()->fetchAll(); + +$fcfd_result = $fcfd_query->execute(); +$this->output()->writeln($fcfd_query->countQuery()->execute()->fetchField() . " duplicate related flags"); + +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){ // $this is not working in function