friendica/src/Worker/CronHooks.php

62 lines
1.3 KiB
PHP
Raw Normal View History

2011-08-16 01:23:17 -04:00
<?php
2017-11-18 02:31:33 -05:00
/**
* @file src/Worker/CronHooks.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 {
2017-11-12 13:50:35 -05:00
public static function execute($hook = '') {
2017-11-12 02:26:04 -05:00
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);
2017-11-12 16:32:10 -05:00
call_single_hook($a, $name, $single_hook, $data);
2017-11-12 02:26:04 -05:00
}
}
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;
}
}