diff options
Diffstat (limited to 'engine/lib/cron.php')
| -rw-r--r-- | engine/lib/cron.php | 84 |
1 files changed, 45 insertions, 39 deletions
diff --git a/engine/lib/cron.php b/engine/lib/cron.php index d51a34bf7..4f3d05b93 100644 --- a/engine/lib/cron.php +++ b/engine/lib/cron.php @@ -7,51 +7,57 @@ */ /** - * Initialisation + * Cron initialization * * @return void + * @access private */ function cron_init() { // Register a pagehandler for cron - register_page_handler('cron', 'cron_page_handler'); + elgg_register_page_handler('cron', 'cron_page_handler'); // register a hook for Walled Garden public pages - register_plugin_hook('public_pages', 'walled_garden', 'cron_public_pages'); + elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'cron_public_pages'); } /** - * Cron handler for redirecting pages. + * Cron handler * * @param array $page Pages * - * @return void + * @return bool + * @throws CronException + * @access private */ function cron_page_handler($page) { - global $CONFIG; + if (!isset($page[0])) { + forward(); + } - if ($page[0]) { - switch (strtolower($page[0])) { - case 'minute' : - case 'fiveminute' : - case 'fifteenmin' : - case 'halfhour' : - case 'hourly' : - case 'daily' : - case 'weekly' : - case 'monthly': - case 'yearly' : - case 'reboot' : - set_input('period', $page[0]); - break; - default : - throw new CronException(elgg_echo('CronException:unknownperiod', array($page[0]))); - } + $period = strtolower($page[0]); - // Include cron handler - include($CONFIG->path . "engine/handlers/cron_handler.php"); - } else { - forward(); + $allowed_periods = array( + 'minute', 'fiveminute', 'fifteenmin', 'halfhour', 'hourly', + 'daily', 'weekly', 'monthly', 'yearly', 'reboot' + ); + + if (!in_array($period, $allowed_periods)) { + throw new CronException(elgg_echo('CronException:unknownperiod', array($period))); } + + // Get a list of parameters + $params = array(); + $params['time'] = time(); + + // Data to return to + $old_stdout = ""; + ob_start(); + + $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout); + $std_out = ob_get_clean(); + + echo $std_out . $old_stdout; + return true; } /** @@ -63,21 +69,21 @@ function cron_page_handler($page) { * @param mixed $params Params * * @return array + * @access private */ function cron_public_pages($hook, $type, $return_value, $params) { - $return_value[] = 'pg/cron/minute'; - $return_value[] = 'pg/cron/fiveminute'; - $return_value[] = 'pg/cron/fifteenmin'; - $return_value[] = 'pg/cron/halfhour'; - $return_value[] = 'pg/cron/hourly'; - $return_value[] = 'pg/cron/daily'; - $return_value[] = 'pg/cron/weekly'; - $return_value[] = 'pg/cron/monthly'; - $return_value[] = 'pg/cron/yearly'; - $return_value[] = 'pg/cron/reboot'; + $return_value[] = 'cron/minute'; + $return_value[] = 'cron/fiveminute'; + $return_value[] = 'cron/fifteenmin'; + $return_value[] = 'cron/halfhour'; + $return_value[] = 'cron/hourly'; + $return_value[] = 'cron/daily'; + $return_value[] = 'cron/weekly'; + $return_value[] = 'cron/monthly'; + $return_value[] = 'cron/yearly'; + $return_value[] = 'cron/reboot'; return $return_value; } -// Register a startup event -register_elgg_event_handler('init', 'system', 'cron_init');
\ No newline at end of file +elgg_register_event_handler('init', 'system', 'cron_init'); |
