Elgg  Version 1.11
cron.php
Go to the documentation of this file.
1 <?php
15 function _elgg_cron_init() {
16  elgg_register_page_handler('cron', '_elgg_cron_page_handler');
17 
18  elgg_register_plugin_hook_handler('cron', 'all', '_elgg_cron_monitor', 1000);
19 
20  elgg_set_config('elgg_cron_periods', array(
21  'minute',
22  'fiveminute',
23  'fifteenmin',
24  'halfhour',
25  'hourly',
26  'daily',
27  'weekly',
28  'monthly',
29  'yearly',
30  // reboot is deprecated and probably does not work
31  'reboot',
32  ));
33 
34  elgg_register_admin_menu_item('administer', 'cron', 'statistics');
35 }
36 
46 function _elgg_cron_page_handler($page) {
47  if (!isset($page[0])) {
48  forward();
49  }
50 
51  $period = strtolower($page[0]);
52 
53  $allowed_periods = elgg_get_config('elgg_cron_periods');
54 
55  if (!in_array($period, $allowed_periods)) {
56  throw new \CronException("$period is not a recognized cron period.");
57  }
58 
59  // Get a list of parameters
60  $params = array();
61  $params['time'] = time();
62 
63  // Data to return to
64  $old_stdout = "";
65  ob_start();
66 
67  $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout);
68  $std_out = ob_get_clean();
69 
70  echo $std_out . $old_stdout;
71  return true;
72 }
73 
84 function _elgg_cron_monitor($hook, $period, $output, $params) {
85  $time = $params['time'];
86  $periods = elgg_get_config('elgg_cron_periods');
87 
88  if (in_array($period, $periods)) {
89  $key = "cron_latest:$period:ts";
90  elgg_get_site_entity()->setPrivateSetting($key, $time);
91  }
92 }
93 
94 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
95  $events->registerHandler('init', 'system', '_elgg_cron_init');
96 };
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
Definition: sites.php:18
_elgg_cron_page_handler($page)
Cron handler.
Definition: cron.php:46
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:703
$params
Definition: login.php:72
elgg_register_admin_menu_item($section, $menu_id, $parent_id=null, $priority=100)
Add an admin area section or child section.
Definition: admin.php:142
$key
Definition: summary.php:34
elgg_set_config($name, $value)
Set an Elgg configuration value.
elgg echo
Translates a string.
Definition: languages.js:43
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:775
_elgg_cron_monitor($hook, $period, $output, $params)
Record cron running.
Definition: cron.php:84
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
_elgg_cron_init()
Cron initialization.
Definition: cron.php:15
$periods
Cron statistics.
Definition: cron.php:7
$output
Definition: item.php:10