// Repair entries in the database
cron_repair_database();
+ // Poll contacts
+ cron_poll_contacts($argc, $argv);
+
+ logger('cron: end');
+
+ set_config('system','last_cron', time());
+
+ return;
+}
+
+/**
+ * @brief Clear cache entries
+ *
+ * @param App $a
+ */
+function cron_poll_contacts($argc, $argv) {
$manual_id = 0;
$generation = 0;
$force = false;
$restart = false;
- if(($argc > 1) && ($argv[1] == 'force'))
+ if (($argc > 1) && ($argv[1] == 'force'))
$force = true;
- if(($argc > 1) && ($argv[1] == 'restart')) {
+ if (($argc > 1) && ($argv[1] == 'restart')) {
$restart = true;
$generation = intval($argv[2]);
- if(! $generation)
+ if (!$generation)
killme();
}
- if(($argc > 1) && intval($argv[1])) {
+ if (($argc > 1) && intval($argv[1])) {
$manual_id = intval($argv[1]);
$force = true;
}
$interval = intval(get_config('system','poll_interval'));
- if(! $interval)
+ if (!$interval)
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
// If we are using the worker we don't need a delivery interval
dbesc(NETWORK_MAIL2)
);
- if(! count($contacts)) {
+ if (!count($contacts)) {
return;
}
- foreach($contacts as $c) {
+ foreach ($contacts as $c) {
$res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval($c['id'])
$update = true;
break;
}
- if(!$update)
+ if (!$update)
continue;
}
@time_sleep_until(microtime(true) + (float) $interval);
}
}
-
- logger('cron: end');
-
- set_config('system','last_cron', time());
-
- return;
}
/**
return;
}
+ load_hooks();
+
+ if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
+ foreach ($a->hooks["cron"] as $hook)
+ if ($hook[1] == $argv[1]) {
+ logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG);
+ call_single_hook($a, $name, $hook, $data);
+ }
+ return;
+ }
+
$last = get_config('system','last_cronhook');
$poll_interval = intval(get_config('system','cronhook_interval'));
$a->set_baseurl(get_config('system','url'));
- load_hooks();
-
logger('cronhooks: start');
$d = datetime_convert();
- call_hooks('cron', $d);
+ if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
+ foreach ($a->hooks["cron"] as $hook) {
+ logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG);
+ proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
+ }
+ } else
+ call_hooks('cron', $d);
logger('cronhooks: end');
* @param string $name of the hook to call
* @param string|array &$data to transmit to the callback handler
*/
-if(! function_exists('call_hooks')) {
function call_hooks($name, &$data = null) {
$stamp1 = microtime(true);
$a = get_app();
- #logger($name, LOGGER_ALL);
-
- if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
- foreach($a->hooks[$name] as $hook) {
- // Don't run a theme's hook if the user isn't using the theme
- if(strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
- continue;
+ if (is_array($a->hooks) && array_key_exists($name, $a->hooks))
+ foreach ($a->hooks[$name] as $hook)
+ call_single_hook($a, $name, $hook, $data);
+}
- @include_once($hook[0]);
- if(function_exists($hook[1])) {
- $func = $hook[1];
- //logger($name." => ".$hook[0].":".$func."()", LOGGER_DEBUG);
- $func($a,$data);
- }
- else {
- // remove orphan hooks
- q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
- dbesc($name),
- dbesc($hook[0]),
- dbesc($hook[1])
- );
- }
- }
+/**
+ * @brief Calls a single hook.
+ *
+ * @param string $name of the hook to call
+ * @param array $hook Hook data
+ * @param string|array &$data to transmit to the callback handler
+ */
+function call_single_hook($a, $name, $hook, &$data = null) {
+ // Don't run a theme's hook if the user isn't using the theme
+ if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
+ return;
+
+ @include_once($hook[0]);
+ if (function_exists($hook[1])) {
+ $func = $hook[1];
+ $func($a, $data);
+ } else {
+ // remove orphan hooks
+ q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
+ dbesc($name),
+ dbesc($hook[0]),
+ dbesc($hook[1])
+ );
}
-}}
+}
//check if an app_menu hook exist for plugin $name.
//Return true if the plugin is an app
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
// Run the cron job that calls all other jobs
- proc_run("php","include/cron.php");
+ proc_run(PRIORITY_MEDIUM, "include/cron.php");
// Run the cronhooks job separately from cron for being able to use a different timing
- proc_run("php","include/cronhooks.php");
+ proc_run(PRIORITY_MEDIUM, "include/cronhooks.php");
// Cleaning dead processes
poller_kill_stale_workers();