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