function ultimate_cron_requirements in Ultimate Cron 7.2
Same name and namespace in other branches
- 8.2 ultimate_cron.install \ultimate_cron_requirements()
- 8 ultimate_cron.install \ultimate_cron_requirements()
- 6 ultimate_cron.install \ultimate_cron_requirements()
- 7 ultimate_cron.install \ultimate_cron_requirements()
Implements hook_requirements().
File
- ./
ultimate_cron.install, line 270 - Installation file for Ultimate Cron.
Code
function ultimate_cron_requirements($phase) {
$response = array();
switch ($phase) {
case 'install':
return $response;
case 'update':
if (!module_exists('ctools')) {
$t = get_t();
$ctools['title'] = 'Ultimate Cron';
$ctools['value'] = $t('Error');
$ctools['severity'] = REQUIREMENT_ERROR;
$ctools['value'] = $t('Chaos tool suite (ctools) is not enabled!');
$ctools['description'] = $t('You must install and enable Chaos tool suite (ctools) before upgrading Ultimate Cron.');
$response['ultimate_cron'] = $ctools;
}
return $response;
case 'runtime':
$t = get_t();
$response['title'] = 'Ultimate Cron';
$response['value'] = array();
$response['description'] = array();
$response['severity'] = REQUIREMENT_OK;
// Check if any jobs are behind.
$jobs_behind = 0;
$jobs = array();
$log_entries = array();
try {
$jobs = _ultimate_cron_job_load_all();
$class = _ultimate_cron_get_class('job');
$log_entries = $class::loadLatestLogEntries($jobs);
} catch (\RuntimeException $e) {
$response['severity'] = REQUIREMENT_ERROR;
$response['value'][] = $t('Error');
$response['description'][] = $t('Runtime exception: %message.', array(
'%message' => $e
->getMessage(),
));
watchdog_exception('ultimate_cron', $e);
}
foreach ($jobs as $job) {
$job->log_entry = $log_entries[$job->name];
if ($job
->isBehindSchedule()) {
$jobs_behind++;
}
}
if ($jobs_behind) {
$response['severity'] = $response['severity'] > REQUIREMENT_ERROR ? $response['severity'] : REQUIREMENT_ERROR;
$response['value'][] = format_plural($jobs_behind, '@count job is behind schedule', '@count jobs are behind schedule');
$response['description'][] = $t('Some jobs are behind their schedule. Please check if !link is running properly.', array(
'!link' => l($t('cron'), 'admin/config/system/cron'),
));
}
// Check for PHP safe mode.
// phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
if (ini_get('safe_mode')) {
$response['severity'] = $response['severity'] > REQUIREMENT_WARNING ? $response['severity'] : REQUIREMENT_WARNING;
$response['value'][] = $t('Safe mode enabled');
$response['description'][] = $t('Safe mode enabled. Ultimate Cron is unable to control maximum execution time for cron jobs. This may cause cron jobs to end prematurely.');
}
if (variable_get('ultimate_cron_disable_scheduled', 0)) {
$response['severity'] = $response['severity'] > REQUIREMENT_WARNING ? $response['severity'] : REQUIREMENT_WARNING;
$response['value'][] = $t('Scheduling disabled');
$response['description'][] = $t('Scheduling disabled. Cannot launch scheduled jobs while <tt>ultimate_cron_disable_scheduled</tt> variable is set.');
}
if (variable_get('maintenance_mode', 0)) {
$response['severity'] = $response['severity'] > REQUIREMENT_WARNING ? $response['severity'] : REQUIREMENT_WARNING;
$response['value'][] = $t('Maintenance mode enabled');
$response['description'][] = $t('Maintenance mode enabled. Cannot launch scheduled jobs while in maintenance mode.');
}
// Compose result.
if (empty($response['value'])) {
$response['value'] = $t('Cron is running properly.');
$response['description'] = '';
}
else {
$response['value'] = implode(', ', $response['value']);
$response['description'] = implode('<br/>', $response['description']);
}
$result = array();
$result['ultimate_cron'] = $response;
return $result;
}
}