]> git.mxchange.org Git - friendica.git/blob - include/cronhooks.php
[frio] Capitalize dropdown menu links
[friendica.git] / include / cronhooks.php
1 <?php
2
3 require_once("boot.php");
4
5
6 function cronhooks_run(&$argv, &$argc){
7         global $a, $db;
8
9         if(is_null($a)) {
10                 $a = new App;
11         }
12
13         if(is_null($db)) {
14                 @include(".htconfig.php");
15                 require_once("include/dba.php");
16                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
17                 unset($db_host, $db_user, $db_pass, $db_data);
18         };
19
20         require_once('include/session.php');
21         require_once('include/datetime.php');
22
23         load_config('config');
24         load_config('system');
25
26         // Don't check this stuff if the function is called by the poller
27         if (App::callstack() != "poller_run") {
28                 if (App::maxload_reached())
29                         return;
30                 if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
31                         return;
32         }
33
34         load_hooks();
35
36         if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
37                 foreach ($a->hooks["cron"] as $hook)
38                         if ($hook[1] == $argv[1]) {
39                                 logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG);
40                                 call_single_hook($a, $name, $hook, $data);
41                         }
42                 return;
43         }
44
45         $last = get_config('system','last_cronhook');
46
47         $poll_interval = intval(get_config('system','cronhook_interval'));
48         if(! $poll_interval)
49                 $poll_interval = 9;
50
51         if($last) {
52                 $next = $last + ($poll_interval * 60);
53                 if($next > time()) {
54                         logger('cronhook intervall not reached');
55                         return;
56                 }
57         }
58
59         $a->set_baseurl(get_config('system','url'));
60
61         logger('cronhooks: start');
62
63         $d = datetime_convert();
64
65         if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
66                 foreach ($a->hooks["cron"] as $hook) {
67                         logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG);
68                         proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
69                 }
70         } else
71                 call_hooks('cron', $d);
72
73         logger('cronhooks: end');
74
75         set_config('system','last_cronhook', time());
76
77         return;
78 }
79
80 if (array_search(__file__,get_included_files())===0){
81         cronhooks_run($_SERVER["argv"],$_SERVER["argc"]);
82         killme();
83 }