diff --git a/drush.services.yml b/drush.services.yml index 67a12db74056cdd584f4e303475cba428116ad67..53b8a797bc931d1fdad6d10e5e58ce0835b3a6ff 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -1,6 +1,6 @@ services: uw_cfg_common.commands: class: Drupal\uw_cfg_common\Commands\UwDrushCommands - arguments: ['@entity_type.manager', '@uw_cfg_common.missing_blocks', '@config.factory', '@request_stack'] + arguments: ['@entity_type.manager', '@uw_cfg_common.missing_blocks', '@config.factory', '@module_handler', '@module_installer'] tags: - { name: drush.command } diff --git a/src/Commands/UwDrushCommands.php b/src/Commands/UwDrushCommands.php index 725464834c454924a071e8289612b3a27ed6449b..6c16f7b4ce6e1c02f5ea064b05626fffe09e9f1b 100644 --- a/src/Commands/UwDrushCommands.php +++ b/src/Commands/UwDrushCommands.php @@ -4,6 +4,8 @@ namespace Drupal\uw_cfg_common\Commands; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Extension\ModuleHandler; +use Drupal\Core\ProxyClass\Extension\ModuleInstaller; use Drupal\uw_cfg_common\Service\UWMissingBlocks; use Drupal\uw_cfg_common\UwPermissions\UwPermissions; use Drupal\uw_cfg_common\UwRoles\UwRoles; @@ -38,13 +40,35 @@ class UwDrushCommands extends DrushCommands { */ protected $configFactory; + /** + * Module handler. + * + * @var \Drupal\Core\Extension\ModuleHandler + */ + protected $moduleHandler; + + /** + * Module installer. + * + * @var \Drupal\Core\ProxyClass\Extension\ModuleInstaller + */ + protected $moduleInstaller; + /** * {@inheritDoc} */ - public function __construct(EntityTypeManagerInterface $entityTypeManager, UWMissingBlocks $missingBlocks, ConfigFactoryInterface $configFactory) { + public function __construct( + EntityTypeManagerInterface $entityTypeManager, + UWMissingBlocks $missingBlocks, + ConfigFactoryInterface $configFactory, + ModuleHandler $moduleHandler, + ModuleInstaller $moduleInstaller + ) { $this->entityTypeManager = $entityTypeManager; $this->missingBlocks = $missingBlocks; $this->configFactory = $configFactory; + $this->moduleHandler = $moduleHandler; + $this->moduleInstaller = $moduleInstaller; } /** @@ -227,4 +251,36 @@ class UwDrushCommands extends DrushCommands { return $path; } + /** + * Drush command to cleanup after a migration. + * + * @command mim:cleanup + * @aliases mimcu + * @usage mimcu + */ + public function migrationCleanUp() { + + // Modules to uninstall. + $modules = [ + 'uw_migrate', + 'webform_migrate', + 'webform_node', + ]; + + // Step through each of the modules, ensure that they + // are enabled, and if enabled, uninstall. + foreach ($modules as $module) { + + // If the module is enabled, uninstall it. + if ($this->moduleHandler->moduleExists($module)) { + + // Uninstall the module. + $this->moduleInstaller->uninstall([$module]); + + // Log to the screen. + $this->logger()->success('Uninstalled: ' . $module); + } + } + } + }