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