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