You are here

public static function Modules::checkEnabled in Hook Update Deploy Tools 7

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

Check to see if the modules are actually enabled.

Parameters

array $modules: An array of module machine names to check for being enabled.

Return value

string Messsage indicating the modules are enabled

Throws

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

1 call to Modules::checkEnabled()
Modules::enable in src/Modules.php
Enables an array of modules and checks to make sure they were enabled.

File

src/Modules.php, line 64

Class

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

Namespace

HookUpdateDeployTools

Code

public static function checkEnabled($modules = array()) {
  $modules = (array) $modules;
  $t = get_t();
  $enabled = $t('enabled');
  $not_enabled = $t('not-enabled');
  $report = array();

  // Check to see if each module is enabled.
  foreach ($modules as $module) {
    if (!module_exists($module)) {

      // This module is not enabled.
      $report[$module] = $not_enabled;
    }
    else {
      $report[$module] = $enabled;
    }
  }
  if (in_array($not_enabled, $report)) {

    // Something was not enabled. Fail the update.
    $message = 'Some of the modules that were supposed to be enabled, are not showing as enabled. Please investigate the problem and re-run this update. Report: !report';
    $variables = array(
      '!report' => $report,
    );
    throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
  }
  $module_list = implode(', ', $modules);
  $message = "The requested modules were enabled successfully. Report: !report";
  $variables = array(
    '!report' => $report,
  );
  return Message::make($message, $variables, WATCHDOG_INFO);
}