]> git.mxchange.org Git - friendica.git/blob - src/Worker/CronHooks.php
42670eb2380f514dfe559c362c4ce1c2da21a537
[friendica.git] / src / Worker / CronHooks.php
1 <?php
2 namespace Friendica\Worker;
3
4 use Friendica\Core\Config;
5 use Friendica\Core\Worker;
6
7 Class CronHooks {
8         public static function execute($hook = '') {
9                 global $a;
10
11                 require_once 'include/datetime.php';
12
13                 if (($hook != '') && is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
14                         foreach ($a->hooks["cron"] as $single_hook) {
15                                 if ($single_hook[1] == $hook) {
16                                         logger("Calling cron hook '" . $hook . "'", LOGGER_DEBUG);
17                                         call_single_hook($a, $name, $single_hook, $data);
18                                 }
19                         }
20                         return;
21                 }
22
23                 $last = Config::get('system', 'last_cronhook');
24
25                 $poll_interval = intval(Config::get('system', 'cronhook_interval'));
26                 if (!$poll_interval) {
27                         $poll_interval = 9;
28                 }
29
30                 if ($last) {
31                         $next = $last + ($poll_interval * 60);
32                         if ($next > time()) {
33                                 logger('cronhook intervall not reached');
34                                 return;
35                         }
36                 }
37
38                 $a->set_baseurl(Config::get('system', 'url'));
39
40                 logger('cronhooks: start');
41
42                 $d = datetime_convert();
43
44                 if (is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
45                         foreach ($a->hooks["cron"] as $hook) {
46                                 logger("Calling cronhooks for '" . $hook[1] . "'", LOGGER_DEBUG);
47                                 Worker::add(PRIORITY_MEDIUM, "CronHooks", $hook[1]);
48                         }
49                 }
50
51                 logger('cronhooks: end');
52
53                 Config::set('system', 'last_cronhook', time());
54
55                 return;
56         }
57 }