コード例 #1
0
ファイル: CronForm.php プロジェクト: dsyman2/X2CRM
 /**
  * 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);
 }
コード例 #2
0
ファイル: CommandUtilTest.php プロジェクト: tymiles003/X2CRM
 /**
  * Tests piping and filtered piping. Can only be run on Linux/Unix.
  */
 public function testPipeFiltered()
 {
     $this->setupTestDirs();
     $u = new CommandUtil();
     $output = $u->run("find {$this->baseDir} -type f")->pipeFilteredTo('/excl/', 'echo')->output();
     $filesListed = array_filter(explode("\n", $output));
     $expectedFilesListed = array();
     foreach ($this->exclFiles as $relPath) {
         $expedtedFilesListed[] = $this->baseDir . '/' . $relPath;
     }
     $this->assertEquals($expectedFilesListed, $filesListed);
     $this->removeTestDirs();
 }
コード例 #3
0
 /**
  * Getter for {@link fileList}
  * @return array
  */
 public function getFileList()
 {
     if (!isset($this->_fileList)) {
         $cmd = new CommandUtil();
         $findCmd = "find {$this->source}/ -type f";
         $this->debug("Running find command: {$findCmd}");
         $output = $cmd->run($findCmd)->output();
         $this->debug("Output: {$output}");
         $output = explode("\n", $output);
         $this->_fileList = array();
         foreach ($output as $line) {
             if (preg_match(':(?<path>protected.+\\.php)$:', $line, $match)) {
                 $this->_fileList[] = $match['path'];
                 $this->debug("file in file list: " . $match['path']);
             } else {
                 $this->debug("line not part of file list: {$line}");
             }
         }
     }
     return $this->_fileList;
 }