ReadinessCheckerManager.php in Automatic Updates 7
File
ReadinessCheckers/ReadinessCheckerManager.php
View source
<?php
class ReadinessCheckerManager {
protected static $checkers = [];
protected static function getCheckers() {
static::$checkers['warning'][0][] = 'BlacklistPhp72Versions';
static::$checkers['warning'][0][] = 'CronFrequency';
static::$checkers['warning'][0][] = 'FileOwnership';
static::$checkers['warning'][0][] = 'MissingProjectInfo';
static::$checkers['warning'][0][] = 'ModifiedFiles';
static::$checkers['warning'][0][] = 'PhpSapi';
static::$checkers['error'][0][] = 'DiskSpace';
static::$checkers['error'][0][] = 'OpcodeCache';
static::$checkers['error'][0][] = 'PendingDbUpdates';
static::$checkers['error'][0][] = 'ReadOnlyFilesystem';
return static::$checkers;
}
public static function run($category) {
$messages = [];
if (!static::isEnabled()) {
return $messages;
}
if (!isset(static::getSortedCheckers()[$category])) {
throw new \InvalidArgumentException(sprintf('No readiness checkers exist of category "%s"', $category));
}
foreach (static::getSortedCheckers()[$category] as $checker) {
$messages[] = $checker::run();
}
$messages = array_merge(...$messages);
$previous_messages = variable_get("automatic_updates.readiness_check_results.{$category}");
if ($previous_messages !== $messages) {
variable_set("automatic_updates.readiness_check_results.{$category}", $messages);
}
if (variable_get('automatic_updates.readiness_check_timestamp') !== REQUEST_TIME) {
variable_set('automatic_updates.readiness_check_timestamp', REQUEST_TIME);
}
return $messages;
}
public static function getResults($category) {
$results = [];
if (static::isEnabled()) {
$results = variable_get("automatic_updates.readiness_check_results.{$category}", []);
}
return $results;
}
public static function timestamp() {
$last_check_timestamp = variable_get('automatic_updates.readiness_check_timestamp');
if (!is_numeric($last_check_timestamp)) {
$last_check_timestamp = variable_get('install_time', 0);
}
return $last_check_timestamp;
}
public static function isEnabled() {
return variable_get('automatic_updates_enable_readiness_checks', TRUE);
}
public static function getCategories() {
return [
'error',
'warning',
];
}
protected static function getSortedCheckers() {
$sorted = [];
foreach (static::getCheckers() as $category => $priorities) {
foreach ($priorities as $checkers) {
krsort($checkers);
$sorted[$category][] = $checkers;
}
$sorted[$category] = array_unique(array_merge(...$sorted[$category]));
}
return $sorted;
}
}