Beispiel #1
0
 /**
  * 判断一个系统任务是否存在,不存在就加一个,存在就启动并更新运行时间
  */
 public function getSysCron($cronFile, $time = 0)
 {
     Wind::import('SRV:cron.dm.PwCronDm');
     $ds = $this->_getCronDs();
     $cron = $ds->getCronByFile($cronFile);
     if ($cron['cron_id']) {
         if (!$time) {
             list($day, $hour, $minute) = explode('-', $cron['loop_daytime']);
             $time = $this->getNextTime($cron['loop_type'], $day, $hour, $minute);
         }
         $dm = new PwCronDm($cron['cron_id']);
         $dm->setNexttime($time);
         $ds->updateCron($dm);
     } else {
         $dm = new PwCronDm();
         $dm->setSubject($cronFile)->setLooptype('day')->setLoopdaytime('0', '3', '0')->setCronfile($cronFile)->setNexttime($time)->setIsopen(2);
         $ds->addCron($dm);
     }
     return true;
 }
Beispiel #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");
 }