Elgg  Version 1.9
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('public_pages', 'walled_garden', '_elgg_cron_public_pages');
19  elgg_register_plugin_hook_handler('cron', 'all', '_elgg_cron_monitor', 1000);
20 
21  elgg_set_config('elgg_cron_periods', array(
22  'minute',
23  'fiveminute',
24  'fifteenmin',
25  'halfhour',
26  'hourly',
27  'daily',
28  'weekly',
29  'monthly',
30  'yearly',
31  // reboot is deprecated and probably does not work
32  'reboot',
33  ));
34 
35  elgg_register_admin_menu_item('administer', 'cron', 'statistics');
36 }
37 
47 function _elgg_cron_page_handler($page) {
48  if (!isset($page[0])) {
49  forward();
50  }
51 
52  $period = strtolower($page[0]);
53 
54  $allowed_periods = elgg_get_config('elgg_cron_periods');
55 
56  if (!in_array($period, $allowed_periods)) {
57  throw new CronException("$period is not a recognized cron period.");
58  }
59 
60  // Get a list of parameters
61  $params = array();
62  $params['time'] = time();
63 
64  // Data to return to
65  $old_stdout = "";
66  ob_start();
67 
68  $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout);
69  $std_out = ob_get_clean();
70 
71  echo $std_out . $old_stdout;
72  return true;
73 }
74 
85 function _elgg_cron_monitor($hook, $period, $output, $params) {
86  $time = $params['time'];
87  $periods = elgg_get_config('elgg_cron_periods');
88 
89  if (in_array($period, $periods)) {
90  $key = "cron_latest:$period:ts";
91  elgg_get_site_entity()->setPrivateSetting($key, $time);
92  }
93 }
94 
107 
108  $periods = elgg_get_config('elgg_cron_periods');
109  foreach ($periods as $period) {
110  $pages[] = "cron/$period";
111  }
112 
113  return $pages;
114 }
115 
116 elgg_register_event_handler('init', 'system', '_elgg_cron_init');
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_get_site_entity($site_guid=0)
Get an ElggSite entity (default is current site)
Definition: sites.php:18
_elgg_cron_page_handler($page)
Cron handler.
Definition: cron.php:47
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)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
$params
Definition: login.php:72
_elgg_cron_public_pages($hook, $type, $pages, $params)
Register cron&#39;s pages as public in case we&#39;re in Walled Garden mode.
Definition: cron.php:106
elgg_register_admin_menu_item($section, $menu_id, $parent_id=null, $priority=100)
Add an admin area section or child section.
Definition: admin.php:192
$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)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
_elgg_cron_monitor($hook, $period, $output, $params)
Record cron running.
Definition: cron.php:85
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
$type
Definition: add.php:8
_elgg_cron_init()
Cron initialization.
Definition: cron.php:15
$periods
Cron statistics.
Definition: cron.php:7
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
$pages
Definition: pagination.php:51
$output
Definition: item.php:10