| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* (c) Anton Medvedev <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace Deployer\Executor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Deployer\Console\Output\OutputWatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class Informer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @var \Deployer\Console\Output\OutputWatcher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @param \Deployer\Console\Output\OutputWatcher $output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 18 |  |     public function __construct(OutputWatcher $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 18 |  |         $this->output = $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 18 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param string $taskName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 15 |  |     public function startTask($taskName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 15 |  |         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 34 | 14 | View Code Duplication |             if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 14 |  |                 $this->output->write("  "); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 14 |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 $this->output->write("➤ "); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 14 |  |             $this->output->writeln("Executing task $taskName"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 14 |  |             $this->output->setWasWritten(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 14 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 15 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * Print task was ok. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 49 | 16 |  |     public function endTask() | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 51 | 16 | View Code Duplication |         if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL && !$this->output->getWasWritten()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 12 |  |             $this->output->write("\033[k\033[1A\r<info>✔</info>\n"); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 12 |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 5 |  |             $this->output->writeln("<info>✔</info> Ok"); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 16 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param string $serverName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 15 |  |     public function onServer($serverName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 15 |  |         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $this->output->writeln("⤷ on [$serverName]"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 15 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param string $serverName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 14 |  |     public function endOnServer($serverName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 14 |  |         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $this->output->writeln("<info>⤶</info> done on [$serverName]"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 14 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * Print error. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param bool $nonFatal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 2 |  |     public function taskError($nonFatal = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 2 |  |         if ($nonFatal) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 1 |  |             $this->output->writeln("<fg=yellow>✘</fg=yellow> Some errors occurred!"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 1 |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 1 |  |             $this->output->writeln("<fg=red>✘</fg=red> <options=underscore>Some errors occurred!</options=underscore>"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param string $serverName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param string $exceptionClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function taskException($serverName, $exceptionClass, $message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $message = "    $message    "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $this->output->writeln([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             "", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             "<error>Exception [$exceptionClass] on [$serverName] server</error>", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             "<error>" . str_repeat(' ', strlen($message)) . "</error>", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             "<error>$message</error>", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             "<error>" . str_repeat(' ', strlen($message)) . "</error>", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             "" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 109 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |  |