/** * 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(); }
/** * 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); }
try { $con->exec("DROP TABLE `x2_test_table`"); } catch (PDOException $e) { RIP(installer_tr($permsError, array('{db}' => $_POST['dbName'], '{u}' => $_POST['dbUser'])) . '; ' . installer_t('cannot drop tables')); } // Now test creating a table, with the InnoDB storage engine (required!): try { $con->exec("CREATE TABLE IF NOT EXISTS `x2_test_table` (\n\t\t\t `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t `a` varchar(10) NOT NULL,\n\t\t\t PRIMARY KEY (`id`)) ENGINE=INNODB"); } catch (PDOException $e) { RIP(installer_tr($permsError, array('{db}' => $_POST['dbName'], '{u}' => $_POST['dbUser'])) . '; ' . installer_t('the InnoDB storage engine is not available')); } $con->exec("DROP TABLE `x2_test_table`"); ResponseUtil::respond(installer_t("Connection successful!")); } elseif (isset($_POST['testCron'])) { require_once 'protected/components/util/CommandUtil.php'; $command = new CommandUtil(); try { $command->loadCrontab(); ResponseUtil::respond(installer_t('Cron can be used on this system')); } catch (Exception $e) { if ($e->getCode() == 1) { RIP(installer_t('The "crontab" command does not exist on this system, so there is no way to set up cron jobs.')); } else { RIP(installer_t('There is a cron service available on this system, but PHP is running as a system user that does not have permission to use it.')); } } } ///////////////////////////////// // Declare Installer Functions // ///////////////////////////////// /**
/** * 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; }