added deleting flagging collections with duplicate relatedflag

This commit is contained in:
Bachir Soussi Chiadmi 2022-02-23 13:59:27 +01:00
parent a96c64712d
commit a635696e2b
1 changed files with 20 additions and 0 deletions

View File

@ -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