friendica-github/src/Worker/CronHooks.php

62 lines
1.3 KiB
PHP
Raw Normal View History

2011-08-16 05:23:17 +00:00
<?php
2017-11-18 07:31:33 +00:00
/**
* @file src/Worker/CronHooks.php
*/
2017-11-12 07:26:04 +00:00
namespace Friendica\Worker;
2011-08-16 05:23:17 +00:00
use Friendica\Core\Config;
2017-11-05 12:15:53 +00:00
use Friendica\Core\Worker;
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;
2017-11-12 07:26:04 +00:00
require_once 'include/datetime.php';
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);
2017-11-12 21:32:10 +00:00
call_single_hook($a, $name, $single_hook, $data);
2017-11-12 07:26:04 +00:00
}
}
2017-11-12 07:26:04 +00:00
return;
}
2017-11-12 07:26:04 +00:00
$last = Config::get('system', 'last_cronhook');
2017-11-12 07:26:04 +00:00
$poll_interval = intval(Config::get('system', 'cronhook_interval'));
if (!$poll_interval) {
$poll_interval = 9;
}
2017-11-12 07:26:04 +00:00
if ($last) {
$next = $last + ($poll_interval * 60);
if ($next > time()) {
logger('cronhook intervall not reached');
return;
}
}
2017-11-12 07:26:04 +00:00
$a->set_baseurl(Config::get('system', 'url'));
2017-11-12 07:26:04 +00:00
logger('cronhooks: start');
2017-11-12 07:26:04 +00:00
$d = datetime_convert();
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]);
}
}
2017-11-12 07:26:04 +00:00
logger('cronhooks: end');
2017-11-12 07:26:04 +00:00
Config::set('system', 'last_cronhook', time());
2017-11-12 07:26:04 +00:00
return;
}
}