|
7 | 7 |
|
8 | 8 | class SimpedeUpdater |
9 | 9 | { |
10 | | - public static function update($option = null): bool |
| 10 | + public static function run($option = null): array |
11 | 11 | { |
12 | 12 | $error = false; |
13 | 13 | try { |
| 14 | + $output = []; |
| 15 | + |
| 16 | + // Start maintenance mode |
14 | 17 | Artisan::call('maintenance', ['action' => 'start']); |
| 18 | + $output['maintenance_start_output'] = Artisan::output(); |
| 19 | + |
| 20 | + // Git pull |
15 | 21 | $process = new Process(['git', 'pull', 'origin', 'main']); |
16 | 22 | $process->run(); |
| 23 | + $output['git_pull'] = $process->getOutput(); |
17 | 24 | if (! $process->isSuccessful()) { |
18 | 25 | $error = true; |
19 | 26 | } |
20 | 27 |
|
| 28 | + // Composer update |
21 | 29 | $composer = config('app.composer'); |
22 | 30 | $home = config('app.composer_home'); |
23 | 31 | $devFlag = $option ? '' : '--no-dev'; |
24 | 32 | $process = Process::fromShellCommandline("$composer update $devFlag", base_path(), ['COMPOSER_HOME' => $home]); |
25 | 33 | $process->run(); |
| 34 | + $output['composer_update'] = $process->getErrorOutput(); |
26 | 35 | if (! $process->isSuccessful()) { |
27 | 36 | $error = true; |
28 | 37 | } |
29 | 38 |
|
| 39 | + // Composer clear-cache |
30 | 40 | $process = Process::fromShellCommandline("$composer clear-cache", base_path(), ['COMPOSER_HOME' => $home]); |
31 | 41 | $process->run(); |
| 42 | + $output['composer_clear_cache'] = $process->getErrorOutput(); |
32 | 43 | if (! $process->isSuccessful()) { |
33 | 44 | $error = true; |
34 | 45 | } |
35 | 46 | } finally { |
| 47 | + // Stop maintenance mode |
36 | 48 | Artisan::call('maintenance', ['action' => 'stop']); |
| 49 | + $output['maintenance_stop_output'] = Artisan::output(); |
| 50 | + |
| 51 | + // Optimize clear |
37 | 52 | Artisan::call('optimize:clear'); |
| 53 | + $output['optimize_clear_output'] = Artisan::output(); |
| 54 | + |
| 55 | + // Optimize |
38 | 56 | Artisan::call('optimize'); |
| 57 | + $output['optimize_output'] = Artisan::output(); |
| 58 | + |
| 59 | + // Simpede cache |
39 | 60 | Artisan::call('simpede:cache'); |
| 61 | + $output['simpede_cache_output'] = Artisan::output(); |
| 62 | + |
| 63 | + // Storage link |
40 | 64 | if (! is_link(public_path('storage'))) { |
41 | 65 | Artisan::call('storage:link'); |
| 66 | + $output['storage_link_output'] = Artisan::output(); |
42 | 67 | } |
43 | | - |
| 68 | + $output['success'] = ! $error; |
44 | 69 | } |
45 | 70 |
|
46 | | - return ! $error; |
| 71 | + // You can log or return $output as needed |
| 72 | + |
| 73 | + return $output; |
| 74 | + } |
| 75 | + |
| 76 | + public static function update($option = null): bool |
| 77 | + { |
| 78 | + return self::run($option)['success']; |
| 79 | + } |
| 80 | + |
| 81 | + public static function getOutput($option = null): array |
| 82 | + { |
| 83 | + return self::run($option); |
47 | 84 | } |
48 | 85 | } |
0 commit comments