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