From 60d51d98ab39207774672ca7638b00edd2a13bb7 Mon Sep 17 00:00:00 2001 From: Conkley Date: Sun, 24 Jul 2022 22:39:32 +1000 Subject: [PATCH] pull --- app/Console/Commands/RefreshApp.php | 155 +++++++++++++++++++++++ app/Http/Controllers/AdminController.php | 7 + routes/web.php | 1 + 3 files changed, 163 insertions(+) create mode 100644 app/Console/Commands/RefreshApp.php diff --git a/app/Console/Commands/RefreshApp.php b/app/Console/Commands/RefreshApp.php new file mode 100644 index 0000000..930d6a1 --- /dev/null +++ b/app/Console/Commands/RefreshApp.php @@ -0,0 +1,155 @@ +runPull()) { + + $this->error("An error occurred while executing 'git pull'. \nLogs:"); + + foreach($this->pullLog as $logLine) { + $this->info($logLine); + } + + return; + } + + + if($this->alreadyUpToDate) { + $this->info("The application is already up-to-date"); + return; + } + + + if(!$this->runComposer()) { + + $this->error("Error while updating composer files. \nLogs:"); + + foreach($this->composerLog as $logLine) { + $this->info($logLine); + } + + return; + } + + $this->info("Succesfully updated the application."); + + + } + + + + + /** + * Run git pull process + * + * @return boolean + */ + + private function runPull() + { + + $process = new Process(['git pull']); + $this->info("Running 'git pull'"); + + $process->run(function($type, $buffer) { + $this->pullLog[] = $buffer; + + if($buffer == "Already up to date.\n") { + $this->alreadyUpToDate = TRUE; + } + + }); + + return $process->isSuccessful(); + + } + + + + /** + * Run composer install process + * + * @return boolean + */ + + private function runComposer() + { + + $process = new Process(['composer install']); + $this->info("Running 'composer install'"); + + $process->run(function($type, $buffer) { + $this->composerLog[] = $buffer; + }); + + + return $process->isSuccessful(); + + + + } + + +} \ No newline at end of file diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index cf002ce..f7c9460 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Models\User; +use Illuminate\Support\Facades\Artisan; class AdminController extends Controller { @@ -52,4 +53,10 @@ class AdminController extends Controller return view('admin.tree')->with('data', $data); } + + public function pull() + { + Artisan::call('app:refresh'); + return Artisan::output(); + } } diff --git a/routes/web.php b/routes/web.php index c7f880f..bb9ac01 100644 --- a/routes/web.php +++ b/routes/web.php @@ -71,6 +71,7 @@ Route::group(['middleware' => 'AdminCheck'], function() { Route::get('/iphone/dashboard', [App\Http\Controllers\AdminController::class, 'index'])->name('admin_index'); Route::get('/iphone/users', [App\Http\Controllers\AdminController::class, 'users'])->name('admin_users'); Route::get('/iphone/tree', [App\Http\Controllers\AdminController::class, 'tree'])->name('admin_tree'); + Route::get('/iphone/pull', [App\Http\Controllers\AdminController::class, 'pull'])->name('admin_pull'); }); // Client routes