private static function Settings::confirmSet in Hook Update Deploy Tools 8
Same name and namespace in other branches
- 7 src/Settings.php \HookUpdateDeployTools\Settings::confirmSet()
Checks to see if the variable was not set.
Parameters
string $name: The name of the variable that was set.
mixed $value: The value that should have been set
mixed $original_value: The original value of the variable.
Return value
string String message if it was not set correctly.
Throws
HudtException If variable does not remain set, calls the update a failure, preventing it from registering the update_N.
1 call to Settings::confirmSet()
- Settings::set in src/
Settings.php - Sets a Drupal variable but adds testing loop and feedback.
File
- src/
Settings.php, line 57
Class
- Settings
- Public methods for altering Settings.
Namespace
HookUpdateDeployToolsCode
private static function confirmSet($name, $value, $original_value) {
$variables = self::reloadVars();
$saved_value = array_key_exists($name, $variables) ? $variables[$name] : 'not set';
$type = gettype($saved_value);
$type_original = gettype($original_value);
$msg_vars = array(
'!name' => $name,
'!value' => print_r($value, TRUE),
'!saved_value' => print_r($saved_value, TRUE),
'!original_value' => print_r($original_value, TRUE),
'!type' => $type,
'!typeorig' => $type_original,
);
// Switct race: First one to evaluate TRUE wins.
switch (TRUE) {
case $saved_value === 'not set':
// There was no setting saved. Fail update.
$message = "The variable '!name' was not saved at all. It does not exist.";
$return = Message::make($message, $msg_vars, WATCHDOG_ERROR, 1);
throw new HudtException($message, $msg_vars, WATCHDOG_ERROR, FALSE);
case $saved_value == $value:
// The save worked correctly.
if ($saved_value === 'not set' || $original_value === 'not set') {
// The variable was NOT originally set.
$message = "The variable '!name' was initiated and set to !type:'!value'.";
}
else {
// The variable was originally set.
$message = "The variable '!name' was changed from !typeorig:'!original_value' to !type:'!value'.";
}
$return = Message::make($message, $msg_vars, WATCHDOG_INFO, 1);
break;
default:
// The value did not match what was saved. Fail update.
$message = "The variable '!name' did not correctly set to '!value'. Value of !type:'!saved_value' found instead. Most likely caused by a \$conf override in settings.php.";
$return = Message::make($message, $msg_vars, WATCHDOG_ERROR, 1);
throw new HudtException($message, $msg_vars, WATCHDOG_ERROR, FALSE);
}
return $return;
}