Exemple #1
0
 public function updateCron(PwCronDm $dm)
 {
     $resource = $dm->beforeUpdate();
     if ($resource instanceof PwError) {
         return $resource;
     }
     return $this->_getDao()->updateCron($dm->cronId, $dm->getData());
 }
Exemple #2
0
 public function doeditAction()
 {
     Wind::import('SRV:cron.dm.PwCronDm');
     $cronId = (int) $this->getInput('id', 'post');
     if ($cronId < 1) {
         $this->showError("operate.fail");
     }
     $type = $this->getInput('looptype', 'post');
     $isopen = $this->getInput('isopen', 'post');
     $filename = $this->getInput('filename', 'post');
     $subject = $this->getInput('subject', 'post');
     if (!$subject && !$filename) {
         $this->showError("operate.fail");
     }
     $dm = new PwCronDm($cronId);
     $dm->setSubject($subject)->setLooptype($type)->setCronfile($filename)->setIsopen($isopen)->setCreatedtime(Pw::getTime());
     switch ($type) {
         case 'month':
             $day = $this->getInput('month_day', 'post');
             $hour = $this->getInput('month_hour', 'post');
             $nexttime = $this->_getCronService()->getNextTime('month', $day, $hour);
             $dm->setLoopdaytime($day, $hour)->setNexttime($nexttime);
             break;
         case 'week':
             $day = $this->getInput('week_day', 'post');
             $hour = $this->getInput('week_hour', 'post');
             $nexttime = $this->_getCronService()->getNextTime('week', $day, $hour);
             $dm->setLoopdaytime($day, $hour)->setNexttime($nexttime);
             break;
         case 'day':
             $hour = $this->getInput('day_hour', 'post');
             $nexttime = $this->_getCronService()->getNextTime('day', 0, $hour);
             $dm->setLoopdaytime(0, $hour)->setNexttime($nexttime);
             break;
         case 'hour':
             $minute = $this->getInput('hour_minute', 'post');
             $nexttime = $this->_getCronService()->getNextTime('hour', 0, 0, $minute);
             $dm->setLoopdaytime(0, 0, $minute)->setNexttime($nexttime);
             break;
         case 'now':
             $time = (int) $this->getInput('now_time', 'post');
             $type = $this->getInput('now_type', 'post');
             if (!$time) {
                 $this->showError("operate.fail");
             }
             $minute = $type == 'minute' ? $time : 0;
             $hour = $type == 'hour' ? $time : 0;
             $day = $type == 'day' ? $time : 0;
             $nexttime = $this->_getCronService()->getNextTime('now', $day, $hour, $minute);
             $dm->setLoopdaytime($day, $hour, $minute)->setNexttime($nexttime);
             break;
         default:
             $this->showError("operate.fail");
     }
     if (!$isopen) {
         $dm->setNexttime(0);
     }
     $resource = $this->_getCronDs()->updateCron($dm);
     if ($resource instanceof PwError) {
         $this->showError($resource->getError());
     }
     $this->showMessage("operate.success");
 }
Exemple #3
0
 /**
  * 递归执行计划任务
  * Enter description here ...
  */
 public function runCron()
 {
     $_time = Pw::getTime();
     $cron = $this->_getCronDs()->getFirstCron();
     if (!$cron || $cron['next_time'] > $_time) {
         return false;
     }
     list($day, $hour, $minute) = explode('-', $cron['loop_daytime']);
     $nexttime = $this->getNextTime($cron['loop_type'], $day, $hour, $minute);
     Wind::import('SRV:cron.dm.PwCronDm');
     $dm = new PwCronDm($cron['cron_id']);
     $dm->setSubject($cron['subject'])->setCronfile($cron['cron_file'])->setModifiedtime($_time)->setNexttime($nexttime);
     $this->_getCronDs()->updateCron($dm);
     if (!$this->_runAction($cron['cron_file'], $cron['cron_id'])) {
         return false;
     }
     $this->runCron();
     return true;
 }