From 54335ff688824e2be0537a41e2c0cb9ba7b8b2e3 Mon Sep 17 00:00:00 2001 From: Adriano Dias Date: Wed, 9 Mar 2022 16:08:15 +0100 Subject: [PATCH 1/2] Add reset command. --- drush.services.yml | 5 +++ .../EntityActivityTrackerCommands.php | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 drush.services.yml create mode 100644 src/Commands/EntityActivityTrackerCommands.php diff --git a/drush.services.yml b/drush.services.yml new file mode 100644 index 0000000..226d11c --- /dev/null +++ b/drush.services.yml @@ -0,0 +1,5 @@ +services: + entity_activity_tracker.commands: + class: \Drupal\entity_activity_tracker\Commands\EntityActivityTrackerCommands + tags: + - { name: drush.command } diff --git a/src/Commands/EntityActivityTrackerCommands.php b/src/Commands/EntityActivityTrackerCommands.php new file mode 100644 index 0000000..fdfcff3 --- /dev/null +++ b/src/Commands/EntityActivityTrackerCommands.php @@ -0,0 +1,41 @@ +listAll('entity_activity_tracker'); + foreach ($configNames as $config) { + \Drupal::configFactory()->getEditable($config)->delete(); + } + + // Truncate entity_activity_tracker and clean up queue. + \Drupal::database()->truncate('entity_activity_tracker')->execute(); + \Drupal::database()->delete('queue')->condition('name','activity_processor_queue')->execute(); + } +} From 4d81160b9c9ee13ba24ac656a1ded0ef02248708 Mon Sep 17 00:00:00 2001 From: Nikolay Lobachev Date: Tue, 15 Mar 2022 15:35:15 +0500 Subject: [PATCH 2/2] Code improvements. --- src/Commands/EntityActivityTrackerCommands.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Commands/EntityActivityTrackerCommands.php b/src/Commands/EntityActivityTrackerCommands.php index fdfcff3..3660209 100644 --- a/src/Commands/EntityActivityTrackerCommands.php +++ b/src/Commands/EntityActivityTrackerCommands.php @@ -2,7 +2,6 @@ namespace Drupal\entity_activity_tracker\Commands; -use Consolidation\OutputFormatters\StructuredData\RowsOfFields; use Drush\Commands\DrushCommands; /** @@ -29,13 +28,16 @@ class EntityActivityTrackerCommands extends DrushCommands { */ public function resetEntityActivityTracker() { // Delete all existing configs. - $configNames = \Drupal::service('config.storage')->listAll('entity_activity_tracker'); - foreach ($configNames as $config) { - \Drupal::configFactory()->getEditable($config)->delete(); + $config_names = \Drupal::service('config.storage')->listAll('entity_activity_tracker'); + $config_factory = \Drupal::configFactory(); + foreach ($config_names as $config) { + $config_factory->getEditable($config)->delete(); } // Truncate entity_activity_tracker and clean up queue. - \Drupal::database()->truncate('entity_activity_tracker')->execute(); - \Drupal::database()->delete('queue')->condition('name','activity_processor_queue')->execute(); + $database = \Drupal::database(); + $database->truncate('entity_activity_tracker')->execute(); + $database->delete('queue')->condition('name', 'activity_processor_queue')->execute(); + $database->delete('queue')->condition('name', 'tracker_processor_queue')->execute(); } }