Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to install and uninstall modules #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Drupal/Driver/BaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
16 changes: 16 additions & 0 deletions src/Drupal/Driver/Cores/CoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
15 changes: 15 additions & 0 deletions src/Drupal/Driver/Cores/Drupal6.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
15 changes: 15 additions & 0 deletions src/Drupal/Driver/Cores/Drupal7.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
20 changes: 20 additions & 0 deletions src/Drupal/Driver/Cores/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

}
16 changes: 16 additions & 0 deletions src/Drupal/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
14 changes: 14 additions & 0 deletions src/Drupal/Driver/DrupalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
14 changes: 14 additions & 0 deletions src/Drupal/Driver/DrushDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down