created custom drush commands to clean missing related flags and duplicates related flags
This commit is contained in:
@@ -19,27 +19,42 @@ $this->output()->writeln(print_r($extra, true));
|
||||
$delete_all = false;
|
||||
$delete_nullname = false;
|
||||
$delete_missing = false;
|
||||
$recreate_missing = false;
|
||||
$delete_dups = false;
|
||||
$recreate_dups = false;
|
||||
|
||||
if ($extra[0] === "delete-all") {
|
||||
$delete_all = true;
|
||||
}
|
||||
|
||||
if ($extra[0] === "delete-missing") {
|
||||
$delete_missing = true;
|
||||
}
|
||||
|
||||
if ($extra[0] === "delete-nullname") {
|
||||
$delete_nullname = true;
|
||||
}
|
||||
|
||||
if ($extra[0] === "delete-dups") {
|
||||
$delete_dups = true;
|
||||
if (count($extra)) {
|
||||
switch ($extra[0]) {
|
||||
case "delete-all":
|
||||
$delete_all = true;
|
||||
break;
|
||||
case "delete-missing":
|
||||
$delete_missing = true;
|
||||
break;
|
||||
case "recreate-missing":
|
||||
$recreate_missing = true;
|
||||
break;
|
||||
case "delete-nullname":
|
||||
$delete_nullname = true;
|
||||
break;
|
||||
case "delete-dups":
|
||||
$delete_dups = true;
|
||||
break;
|
||||
case "recreate-dups":
|
||||
$recreate_dups = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$database = \Drupal::database();
|
||||
|
||||
// _ _ _ _
|
||||
// | \ | |_ _| | | _ __ __ _ _ __ ___ ___
|
||||
// | \| | | | | | | | '_ \ / _` | '_ ` _ \ / _ \
|
||||
// | |\ | |_| | | | | | | | (_| | | | | | | __/
|
||||
// |_| \_|\__,_|_|_| |_| |_|\__,_|_| |_| |_|\___|
|
||||
|
||||
// remove flagging collection with null name
|
||||
$this->output()->writeln("");
|
||||
$this->output()->writeln("Flagging collection With NULL name cleaning");
|
||||
@@ -66,12 +81,17 @@ foreach ($fcfd_result as $fc) {
|
||||
delete_flagingcollection($fc, $database, $delete_all ? true : $delete_nullname);
|
||||
}
|
||||
|
||||
|
||||
// __ __ _ _ ____ _ _ _ _____ _
|
||||
// | \/ (_)___ ___(_)_ __ __ _ | _ \ ___| | __ _| |_ ___ __| | | ___| | __ _ __ _
|
||||
// | |\/| | / __/ __| | '_ \ / _` | | |_) / _ \ |/ _` | __/ _ \/ _` | | |_ | |/ _` |/ _` |
|
||||
// | | | | \__ \__ \ | | | | (_| | | _ < __/ | (_| | || __/ (_| | | _| | | (_| | (_| |
|
||||
// |_| |_|_|___/___/_|_| |_|\__, | |_| \_\___|_|\__,_|\__\___|\__,_| |_| |_|\__,_|\__, |
|
||||
// |___/ |___/
|
||||
// searching for missing related flags
|
||||
$this->output()->writeln("");
|
||||
$this->output()->writeln("Missing related flag Flagging collection cleaning");
|
||||
$fcfd_query = $database->select('flagging_collection_field_data', 'fcfd')
|
||||
->fields('fcfd', ['id', 'relatedflag']);
|
||||
->fields('fcfd', ['name', 'id', 'relatedflag']);
|
||||
|
||||
$fcfd_result = $fcfd_query->execute();
|
||||
$this->output()->writeln($fcfd_query->countQuery()->execute()->fetchField() . " flagging_collections");
|
||||
@@ -84,13 +104,24 @@ foreach ($fcfd_result as $fc) {
|
||||
$conf_result = $flag_query->execute();
|
||||
$count = $flag_query->countQuery()->execute()->fetchField();
|
||||
if(!$count){
|
||||
$this->output()->writeln(' flagging_collection' . $fc->id . ' has ' . $count . " relatedflag");
|
||||
$this->output()->writeln(' flagging_collection ' . $fc->name . ' ('. $fc->id . ') has ' . $count . " relatedflag");
|
||||
$fc_missing_relatedflag ++;
|
||||
delete_flagingcollection($fc, $database, $delete_all ? true : $delete_missing);
|
||||
if ($recreate_missing) {
|
||||
$FlagListsService = new FlagListsService();
|
||||
$flaggingcollection = $FlagListsService->getFlaggingCollectionById($fc->id);
|
||||
$this->output()->writeln(' flagging_collection ' . $flaggingcollection->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
$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");
|
||||
@@ -190,4 +221,4 @@ function delete_flagingcollection($fc, $database, $delete){
|
||||
// $this->output()->writeln("In order to actually delete fault flagging collection data please use delete option");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user