Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.9KB

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