Beispiel #1
0
 /**
  * Process form data and save in the cron table
  */
 public function save($formData)
 {
     // Nothing to save
     if (!isset($formData[$this->name])) {
         $jobs = array();
     } else {
         $jobs = $formData[$this->name];
     }
     // Add/update all cron jobs for which there is form data present:
     foreach ($jobs as $tag => $job) {
         if (is_array($job)) {
             if (in_array($tag, $this->jobTags)) {
                 $this->j[$tag] = CrontabUtil::processForm($job);
                 // Overwrite cmd/desc with the default as defined in the widget declaration/job config:
                 if (!$this->allowUserCmdInput) {
                     $this->j[$tag]['cmd'] = $this->jobAttr($tag, 'cmd');
                     $this->j[$tag]['desc'] = $this->jobAttr($tag, 'desc');
                 }
             }
         }
     }
     // Delete any cron jobs not accounted for in form data, but expected:
     foreach ($this->jobTags as $tag) {
         if (!isset($jobs[$tag]) && isset($this->j[$tag])) {
             unset($this->j[$tag]);
         }
     }
     // Save the cron table:
     CrontabUtil::arrayToCrontab($this->crontab, $this->j);
     $ctFile = implode(DIRECTORY_SEPARATOR, array(Yii::app()->basePath, '.crontab.tmp'));
     file_put_contents($ctFile, $this->crontab);
     $this->cmdU->run("crontab {$ctFile}")->complete();
     unlink($ctFile);
 }