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