Cheetah
cron.php
Go to the documentation of this file.
1 <?php
2 
8 $GLOBALS['ch_profiler_disable'] = true;
9 define('CH_WSB_CRON_EXECUTE', '1');
10 
11 $aPathInfo = pathinfo(__FILE__);
12 require_once ($aPathInfo['dirname'] . '/../inc/header.inc.php');
13 require_once(CH_DIRECTORY_PATH_INC . 'utils.inc.php');
14 require_once(CH_DIRECTORY_PATH_INC . 'profiles.inc.php' );
15 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbDb.php');
16 
17 function getRange($iLow, $iHigh, $iStep)
18 {
19  $aResult = array();
20  for ($i = $iLow; $i <= $iHigh && $iStep; $i += $iStep)
21  $aResult[] = $i;
22  return $aResult;
23 }
24 
25 function getPeriod($sPeriod, $iLow, $iHigh)
26 {
27  $aRes = array();
28  $iStep = 1;
29  $sErr = '';
30 
31  do {
32  if ('' === $sPeriod) {
33  $sErr = 'Variable sPeriod is emply';
34  break;
35  }
36 
37  $aParam = explode('/', $sPeriod);
38 
39  if (count($aParam) > 2) {
40  $sErr = 'Error of format for string assigning period';
41  break;
42  }
43 
44  if (count($aParam) == 2 && is_numeric($aParam[1]))
45  $iStep = $aParam[1];
46 
47  $sPeriod = $aParam[0];
48 
49  if ($sPeriod != '*') {
50  $aParam = explode('-', $sPeriod);
51 
52  if (count($aParam) > 2) {
53  $sErr = 'Error of format for string assigning period';
54  break;
55  }
56 
57  if (count($aParam) == 2)
58  $aRes = getRange($aParam[0], $aParam[1], $iStep);
59  else
60  $aRes = explode(',', $sPeriod);
61  } else
62  $aRes = getRange($iLow, $iHigh, $iStep);
63  } while(false);
64 
65  if ($sErr) {
66  // show error or add to log
67  }
68 
69  return $aRes;
70 }
71 
72 function checkCronJob($sPeriods, $aDate = array())
73 {
74  $aParam = explode(' ', preg_replace("{ +}", ' ', trim($sPeriods)));
75  $bRes = true;
76 
77  if(empty($aDate))
78  $aDate = getdate(time());
79 
80  //$aDate = getdate(strtotime('today midnight'));
81 
82  for ($i = 0; $i < count($aParam); $i++) {
83  switch ($i) {
84  case 0:
85  $aRes = getPeriod($aParam[$i], 0, 59);
86  $bRes = in_array($aDate['minutes'], $aRes);
87  break;
88  case 1:
89  $aRes = getPeriod($aParam[$i], 0, 23);
90  $bRes = in_array($aDate['hours'], $aRes);
91  break;
92  case 2:
93  $aRes = getPeriod($aParam[$i], 1, 31);
94  $bRes = in_array($aDate['mday'], $aRes);
95  break;
96  case 3:
97  $aRes = getPeriod($aParam[$i], 1, 12);
98  $bRes = in_array($aDate['mon'], $aRes);
99  break;
100  case 4:
101  $aRes = getPeriod($aParam[$i], 0, 6);
102  $bRes = in_array($aDate['wday'], $aRes);
103  break;
104  }
105 
106  if (!$bRes)
107  break;
108  }
109 
110  return $bRes;
111 }
112 
113 function runJob($aJob)
114 {
115  if(!empty($aJob['file']) && !empty($aJob['class']) && file_exists(CH_DIRECTORY_PATH_ROOT . $aJob['file'])) {
116  if(!class_exists($aJob['class']))
117  require_once(CH_DIRECTORY_PATH_ROOT . $aJob['file']);
118 
119  $oHandler = new $aJob['class']();
120  $oHandler->processing();
121  } else if(!empty($aJob['eval'])) {
122  require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbService.php');
123  eval($aJob['eval']);
124  }
125 }
126 
128 $aJobs = $oDb->fromCache('sys_cron_jobs', 'getAll', 'SELECT * FROM `sys_cron_jobs`');
129 
131 setParam('sys_cron_time', $iDate);
132 
133 $aDate = getdate($iDate);
134 foreach($aJobs as $aRow) {
135  if (checkCronJob($aRow['time'], $aDate))
136  runJob($aRow);
137 }
$oDb
$oDb
Definition: cron.php:127
$aPathInfo
$aPathInfo
Definition: cron.php:11
checkCronJob
checkCronJob($sPeriods, $aDate=array())
Definition: cron.php:72
$aResult
$aResult
Definition: index.php:19
php
$aJobs
$aJobs
Definition: cron.php:128
runJob
runJob($aJob)
Definition: cron.php:113
$aDate
$aDate
Definition: cron.php:133
getPeriod
getPeriod($sPeriod, $iLow, $iHigh)
Definition: cron.php:25
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
$iDate
$iDate
Definition: cron.php:130
$GLOBALS
$GLOBALS['ch_profiler_disable']
Definition: cron.php:8
setParam
setParam($sParamName, $sParamValue)
Definition: db.inc.php:149
getRange
getRange($iLow, $iHigh, $iStep)
Definition: cron.php:17
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbDb\getInstance
static getInstance()
Definition: ChWsbDb.php:82