@@ -20,40 +20,46 @@ public function siteUpdate(Request $request)
2020 try {
2121 // Specify the project root directory
2222 $ projectRoot = base_path ();
23-
23+
2424 // Run git reset
2525 $ gitReset = Process::path ($ projectRoot )->run ('git reset --hard ' );
2626 if ($ gitReset ->failed ()) {
27- Log::error ('Git reset failed: ' . $ gitReset ->errorOutput ());
27+ Log::error ('Git reset failed: ' .$ gitReset ->errorOutput ());
28+
2829 return response ()->json (['status ' => 'failed ' , 'error_code ' => 10 , 'message ' => 'Git reset failed ' ]);
2930 }
30-
31+
3132 // Run git pull
3233 $ gitPull = Process::path ($ projectRoot )->run ('git pull ' );
3334 if ($ gitPull ->failed ()) {
34- Log::error ('Git pull failed: ' . $ gitPull ->errorOutput ());
35+ Log::error ('Git pull failed: ' .$ gitPull ->errorOutput ());
36+
3537 return response ()->json (['status ' => 'failed ' , 'error_code ' => 11 , 'message ' => 'Git pull failed ' ]);
3638 }
37-
39+
3840 // Run migrations
3941 $ exitCodeMigrate = Artisan::call ('migrate ' , ['--force ' => true ]);
4042 if ($ exitCodeMigrate !== 0 ) {
41- Log::error ('Migration failed with exit code: ' . $ exitCodeMigrate );
43+ Log::error ('Migration failed with exit code: ' .$ exitCodeMigrate );
44+
4245 return response ()->json (['status ' => 'failed ' , 'error_code ' => 12 , 'message ' => 'Migration failed ' ]);
4346 }
44-
47+
4548 // Optimize the application
4649 $ exitCodeOptimize = Artisan::call ('optimize ' );
4750 if ($ exitCodeOptimize !== 0 ) {
48- Log::error ('Optimization failed with exit code: ' . $ exitCodeOptimize );
51+ Log::error ('Optimization failed with exit code: ' .$ exitCodeOptimize );
52+
4953 return response ()->json (['status ' => 'failed ' , 'error_code ' => 13 , 'message ' => 'Optimization failed ' ]);
5054 }
51-
55+
5256 Log::info ('Site update completed successfully ' );
57+
5358 return response ()->json (['status ' => 'ok ' , 'error_code ' => 0 ]);
54-
59+
5560 } catch (\Exception $ e ) {
56- Log::error ('Site update failed with exception: ' . $ e ->getMessage ());
61+ Log::error ('Site update failed with exception: ' .$ e ->getMessage ());
62+
5763 return response ()->json (['status ' => 'failed ' , 'error_code ' => 500 , 'message ' => $ e ->getMessage ()]);
5864 }
5965 }
0 commit comments