public static function Contexts::checkDisabled in Hook Update Deploy Tools 7
Check to see if contexts are actually disabled.
Parameters
array $contexts: An array of context machine names to check for being disabled.
Return value
string Messsage indicating the contexts are disabled
Throws
\HudtException Calls the update a failure, preventing it from registering the update_N.
1 call to Contexts::checkDisabled()
- Contexts::disable in src/
Contexts.php - Disables an array of contexts and checks to make sure they were disabled.
File
- src/
Contexts.php, line 21
Class
- Contexts
- Public method for managing Contexts that verifies the changes.
Namespace
HookUpdateDeployToolsCode
public static function checkDisabled($contexts = array()) {
$contexts = (array) $contexts;
$enabled_contexts = array();
$t = get_t();
$enabled = $t('enabled');
$not_enabled = $t('disabled');
$not_present = $t('not present');
$report = array();
self::canSwitch();
$existing_contexts = context_load(NULL, TRUE);
// Check to see if each context is disabled.
foreach ($contexts as $context) {
if (!empty($existing_contexts[$context])) {
// The context is present.
if (!empty($existing_contexts[$context]->disabled)) {
// The context is disabled.
$report[$context] = $not_enabled;
}
else {
// This context is enabled.
$report[$context] = $enabled;
}
}
else {
// The context does not exist, which is close enough to disabled.
$report[$context] = "{$not_enabled} - {$not_present}";
}
}
if (in_array($enabled, $report)) {
$message = 'The contexts that were supposed to be disabled by this update, were not. Please investigate the problem and re-run this update. Report: !report';
$variables = array(
'!report' => $report,
);
throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
}
else {
$message = "The requested contexts are disabled. Report: !report";
$variables = array(
'!report' => $report,
);
return Message::make($message, $variables, WATCHDOG_INFO);
}
}