| | 21 | } |
|---|
| | 22 | |
|---|
| | 23 | |
|---|
| | 24 | protected function execute($arguments = array(), $options = array()) |
|---|
| | 25 | { |
|---|
| | 26 | $totalTimer = $this->getTimer(); |
|---|
| | 27 | chdir(sfConfig::get('sf_root_dir')); |
|---|
| | 28 | foreach ($this->_prepareCommands($arguments['profile']) as $command) { |
|---|
| | 29 | $this->_doCommand($command); |
|---|
| | 30 | } |
|---|
| | 31 | |
|---|
| | 32 | $this->showTime($totalTimer, 'Total time: '); |
|---|
| | 33 | } |
|---|
| | 34 | |
|---|
| | 35 | protected function _doCommand($command) |
|---|
| | 36 | { |
|---|
| | 37 | $command = trim($command); |
|---|
| | 38 | if(empty($command)) return; |
|---|
| | 39 | |
|---|
| | 40 | $this->logSection("Command :", $command); |
|---|
| | 41 | |
|---|
| | 42 | $timer = $this->getTimer(); |
|---|
| | 43 | $result = 0; |
|---|
| | 44 | |
|---|
| | 45 | passthru($command, $result); |
|---|
| | 46 | |
|---|
| | 47 | $this->showTime($timer); |
|---|
| | 48 | |
|---|
| | 49 | if((int)$result > 0) { |
|---|
| | 50 | $this->showTime($totalTimer, 'Total time: '); |
|---|
| | 51 | |
|---|
| | 52 | throw new Exception('Command: `' . $command . '`. Exit with error code: `'.$result.'`'); |
|---|
| | 53 | } |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| | 56 | /** |
|---|
| | 57 | * |
|---|
| | 58 | * @param string $source |
|---|
| | 59 | * |
|---|
| | 60 | * @throws Exceptino if the source cannot be found. |
|---|
| | 61 | * |
|---|
| | 62 | * @return array |
|---|
| | 63 | */ |
|---|
| | 64 | protected function _prepareCommands($source) |
|---|
| | 65 | { |
|---|
| | 66 | // guess file form project root config directory. |
|---|
| | 67 | $relativeConfigPath = sfConfig::get('sf_root_dir').'/config/'.$source; |
|---|
| | 68 | if (file_exists($relativeConfigPath)) { |
|---|
| | 69 | return file($relativeConfigPath); |
|---|
| | 70 | } |
|---|
| | 71 | |
|---|
| | 72 | // guess relative from project root |
|---|
| | 73 | $relativeRootPath = sfConfig::get('sf_root_dir') . '/'. $source; |
|---|
| | 74 | if (file_exists($relativeRootPath)) { |
|---|
| | 75 | return file($relativeRootPath); |
|---|
| | 76 | } |
|---|
| | 77 | |
|---|
| | 78 | // guess absolute |
|---|
| | 79 | $absolutePath = $source; |
|---|
| | 80 | if (file_exists($absolutePath)) { |
|---|
| | 81 | return file($absolutePath); |
|---|
| | 82 | } |
|---|
| | 83 | |
|---|
| | 84 | throw new Exception("Provided path to build profile is not exist or invalid. Given parameter is `{$source}`. The next pathes were tried: " . |
|---|
| | 85 | "\nRelative from config `{$relativeConfigPath}`," . |
|---|
| | 86 | "\nRelative from root - `{$relativeRootPath}`," . |
|---|
| | 87 | "\nAbsolute - `{$absolutePath}`"); |
|---|
| 37 | | |
|---|
| 38 | | echo $message; |
|---|
| 39 | | echo (int)$timer->getElapsedTime() . " second(s)\n"; |
|---|
| 40 | | echo $afterMessage; |
|---|
| 41 | | } |
|---|
| 42 | | |
|---|
| 43 | | protected function execute($arguments = array(), $options = array()) |
|---|
| 44 | | { |
|---|
| 45 | | $profile = $arguments['profile']; |
|---|
| 46 | | $configProfile = sfConfig::get('sf_root_dir').'/config/'.$profile; |
|---|
| 47 | | if (file_exists($configProfile)) { |
|---|
| 48 | | $profile = $configProfile; |
|---|
| 49 | | } |
|---|
| 50 | | if (!(file_exists($profile) && is_readable($profile))) { |
|---|
| 51 | | throw new Exception('Provided path to build profile is not exist or invalid. Given path is `'.$arguments['profile'].'`'); |
|---|
| 52 | | } |
|---|
| 53 | | |
|---|
| 54 | | chdir(sfConfig::get('sf_root_dir')); |
|---|
| 55 | | |
|---|
| 56 | | $totalTimer = $this->getTimer(); |
|---|
| 57 | | |
|---|
| 58 | | foreach (file($profile) as $task) |
|---|
| 59 | | { |
|---|
| 60 | | |
|---|
| 61 | | $timer = $this->getTimer(); |
|---|
| 62 | | |
|---|
| 63 | | $task = trim($task); |
|---|
| 64 | | |
|---|
| 65 | | if(!empty($task)) |
|---|
| 66 | | { |
|---|
| 67 | | $taskName = 'Task: ' . $task; |
|---|
| 68 | | |
|---|
| 69 | | $result = 0; |
|---|
| 70 | | echo $taskName . "\n\n"; |
|---|
| 71 | | passthru($task, $result); |
|---|
| 72 | | echo "\n"; |
|---|
| 73 | | |
|---|
| 74 | | $this->showTime($timer); |
|---|
| 75 | | |
|---|
| 76 | | if((int)$result > 0) |
|---|
| 77 | | { |
|---|
| 78 | | $this->showTime($totalTimer, 'Total time: '); |
|---|
| 79 | | throw new Exception('`' . $taskName . '`. Running with error #ID: `'.$result.'`'); |
|---|
| 80 | | } |
|---|
| 81 | | |
|---|
| 82 | | } |
|---|
| 83 | | |
|---|
| 84 | | } |
|---|
| 85 | | |
|---|
| 86 | | $this->showTime($totalTimer, 'Total time: '); |
|---|
| 87 | | |
|---|
| | 104 | $this->log(''); |
|---|
| | 105 | $this->logSection($message, date('i:s', (int) $timer->getElapsedTime())); |
|---|
| | 106 | $this->log(''); |
|---|
| | 107 | $this->log(''); |
|---|