Skip to content

Commit b59a206

Browse files
Refactor update process to return detailed output and improve error handling
1 parent 02e6dc2 commit b59a206

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

app/Console/Commands/Update.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class Update extends Command
2626
*/
2727
public function handle()
2828
{
29-
$success = SimpedeUpdater::update($this->option('dev'));
30-
$success ? $this->info('Update Sukses') : $this->error('Update Gagal');
29+
$messages = SimpedeUpdater::getOutput($this->option('dev'));
30+
foreach ($messages as $message) {
31+
$this->line($message);
32+
}
3133

3234
}
3335
}

app/Helpers/SimpedeUpdater.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,79 @@
77

88
class SimpedeUpdater
99
{
10-
public static function update($option = null): bool
10+
public static function run($option = null): array
1111
{
1212
$error = false;
1313
try {
14+
$output = [];
15+
16+
// Start maintenance mode
1417
Artisan::call('maintenance', ['action' => 'start']);
18+
$output['maintenance_start_output'] = Artisan::output();
19+
20+
// Git pull
1521
$process = new Process(['git', 'pull', 'origin', 'main']);
1622
$process->run();
23+
$output['git_pull'] = $process->getOutput();
1724
if (! $process->isSuccessful()) {
1825
$error = true;
1926
}
2027

28+
// Composer update
2129
$composer = config('app.composer');
2230
$home = config('app.composer_home');
2331
$devFlag = $option ? '' : '--no-dev';
2432
$process = Process::fromShellCommandline("$composer update $devFlag", base_path(), ['COMPOSER_HOME' => $home]);
2533
$process->run();
34+
$output['composer_update'] = $process->getErrorOutput();
2635
if (! $process->isSuccessful()) {
2736
$error = true;
2837
}
2938

39+
// Composer clear-cache
3040
$process = Process::fromShellCommandline("$composer clear-cache", base_path(), ['COMPOSER_HOME' => $home]);
3141
$process->run();
42+
$output['composer_clear_cache'] = $process->getErrorOutput();
3243
if (! $process->isSuccessful()) {
3344
$error = true;
3445
}
3546
} finally {
47+
// Stop maintenance mode
3648
Artisan::call('maintenance', ['action' => 'stop']);
49+
$output['maintenance_stop_output'] = Artisan::output();
50+
51+
// Optimize clear
3752
Artisan::call('optimize:clear');
53+
$output['optimize_clear_output'] = Artisan::output();
54+
55+
// Optimize
3856
Artisan::call('optimize');
57+
$output['optimize_output'] = Artisan::output();
58+
59+
// Simpede cache
3960
Artisan::call('simpede:cache');
61+
$output['simpede_cache_output'] = Artisan::output();
62+
63+
// Storage link
4064
if (! is_link(public_path('storage'))) {
4165
Artisan::call('storage:link');
66+
$output['storage_link_output'] = Artisan::output();
4267
}
43-
68+
$output['success'] = ! $error;
4469
}
4570

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);
4784
}
4885
}

0 commit comments

Comments
 (0)