|
20 | 20 | use Cake\Console\BaseCommand; |
21 | 21 | use Cake\Console\ConsoleIo; |
22 | 22 | use Cake\Console\ConsoleOptionParser; |
| 23 | +use Symfony\Component\Process\Process; |
23 | 24 |
|
24 | 25 | /** |
25 | 26 | * Runs rector rulesets against the provided path. |
@@ -59,11 +60,11 @@ public function execute(Arguments $args, ConsoleIo $io): ?int |
59 | 60 |
|
60 | 61 | $result = $this->runRector($io, $args, $autoload); |
61 | 62 | if ($result === false) { |
62 | | - $io->error('Could not run rector. Ensure that `php` is on your PATH.'); |
| 63 | + $io->error('Something went wrong while running rector. Ensure that `php` is on your PATH.'); |
63 | 64 |
|
64 | 65 | return static::CODE_ERROR; |
65 | 66 | } |
66 | | - $io->success('Rector applied successfully'); |
| 67 | + $io->success('🎉 Upgrade complete! 🎉'); |
67 | 68 |
|
68 | 69 | return static::CODE_SUCCESS; |
69 | 70 | } |
@@ -93,39 +94,28 @@ protected function runRector(ConsoleIo $io, Arguments $args, string $autoload): |
93 | 94 | ); |
94 | 95 | $io->verbose("Running <info>{$command}</info>"); |
95 | 96 |
|
96 | | - $descriptorSpec = [ |
97 | | - 0 => ['pipe', 'r'], |
98 | | - 1 => ['pipe', 'w'], |
99 | | - 2 => ['pipe', 'w'], |
100 | | - ]; |
101 | | - $process = proc_open( |
102 | | - $command, |
103 | | - $descriptorSpec, |
104 | | - $pipes, |
105 | | - ); |
106 | | - if (!is_resource($process)) { |
107 | | - $io->error('Could not create rector process'); |
| 97 | + $io->info('Starting rector at ' . date('Y-m-d H:i:s')); |
108 | 98 |
|
109 | | - return false; |
110 | | - } |
| 99 | + $process = Process::fromShellCommandline($command); |
| 100 | + $process->setEnv($_ENV); |
| 101 | + $process->setTimeout(null); |
| 102 | + $process->start(); |
111 | 103 |
|
112 | | - while (true) { |
113 | | - if (feof($pipes[1]) && feof($pipes[2])) { |
114 | | - break; |
115 | | - } |
116 | | - $output = fread($pipes[1], 1024); |
117 | | - if ($output) { |
118 | | - $io->out($output); |
119 | | - } |
120 | | - $error = fread($pipes[2], 1024); |
121 | | - if ($error) { |
122 | | - $io->err($error); |
| 104 | + foreach ($process as $type => $data) { |
| 105 | + if ($type === Process::OUT) { |
| 106 | + $io->out($data); |
| 107 | + } elseif ($type === Process::ERR) { |
| 108 | + $io->err($data); |
123 | 109 | } |
124 | 110 | } |
125 | 111 |
|
126 | | - fclose($pipes[1]); |
127 | | - fclose($pipes[2]); |
128 | | - proc_close($process); |
| 112 | + if (!$process->isSuccessful()) { |
| 113 | + $io->error('Something went wrong while running rector.'); |
| 114 | + |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
| 118 | + $io->info('Rector completed successfully at ' . date('Y-m-d H:i:s')); |
129 | 119 |
|
130 | 120 | return true; |
131 | 121 | } |
|
0 commit comments