[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/cron/ -> _cron.funcs.php (source)

   1  <?php
   2  /**

   3   * This file implements cron (scheduled tasks) handling functions.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   9   *

  10   * {@internal License choice

  11   * - If you have received this file as part of a package, please find the license.txt file in

  12   *   the same folder or the closest folder above for complete license terms.

  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  14   *   then you must choose one of the following licenses before using the file:

  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  17   * }}

  18   *

  19   * {@internal Open Source relicensing agreement:

  20   * }}

  21   *

  22   * @package evocore

  23   *

  24   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  25   * @author fplanque: Francois PLANQUE.

  26   *

  27   * @version $Id: _cron.funcs.php,v 1.1 2007/06/25 10:59:43 fplanque Exp $

  28   */
  29  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  30  
  31  function cron_log( $message )
  32  {
  33      global $is_web;
  34  
  35      if( $is_web )
  36      {
  37          echo '<p>'.$message.'</p>';
  38      }
  39      else
  40      {
  41          echo "\n".$message."\n";
  42      }
  43  }
  44  
  45  
  46  /**

  47   * Call a cron job.

  48   *

  49   * @param string Name of the job

  50   * @param string Params for the job

  51   */
  52  function call_job( $job_name, $job_params = array() )
  53  {
  54      global $DB, $inc_path, $Plugins;
  55  
  56      global $result_message, $result_status, $timestop, $time_difference;
  57  
  58      $result_message = NULL;
  59      $result_status = 'error';
  60  
  61      if( preg_match( '~^plugin_(\d+)_(.*)$~', $job_name, $match ) )
  62      { // Cron job provided by a plugin:
  63          if( ! is_object($Plugins) )
  64          {
  65        load_class('plugins/model/_plugins.class.php');
  66              $Plugins = & new Plugins();
  67          }
  68  
  69          $Plugin = & $Plugins->get_by_ID( $match[1] );
  70          if( ! $Plugin )
  71          {
  72              $result_message = 'Plugin for controller ['.$job_name.'] could not get instantiated.';
  73              cron_log( $result_message );
  74              return;
  75          }
  76  
  77          // CALL THE PLUGIN TO HANDLE THE JOB:

  78          $tmp_params = array( 'ctrl' => $match[2], 'params' => $job_params );
  79          $sub_r = $Plugins->call_method( $Plugin->ID, 'ExecCronJob', $tmp_params );
  80  
  81          $error_code = (int)$sub_r['code'];
  82          $result_message = $sub_r['message'];
  83      }
  84      else
  85      {
  86          $controller = $inc_path.$job_name;
  87          if( ! is_file( $controller ) )
  88          {
  89              $result_message = 'Controller ['.$job_name.'] does not exist.';
  90              cron_log( $result_message );
  91              return;
  92          }
  93  
  94          // INCLUDE THE JOB FILE AND RUN IT:

  95          $error_code = require $controller;
  96      }
  97  
  98      if( $error_code != 1 )
  99      {    // We got an error
 100          $result_status = 'error';
 101          $result_message = '[Error code: '.$error_code.' ] '.$result_message;
 102      }
 103      else
 104      {
 105          $result_status = 'finished';
 106      }
 107  
 108      $timestop = time() + $time_difference;
 109      cron_log( 'Task finished at '.date( 'H:i:s', $timestop ).' with status: '.$result_status
 110          ."\nMessage: $result_message" );
 111  }
 112  
 113  
 114  /*

 115   * $Log: _cron.funcs.php,v $

 116   * Revision 1.1  2007/06/25 10:59:43  fplanque

 117   * MODULES (refactored MVC)

 118   *

 119   * Revision 1.10  2007/04/26 00:11:09  fplanque

 120   * (c) 2007

 121   *

 122   * Revision 1.9  2006/11/24 18:27:24  blueyed

 123   * Fixed link to b2evo CVS browsing interface in file docblocks

 124   *

 125   * Revision 1.8  2006/09/02 00:14:43  blueyed

 126   * Display cron job message on a single line

 127   *

 128   * Revision 1.7  2006/08/30 18:10:01  blueyed

 129   * Re-use existing $Plugins event

 130   *

 131   * Revision 1.6  2006/08/28 20:16:29  blueyed

 132   * Added GetCronJobs/ExecCronJob Plugin hooks.

 133   *

 134   * Revision 1.5  2006/08/24 00:43:28  fplanque

 135   * scheduled pings part 2

 136   *

 137   * Revision 1.4  2006/07/16 23:07:19  fplanque

 138   * no message

 139   *

 140   * Revision 1.2  2006/06/13 21:52:44  blueyed

 141   * Added files from 1.8 branch

 142   *

 143   * Revision 1.1.2.1  2006/06/12 20:00:37  fplanque

 144   * one too many massive syncs...

 145   *

 146   */
 147  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics