You are here

public static function Modules::uninstall in Hook Update Deploy Tools 8

Same name and namespace in other branches
  1. 7 src/Modules.php \HookUpdateDeployTools\Modules::uninstall()

Uninstalls an array of modules there were previously disabled.

Parameters

array $modules: An array of module machine names to uninstall that are already disabled.

Return value

string Messsage indicating the modules are uninstalled.

Throws

\HudtException Calls the update a failure, preventing it from registering the update_N.

1 call to Modules::uninstall()
Modules::disableAndUninstall in src/Modules.php
Disables and Uninstalls an array of modules. Will not process dependents.

File

src/Modules.php, line 138

Class

Modules
Public method for enabling modules that verifies it was actually enabled.

Namespace

HookUpdateDeployTools

Code

public static function uninstall($modules = array()) {
  $modules = (array) $modules;
  $t = get_t();
  module_disable($modules);
  foreach ($modules as $module) {
    if (module_exists($module)) {

      // The module is not disabled, so it can not be uninstalled.
      $variables = array(
        '@module' => $module,
      );
      Message::make($message, $variables, WATCHDOG_ERROR);
      throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
    }
  }

  // Made it this far.Safe to uninstall.
  // Uninstall only the specified modules.  Do not uninstall dependents
  // unless the are specified as well.
  $uninstall_dependents = FALSE;
  $success = drupal_uninstall_modules($modules, $uninstall_dependents);
  $module_list = implode(', ', $modules);
  if ($success) {
    $message = "The modules @uninstalled were uninstalled successfully.";
    $variables = array(
      '@uninstalled' => $module_list,
    );
    return Message::make($message, $variables, WATCHDOG_INFO);
  }
  else {

    // Uninstalling the modules failed, can not be more specifc about why.
    $message = "The modules @uninstalled were NOT uninstalled successfully.  Check to see that the modules you are attempting to uninstall include any dependents in the correct order.";
    $variables = array(
      '@uninstalled' => $module_list,
    );
    Message::make($message, $variables, WATCHDOG_ERROR);
    throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
  }
}