diff options
Diffstat (limited to 'apis')
-rw-r--r-- | apis/clientlog.inc.php | 2 | ||||
-rw-r--r-- | apis/cron.inc.php | 33 | ||||
-rw-r--r-- | apis/getconfig.inc.php | 2 |
3 files changed, 25 insertions, 12 deletions
diff --git a/apis/clientlog.inc.php b/apis/clientlog.inc.php index b68e4632..29838dfc 100644 --- a/apis/clientlog.inc.php +++ b/apis/clientlog.inc.php @@ -9,7 +9,7 @@ if (empty($_POST['type'])) die('Missing options.'); $type = mb_strtolower($_POST['type']); -if ($type{0} === '~' || $type{0} === '.') { +if ($type[0] === '~' || $type[0] === '.') { if (Module::isAvailable('statistics')) { require 'modules/statistics/api.inc.php'; } diff --git a/apis/cron.inc.php b/apis/cron.inc.php index 75d7f132..03b6201f 100644 --- a/apis/cron.inc.php +++ b/apis/cron.inc.php @@ -14,15 +14,15 @@ define('CRON_KEY_STATUS', 'cron.key.status'); define('CRON_KEY_BLOCKED', 'cron.key.blocked'); // Crash report mode - used by system crontab entry -if (($report = Request::get('crashreport', false, 'string'))) { +if (($report = Request::get('crashreport', false, 'string')) !== false) { $list = Property::getList(CRON_KEY_STATUS); if (empty($list)) { error_log('Cron crash report triggered but no cronjob marked active.'); exit(0); } $str = array(); - foreach ($list as $item) { - Property::removeFromList(CRON_KEY_STATUS, $item); + foreach ($list as $subkey => $item) { + Property::removeFromListByKey(CRON_KEY_STATUS, $subkey); $entry = explode('|', $item, 2); if (count($entry) !== 2) continue; @@ -35,7 +35,7 @@ if (($report = Request::get('crashreport', false, 'string'))) { if (empty($str)) { $str = 'an unknown module'; } - $message = 'Conjob failed. No reply by ' . implode(', ', $str); + $message = 'Cronjob failed. No reply by ' . implode(', ', $str); $details = ''; if (is_readable($report)) { $details = file_get_contents($report); @@ -62,9 +62,22 @@ function getJobStatus($id) } // Hooks by other modules -function handleModule($file) +function handleModule(Hook $hook): void { - include_once $file; + global $cron_log_text; + $cron_log_text = ''; + include_once $hook->file; + if (!empty($cron_log_text)) { + EventLog::info('CronJob ' . $hook->moduleId . ' finished.', $cron_log_text); + } +} + +$cron_log_text = ''; +function cron_log($text) +{ + // XXX: Enable this code for debugging -- make this configurable some day + //global $cron_log_text; + //$cron_log_text .= $text . "\n"; } $blocked = Property::getList(CRON_KEY_BLOCKED); @@ -75,13 +88,13 @@ foreach (Hook::load('cron') as $hook) { $runtime = (time() - $status['start']); if ($runtime < 0) { // Clock skew - Property::removeFromList(CRON_KEY_STATUS, $status['string']); + Property::removeFromListByVal(CRON_KEY_STATUS, $status['string']); } elseif ($runtime < 900) { // Allow up to 15 minutes for a job to complete before we complain... continue; } else { // Consider job crashed - Property::removeFromList(CRON_KEY_STATUS, $status['string']); + Property::removeFromListByVal(CRON_KEY_STATUS, $status['string']); EventLog::failure('Cronjob for module ' . $hook->moduleId . ' seems to be stuck or has crashed.'); continue; } @@ -93,10 +106,10 @@ foreach (Hook::load('cron') as $hook) { $value = $hook->moduleId . '|' . time(); Property::addToList(CRON_KEY_STATUS, $value, 30); try { - handleModule($hook->file); + handleModule($hook); } catch (Exception $e) { // Logging EventLog::failure('Cronjob for module ' . $hook->moduleId . ' has crashed. Check the php or web server error log.', $e->getMessage()); } - Property::removeFromList(CRON_KEY_STATUS, $value); + Property::removeFromListByVal(CRON_KEY_STATUS, $value); } diff --git a/apis/getconfig.inc.php b/apis/getconfig.inc.php index 3fe05ed1..a5d5254d 100644 --- a/apis/getconfig.inc.php +++ b/apis/getconfig.inc.php @@ -6,7 +6,7 @@ */ if (!Module::isAvailable('baseconfig')) { - Util::traceError('Module baseconfig not available'); + ErrorHandler::traceError('Module baseconfig not available'); } require 'modules/baseconfig/api.inc.php';
\ No newline at end of file |