Source for file _cron.funcs.php
Documentation is available at _cron.funcs.php
* This file implements cron (scheduled tasks) handling functions.
* This file is part of Quam Plures - {@link http://quamplures.net/}
* See also {@link https://launchpad.net/quam-plures}.
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
* {@internal License choice
* - If you have received this file as part of a package, please find the license.txt file in
* the same folder or the closest folder above for complete license terms.
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
* then you must choose one of the following licenses before using the file:
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
* {@internal Open Source relicensing agreement:
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
* @author fplanque: Francois PLANQUE.
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
* Log a message from cron.
* @param integer Level of importance. The higher the more important.
* (if $quiet (number of "-q" params passed to cron_exec.php)
* is higher than this, the message gets skipped)
function cron_log( $message, $level = 0 )
echo '<p>'. $message. '</p>';
* @param string Name of the job
* @param string Params for the job
function call_job( $job_name, $job_params = array() )
global $DB, $inc_path, $Plugins;
global $result_message, $result_status, $timestop, $time_difference;
$result_status = 'error';
if( preg_match( '~^plugin_(\d+)_(.*)$~', $job_name, $match ) )
{ // Cron job provided by a plugin:
$Plugin = & $Plugins->get_by_ID( $match[1] );
$result_message = 'Plugin for controller ['. $job_name. '] could not get instantiated.';
// CALL THE PLUGIN TO HANDLE THE JOB:
$tmp_params = array( 'ctrl' => $match[2], 'params' => $job_params );
$sub_r = $Plugins->call_method( $Plugin->ID, 'ExecCronJob', $tmp_params );
$error_code = (int) $sub_r['code'];
$result_message = $sub_r['message'];
$controller = $inc_path. $job_name;
$result_message = 'Controller ['. $job_name. '] does not exist.';
// INCLUDE THE JOB FILE AND RUN IT:
$error_code = require $controller;
$result_status = 'error';
$result_message = '[Error code: '. $error_code. ' ] '. $result_message;
$result_status = 'finished';
$timestop = time() + $time_difference;
cron_log( 'Task finished at '. date( 'H:i:s', $timestop ). ' with status: '. $result_status
. "\nMessage: $result_message", $cron_log_level );
|