Exemplo n.º 1
0
 /**
  * Function used to prepare all cronjobs requiring execution
  *
  * This function will check all cronjobs against current time in order to determine if any of them need to run. Also allows manually running a single cronjob.
  *
  * @param string $name The name of the cronjob. Will run all cronjobs if not set.
  */
 private static function HandleCronjob($name)
 {
     if (!empty($name)) {
         self::SetError(404, 'CRONJOB_NOT_FOUND');
     }
     // Set 404 incase anything goes wrong
     if (preg_match(LWC::REGEX_PATH, $name) && !preg_match(LWC::REGEX_PATH_BREAKOUT, $name)) {
         if (is_array(self::$cronjobs)) {
             if (empty($name)) {
                 foreach (self::$cronjobs as $key => $cronjob) {
                     if ($cronjob['interval'] == 0 || time() < strtotime($cronjob['lastrun']) + $cronjob['interval'] * 60) {
                         // Check if the cronjob is not ready yet...
                         unset(self::$cronjobs[$key]);
                     }
                     // ...and remove it.
                 }
             } else {
                 foreach (self::$cronjobs as $cronjob) {
                     if ($cronjob['name'] == $name) {
                         self::$cronjob = $cronjob;
                         // ...and set it for execution.
                         return;
                     }
                 }
             }
         }
     }
 }