Skip to content

Commit 7729280

Browse files
committed
update ProcessController.php
1 parent 5641949 commit 7729280

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

app/Http/Controllers/ProcessController.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\Request;
66
use Illuminate\Support\Facades\Artisan;
77
use Illuminate\Support\Facades\Process;
8+
use Log;
89

910
class ProcessController extends Controller
1011
{
@@ -16,15 +17,44 @@ class ProcessController extends Controller
1617
*/
1718
public function siteUpdate(Request $request)
1819
{
19-
$gitReset = Process::run(['git', 'reset', '--hard']);
20-
$processGitPull = Process::run(['git', 'pull']);
21-
$exitCodeMigrate = Artisan::call('migrate', ['--force' => true]);
22-
$exitCodeOptimize = Artisan::call('optimize');
23-
24-
if (($exitCodeMigrate + $exitCodeOptimize) != 0) {
25-
return response()->json(['status' => 'failed', 'error_code' => 19]);
20+
try {
21+
// Specify the project root directory
22+
$projectRoot = base_path();
23+
24+
// Run git reset
25+
$gitReset = Process::path($projectRoot)->run('git reset --hard');
26+
if ($gitReset->failed()) {
27+
Log::error('Git reset failed: ' . $gitReset->errorOutput());
28+
return response()->json(['status' => 'failed', 'error_code' => 10, 'message' => 'Git reset failed']);
29+
}
30+
31+
// Run git pull
32+
$gitPull = Process::path($projectRoot)->run('git pull');
33+
if ($gitPull->failed()) {
34+
Log::error('Git pull failed: ' . $gitPull->errorOutput());
35+
return response()->json(['status' => 'failed', 'error_code' => 11, 'message' => 'Git pull failed']);
36+
}
37+
38+
// Run migrations
39+
$exitCodeMigrate = Artisan::call('migrate', ['--force' => true]);
40+
if ($exitCodeMigrate !== 0) {
41+
Log::error('Migration failed with exit code: ' . $exitCodeMigrate);
42+
return response()->json(['status' => 'failed', 'error_code' => 12, 'message' => 'Migration failed']);
43+
}
44+
45+
// Optimize the application
46+
$exitCodeOptimize = Artisan::call('optimize');
47+
if ($exitCodeOptimize !== 0) {
48+
Log::error('Optimization failed with exit code: ' . $exitCodeOptimize);
49+
return response()->json(['status' => 'failed', 'error_code' => 13, 'message' => 'Optimization failed']);
50+
}
51+
52+
Log::info('Site update completed successfully');
53+
return response()->json(['status' => 'ok', 'error_code' => 0]);
54+
55+
} catch (\Exception $e) {
56+
Log::error('Site update failed with exception: ' . $e->getMessage());
57+
return response()->json(['status' => 'failed', 'error_code' => 500, 'message' => $e->getMessage()]);
2658
}
27-
28-
return response()->json(['status' => 'ok', 'error_code' => 0]);
2959
}
3060
}

0 commit comments

Comments
 (0)