Beispiel #1
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");
 }
Beispiel #2
0
 /**
  * 更新系统计划任务
  * 
  * Enter description here ...
  */
 public function updateSysCron()
 {
     $ds = $this->_getCronDs();
     Wind::import('SRV:cron.dm.PwCronDm');
     $path = Wind::getRealPath('SRV:cron.srv.system.systemCron');
     if (!is_file($path)) {
         return false;
     }
     $cron = @(include $path);
     $sysCron = $ds->getList(2);
     $_sysCron = array();
     foreach ($sysCron as $k => $v) {
         $_sysCron[$v['cron_file']] = $v;
     }
     foreach ($cron as $k => $v) {
         if (!in_array($v['type'], array('month', 'week', 'day', 'hour', 'now'))) {
             continue;
         }
         if (!$v['file']) {
             continue;
         }
         $cronInfo = $ds->getCronByFile($v['file']);
         //if ($cronInfo) $ds->deleteCron($cronInfo['cron_id']);
         $day = $v['time']['day'];
         $hour = $v['time']['hour'];
         $minute = $v['time']['minute'];
         if ($cronInfo) {
             $dm = new PwCronDm($cronInfo['cron_id']);
         } else {
             $dm = new PwCronDm();
         }
         $dm->setSubject($v['name'])->setLooptype($v['type'])->setCronfile($v['file'])->setIsopen(PwCron::SYSTEM)->setCreatedtime(Pw::getTime());
         switch ($v['type']) {
             case 'month':
                 $nexttime = $this->getNextTime('month', $day, $hour);
                 $dm->setLoopdaytime($day, $hour)->setNexttime($nexttime);
                 break;
             case 'week':
                 $nexttime = $this->getNextTime('week', $day, $hour);
                 $dm->setLoopdaytime($day, $hour)->setNexttime($nexttime);
                 break;
             case 'day':
                 $nexttime = $this->getNextTime('day', 0, $hour);
                 $dm->setLoopdaytime(0, $hour)->setNexttime($nexttime);
                 break;
             case 'hour':
                 $nexttime = $this->getNextTime('hour', 0, 0, $minute);
                 $dm->setLoopdaytime(0, 0, $minute)->setNexttime($nexttime);
                 break;
             case 'now':
                 $nexttime = $this->getNextTime('now', $day, $hour, $minute);
                 $dm->setLoopdaytime($day, $hour, $minute)->setNexttime($nexttime);
                 break;
             default:
                 return false;
         }
         if ($cronInfo) {
             $resource = $ds->updateCron($dm);
         } else {
             $resource = $ds->addCron($dm);
         }
         unset($_sysCron[$v['file']]);
     }
     foreach ($_sysCron as $v) {
         $ds->deleteCron($v['cron_id']);
     }
     return true;
 }