friendica/src/Worker/CronHooks.php

58 lines
1.3 KiB
PHP
Raw Normal View History

2011-08-16 01:23:17 -04:00
<?php
2017-11-12 02:26:04 -05:00
namespace Friendica\Worker;
2011-08-16 01:23:17 -04:00
use Friendica\Core\Config;
2017-11-05 07:15:53 -05:00
use Friendica\Core\Worker;
2017-11-12 02:26:04 -05:00
Class CronHooks {
static public function execute($hook = '') {
global $a;
2017-11-12 02:26:04 -05:00
require_once 'include/datetime.php';
2017-11-12 02:26:04 -05:00
if (($hook != '') && is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
foreach ($a->hooks["cron"] as $single_hook) {
if ($single_hook[1] == $hook) {
logger("Calling cron hook '" . $hook . "'", LOGGER_DEBUG);
call_single_hook($a, $name, $hook, $data);
}
}
2017-11-12 02:26:04 -05:00
return;
}
2017-11-12 02:26:04 -05:00
$last = Config::get('system', 'last_cronhook');
2017-11-12 02:26:04 -05:00
$poll_interval = intval(Config::get('system', 'cronhook_interval'));
if (!$poll_interval) {
$poll_interval = 9;
}
2017-11-12 02:26:04 -05:00
if ($last) {
$next = $last + ($poll_interval * 60);
if ($next > time()) {
logger('cronhook intervall not reached');
return;
}
}
2017-11-12 02:26:04 -05:00
$a->set_baseurl(Config::get('system', 'url'));
2017-11-12 02:26:04 -05:00
logger('cronhooks: start');
2017-11-12 02:26:04 -05:00
$d = datetime_convert();
2017-11-12 02:26:04 -05:00
if (is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
foreach ($a->hooks["cron"] as $hook) {
logger("Calling cronhooks for '" . $hook[1] . "'", LOGGER_DEBUG);
Worker::add(PRIORITY_MEDIUM, "CronHooks", $hook[1]);
}
}
2017-11-12 02:26:04 -05:00
logger('cronhooks: end');
2017-11-12 02:26:04 -05:00
Config::set('system', 'last_cronhook', time());
2017-11-12 02:26:04 -05:00
return;
}
}