Skip to content

Commit

Permalink
Merge pull request #28 from cnect-web/add-reset-command
Browse files Browse the repository at this point in the history
Add reset command.
  • Loading branch information
LOBsTerr authored Mar 15, 2022
2 parents f70d7da + 4d81160 commit 595dbc7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
entity_activity_tracker.commands:
class: \Drupal\entity_activity_tracker\Commands\EntityActivityTrackerCommands
tags:
- { name: drush.command }
43 changes: 43 additions & 0 deletions src/Commands/EntityActivityTrackerCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Drupal\entity_activity_tracker\Commands;

use Drush\Commands\DrushCommands;

/**
* A Drush commandfile.
*
* In addition to this file, you need a drush.services.yml
* in root of your module, and a composer.json file that provides the name
* of the services file to use.
*
* See these files for an example of injecting Drupal services:
* - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
* - http://cgit.drupalcode.org/devel/tree/drush.services.yml
*/
class EntityActivityTrackerCommands extends DrushCommands {

/**
* Reset Entity Activity Tracker.
*
* @usage entity_activity_tracker-resetEntityActivityTracker reat
* Usage description
*
* @command entity_activity_tracker:resetEntityActivityTracker
* @aliases reat
*/
public function resetEntityActivityTracker() {
// Delete all existing configs.
$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.
$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();
}
}

0 comments on commit 595dbc7

Please sign in to comment.