From e692d85d56fc613d2601619d7873d157c724112b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=A9na=20Proxima?= Date: Sat, 3 Feb 2018 14:21:35 -0800 Subject: [PATCH] Added install/uninstall module methods. --- src/Drupal/Driver/BaseDriver.php | 14 ++++++++++++++ src/Drupal/Driver/Cores/CoreInterface.php | 16 ++++++++++++++++ src/Drupal/Driver/Cores/Drupal6.php | 15 +++++++++++++++ src/Drupal/Driver/Cores/Drupal7.php | 15 +++++++++++++++ src/Drupal/Driver/Cores/Drupal8.php | 20 ++++++++++++++++++++ src/Drupal/Driver/DriverInterface.php | 16 ++++++++++++++++ src/Drupal/Driver/DrupalDriver.php | 14 ++++++++++++++ src/Drupal/Driver/DrushDriver.php | 14 ++++++++++++++ 8 files changed, 124 insertions(+) diff --git a/src/Drupal/Driver/BaseDriver.php b/src/Drupal/Driver/BaseDriver.php index ef420667..c4ce6f0b 100644 --- a/src/Drupal/Driver/BaseDriver.php +++ b/src/Drupal/Driver/BaseDriver.php @@ -174,4 +174,18 @@ public function entityDelete($entity_type, $entity) { throw new UnsupportedDriverActionException($this->errorString('delete entities using the generic Entity API'), $this); } + /** + * {@inheritdoc} + */ + public function moduleInstall($module_name) { + throw new UnsupportedDriverActionException($this->errorString('install modules'), $this); + } + + /** + * {@inheritdoc} + */ + public function moduleUninstall($module_name) { + throw new UnsupportedDriverActionException($this->errorString('uninstall modules'), $this); + } + } diff --git a/src/Drupal/Driver/Cores/CoreInterface.php b/src/Drupal/Driver/Cores/CoreInterface.php index 303c5f90..705176e1 100644 --- a/src/Drupal/Driver/Cores/CoreInterface.php +++ b/src/Drupal/Driver/Cores/CoreInterface.php @@ -236,4 +236,20 @@ public function entityCreate($entity_type, $entity); */ public function entityDelete($entity_type, $entity); + /** + * Installs a module. + * + * @param string $module_name + * The machine name of the module to install. + */ + public function moduleInstall($module_name); + + /** + * Uninstalls a module. + * + * @param string $module_name + * The machine name of the module to uninstall. + */ + public function moduleUninstall($module_name); + } diff --git a/src/Drupal/Driver/Cores/Drupal6.php b/src/Drupal/Driver/Cores/Drupal6.php index 97026ea8..81c4eafb 100644 --- a/src/Drupal/Driver/Cores/Drupal6.php +++ b/src/Drupal/Driver/Cores/Drupal6.php @@ -513,4 +513,19 @@ public function entityDelete($entity_type, $entity) { throw new \Exception('Drupal 6 does not have a generic Entity API, so deletion of entities is not possible in this way.'); } + /** + * {@inheritdoc} + */ + public function moduleInstall($module_name) { + module_enable(array($module_name)); + } + + /** + * {@inheritdoc} + */ + public function moduleUninstall($module_name) { + module_disable(array($module_name)); + drupal_uninstall_module(array($module_name)); + } + } diff --git a/src/Drupal/Driver/Cores/Drupal7.php b/src/Drupal/Driver/Cores/Drupal7.php index bdbe1df4..54ec8e98 100644 --- a/src/Drupal/Driver/Cores/Drupal7.php +++ b/src/Drupal/Driver/Cores/Drupal7.php @@ -498,4 +498,19 @@ public function entityDelete($entity_type, $entity) { throw new \Exception('Deletion of entities via the generic Entity API is not yet implemented for Drupal 7.'); } + /** + * {@inheritdoc} + */ + public function moduleInstall($module_name) { + module_enable(array($module_name)); + } + + /** + * {@inheritdoc} + */ + public function moduleUninstall($module_name) { + module_disable(array($module_name)); + drupal_uninstall_modules(array($module_name)); + } + } diff --git a/src/Drupal/Driver/Cores/Drupal8.php b/src/Drupal/Driver/Cores/Drupal8.php index 108a44e4..e819d16b 100644 --- a/src/Drupal/Driver/Cores/Drupal8.php +++ b/src/Drupal/Driver/Cores/Drupal8.php @@ -3,6 +3,7 @@ namespace Drupal\Driver\Cores; use Drupal\Core\DrupalKernel; +use Drupal\Core\Site\Settings; use Drupal\Driver\Exception\BootstrapException; use Drupal\field\Entity\FieldStorageConfig; use Drupal\language\Entity\ConfigurableLanguage; @@ -470,4 +471,23 @@ public function entityDelete($entity_type, $entity) { } } + /** + * {@inheritdoc} + */ + public function moduleInstall($module_name) { + // Scan test directories for modules. + $settings = Settings::getAll(); + $settings['extension_discovery_scan_tests'] = TRUE; + new Settings($settings); + + \Drupal::service('module_installer')->install(array($module_name)); + } + + /** + * {@inheritdoc} + */ + public function moduleUninstall($module_name) { + \Drupal::service('module_installer')->uninstall(array($module_name)); + } + } diff --git a/src/Drupal/Driver/DriverInterface.php b/src/Drupal/Driver/DriverInterface.php index 5bbafb5f..51b7ef0e 100644 --- a/src/Drupal/Driver/DriverInterface.php +++ b/src/Drupal/Driver/DriverInterface.php @@ -178,4 +178,20 @@ public function configGet($name, $key); */ public function configSet($name, $key, $value); + /** + * Installs a module. + * + * @param string $module_name + * The machine name of the module to install. + */ + public function moduleInstall($module_name); + + /** + * Uninstalls a module. + * + * @param string $module_name + * The machine name of the module to uninstall. + */ + public function moduleUninstall($module_name); + } diff --git a/src/Drupal/Driver/DrupalDriver.php b/src/Drupal/Driver/DrupalDriver.php index e46bc5a8..cc3c097c 100644 --- a/src/Drupal/Driver/DrupalDriver.php +++ b/src/Drupal/Driver/DrupalDriver.php @@ -333,4 +333,18 @@ public function entityDelete($entity_type, $entity) { return $this->getCore()->entityDelete($entity_type, $entity); } + /** + * {@inheritdoc} + */ + public function moduleInstall($module_name) { + $this->getCore()->moduleInstall($module_name); + } + + /** + * {@inheritdoc} + */ + public function moduleUninstall($module_name) { + $this->getCore()->moduleUninstall($module_name); + } + } diff --git a/src/Drupal/Driver/DrushDriver.php b/src/Drupal/Driver/DrushDriver.php index 12e5b516..c2d41cee 100644 --- a/src/Drupal/Driver/DrushDriver.php +++ b/src/Drupal/Driver/DrushDriver.php @@ -386,6 +386,20 @@ public function runCron() { $this->drush('cron'); } + /** + * {@inheritdoc} + */ + public function moduleInstall($module_name) { + $this->drush('pm-enable', array($module_name), array('yes' => TRUE)); + } + + /** + * {@inheritdoc} + */ + public function moduleUninstall($module_name) { + $this->drush('pm-uninstall', array($module_name), array('yes' => TRUE)); + } + /** * Run Drush commands dynamically from a DrupalContext. */