2011-08-16 05:23:17 +00:00
|
|
|
<?php
|
2017-11-12 07:26:04 +00:00
|
|
|
namespace Friendica\Worker;
|
2011-08-16 05:23:17 +00:00
|
|
|
|
2017-04-30 04:29:14 +00:00
|
|
|
use Friendica\Core\Config;
|
2017-11-05 12:15:53 +00:00
|
|
|
use Friendica\Core\Worker;
|
2011-08-15 05:59:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
Class CronHooks {
|
2017-11-12 18:50:35 +00:00
|
|
|
public static function execute($hook = '') {
|
2017-11-12 07:26:04 +00:00
|
|
|
global $a;
|
2011-08-15 05:59:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
require_once 'include/datetime.php';
|
2011-08-15 05:59:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00: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);
|
|
|
|
}
|
2016-08-02 04:28:34 +00:00
|
|
|
}
|
2017-11-12 07:26:04 +00:00
|
|
|
return;
|
2017-04-04 17:46:56 +00:00
|
|
|
}
|
2016-08-02 04:28:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
$last = Config::get('system', 'last_cronhook');
|
2015-09-12 18:22:58 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
$poll_interval = intval(Config::get('system', 'cronhook_interval'));
|
|
|
|
if (!$poll_interval) {
|
|
|
|
$poll_interval = 9;
|
|
|
|
}
|
2015-09-12 18:22:58 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
if ($last) {
|
|
|
|
$next = $last + ($poll_interval * 60);
|
|
|
|
if ($next > time()) {
|
|
|
|
logger('cronhook intervall not reached');
|
|
|
|
return;
|
|
|
|
}
|
2015-09-12 18:22:58 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
$a->set_baseurl(Config::get('system', 'url'));
|
2011-08-15 05:59:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
logger('cronhooks: start');
|
2014-04-04 08:48:02 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
$d = datetime_convert();
|
2011-08-15 05:59:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00: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]);
|
|
|
|
}
|
2016-08-02 04:28:34 +00:00
|
|
|
}
|
2011-08-15 05:59:34 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
logger('cronhooks: end');
|
2014-05-21 05:28:33 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
Config::set('system', 'last_cronhook', time());
|
2015-09-12 18:22:58 +00:00
|
|
|
|
2017-11-12 07:26:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-08-15 05:59:34 +00:00
|
|
|
}
|