phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file _cron.funcs.php

Documentation is available at _cron.funcs.php

  1. <?php
  2. /**
  3.  * This file implements cron (scheduled tasks) handling functions.
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *
  11.  *  {@internal License choice
  12.  *  - If you have received this file as part of a package, please find the license.txt file in
  13.  *    the same folder or the closest folder above for complete license terms.
  14.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15.  *    then you must choose one of the following licenses before using the file:
  16.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18.  *  }}}
  19.  *
  20.  *  {@internal Open Source relicensing agreement:
  21.  *  }}}
  22.  *
  23.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  24.  * @author fplanque: Francois PLANQUE.
  25.  *
  26.  * @package pond
  27.  */
  28. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  29.  
  30.  
  31. /**
  32.  * Log a message from cron.
  33.  * @param string Message
  34.  * @param integer Level of importance. The higher the more important.
  35.  *         (if $quiet (number of "-q" params passed to cron_exec.php)
  36.  *          is higher than this, the message gets skipped)
  37.  */
  38. function cron_log$message$level )
  39. {
  40.     global $is_web$quiet;
  41.  
  42.     if$quiet $level )
  43.     {
  44.         return;
  45.     }
  46.  
  47.     if$is_web )
  48.     {
  49.         echo '<p>'.$message.'</p>';
  50.     }
  51.     else
  52.     {
  53.         echo "\n".$message."\n";
  54.     }
  55. }
  56.  
  57.  
  58. /**
  59.  * Call a cron job.
  60.  *
  61.  * @param string Name of the job
  62.  * @param string Params for the job
  63.  */
  64. function call_job$job_name$job_params array() )
  65. {
  66.     global $DB$inc_path$Plugins;
  67.  
  68.     global $result_message$result_status$timestop$time_difference;
  69.  
  70.     $result_message NULL;
  71.     $result_status 'error';
  72.  
  73.     ifpreg_match'~^plugin_(\d+)_(.*)$~'$job_name$match ) )
  74.     // Cron job provided by a plugin:
  75.         ifis_object($Plugins) )
  76.         {
  77.       load_class('plugins/model/_plugins.class.php');
  78.             $Plugins new Plugins();
  79.         }
  80.  
  81.         $Plugin $Plugins->get_by_ID$match[1);
  82.         if$Plugin )
  83.         {
  84.             $result_message 'Plugin for controller ['.$job_name.'] could not get instantiated.';
  85.             cron_log$result_message);
  86.             return;
  87.         }
  88.  
  89.         // CALL THE PLUGIN TO HANDLE THE JOB:
  90.         $tmp_params array'ctrl' => $match[2]'params' => $job_params );
  91.         $sub_r $Plugins->call_method$Plugin->ID'ExecCronJob'$tmp_params );
  92.  
  93.         $error_code = (int)$sub_r['code'];
  94.         $result_message $sub_r['message'];
  95.     }
  96.     else
  97.     {
  98.         $controller $inc_path.$job_name;
  99.         ifis_file$controller ) )
  100.         {
  101.             $result_message 'Controller ['.$job_name.'] does not exist.';
  102.             cron_log$result_message);
  103.             return;
  104.         }
  105.  
  106.         // INCLUDE THE JOB FILE AND RUN IT:
  107.         $error_code = require $controller;
  108.     }
  109.  
  110.     if$error_code != )
  111.     {    // We got an error
  112.         $result_status 'error';
  113.         $result_message '[Error code: '.$error_code.' ] '.$result_message;
  114.         $cron_log_level 2;
  115.     }
  116.     else
  117.     {
  118.         $result_status 'finished';
  119.         $cron_log_level 1;
  120.     }
  121.  
  122.     $timestop time($time_difference;
  123.     cron_log'Task finished at '.date'H:i:s'$timestop ).' with status: '.$result_status
  124.         ."\nMessage: $result_message"$cron_log_level );
  125. }
  126.  
  127.  
  128. ?>