Mage_Cron_Model_Schedule Class Reference

Inheritance diagram for Mage_Cron_Model_Schedule:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 _construct ()
 setCronExpr ($expr)
 trySchedule ($time)
 matchCronExpression ($expr, $num)
 getNumeric ($value)

Public Attributes

const STATUS_PENDING = 'pending'
const STATUS_RUNNING = 'running'
const STATUS_SUCCESS = 'success'
const STATUS_MISSED = 'missed'
const STATUS_ERROR = 'error'


Detailed Description

Definition at line 34 of file Schedule.php.


Member Function Documentation

_construct (  ) 

Enter description here...

Reimplemented from Varien_Object.

Definition at line 42 of file Schedule.php.

00043     {
00044         $this->_init('cron/schedule');
00045     }

getNumeric ( value  ) 

Definition at line 151 of file Schedule.php.

00152     {
00153         static $data = array(
00154             'jan'=>1,
00155             'feb'=>2,
00156             'mar'=>3,
00157             'apr'=>4,
00158             'may'=>5,
00159             'jun'=>6,
00160             'jul'=>7,
00161             'aug'=>8,
00162             'sep'=>9,
00163             'oct'=>10,
00164             'nov'=>11,
00165             'dec'=>12,
00166 
00167             'sun'=>0,
00168             'mon'=>1,
00169             'tue'=>2,
00170             'wed'=>3,
00171             'thu'=>4,
00172             'fri'=>5,
00173             'sat'=>6,
00174         );
00175 
00176         if (is_numeric($value)) {
00177             return $value;
00178         }
00179 
00180         if (is_string($value)) {
00181             $value = strtolower(substr($value,0,3));
00182             if (isset($data[$value])) {
00183                 return $data[$value];
00184             }
00185         }
00186 
00187         return false;
00188     }

matchCronExpression ( expr,
num 
)

Definition at line 91 of file Schedule.php.

00092     {
00093         // handle ALL match
00094         if ($expr==='*') {
00095             return true;
00096         }
00097 
00098         // handle multiple options
00099         if (strpos($expr,',')!==false) {
00100             foreach (explode(',',$expr) as $e) {
00101                 if ($this->matchCronExpression($e, $num)) {
00102                     return true;
00103                 }
00104             }
00105             return false;
00106         }
00107 
00108         // handle modulus
00109         if (strpos($expr,'/')!==false) {
00110             $e = explode('/', $expr);
00111             if (sizeof($e)!==2) {
00112                 throw Mage::exception('Mage_Cron', "Invalid cron expression, expecting 'match/modulus': ".$expr);
00113             }
00114             if (!is_numeric($e[1])) {
00115                 throw Mage::exception('Mage_Cron', "Invalid cron expression, expecting numeric modulus: ".$expr);
00116             }
00117             $expr = $e[0];
00118             $mod = $e[1];
00119         } else {
00120             $mod = 1;
00121         }
00122 
00123         // handle all match by modulus
00124         if ($expr==='*') {
00125             $from = 0;
00126             $to = 60;
00127         }
00128         // handle range
00129         elseif (strpos($expr,'-')!==false) {
00130             $e = explode('-', $expr);
00131             if (sizeof($e)!==2) {
00132                 throw Mage::exception('Mage_Cron', "Invalid cron expression, expecting 'from-to' structure: ".$expr);
00133             }
00134 
00135             $from = $this->getNumeric($e[0]);
00136             $to = $this->getNumeric($e[1]);
00137         }
00138         // handle regular token
00139         else {
00140             $from = $this->getNumeric($expr);
00141             $to = $from;
00142         }
00143 
00144         if ($from===false || $to===false) {
00145             throw Mage::exception('Mage_Cron', "Invalid cron expression: ".$expr);
00146         }
00147 
00148         return ($num>=$from) && ($num<=$to) && ($num%$mod===0);
00149     }

setCronExpr ( expr  ) 

Definition at line 47 of file Schedule.php.

00048     {
00049         $e = preg_split('#\s+#', $expr, null, PREG_SPLIT_NO_EMPTY);
00050         if (sizeof($e)<5 || sizeof($e)>6) {
00051             throw Mage::exception('Mage_Cron', 'Invalid cron expression: '.$expr);
00052         }
00053 
00054         $this->setCronExprArr($e);
00055         return $this;
00056     }

trySchedule ( time  ) 

Checks the observer's cron expression against time

Supports $this->setCronExpr('* 0-5,10-59/5 2-10,15-25 january-june/2 mon-fri')

Parameters:
Varien_Event $event
Returns:
boolean

Definition at line 66 of file Schedule.php.

00067     {
00068         $e = $this->getCronExprArr();
00069         if (!$e || !$time) {
00070             return false;
00071         }
00072         if (!is_numeric($time)) {
00073             $time = strtotime($time);
00074         }
00075 
00076         $d = getdate(Mage::getSingleton('core/date')->timestamp($time));
00077 
00078         $match = $this->matchCronExpression($e[0], $d['minutes'])
00079             && $this->matchCronExpression($e[1], $d['hours'])
00080             && $this->matchCronExpression($e[2], $d['mday'])
00081             && $this->matchCronExpression($e[3], $d['mon'])
00082             && $this->matchCronExpression($e[4], $d['wday']);
00083 
00084         if ($match) {
00085             $this->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
00086             $this->setScheduledAt(strftime('%Y-%m-%d %H:%M', $time));
00087         }
00088         return $match;
00089     }


Member Data Documentation

const STATUS_ERROR = 'error'

Definition at line 40 of file Schedule.php.

const STATUS_MISSED = 'missed'

Definition at line 39 of file Schedule.php.

const STATUS_PENDING = 'pending'

Definition at line 36 of file Schedule.php.

const STATUS_RUNNING = 'running'

Definition at line 37 of file Schedule.php.

const STATUS_SUCCESS = 'success'

Definition at line 38 of file Schedule.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:01 2009 for Magento by  doxygen 1.5.8