pull
This commit is contained in:
parent
eae4c3dee6
commit
60d51d98ab
|
|
@ -0,0 +1,155 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
class RefreshApp extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:refresh';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Pull files from GIT';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the code already updated or not
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $alreadyUpToDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log from git pull
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $pullLog = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log from composer install
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $composerLog = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!$this->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();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
class AdminController extends Controller
|
class AdminController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -52,4 +53,10 @@ class AdminController extends Controller
|
||||||
|
|
||||||
return view('admin.tree')->with('data', $data);
|
return view('admin.tree')->with('data', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pull()
|
||||||
|
{
|
||||||
|
Artisan::call('app:refresh');
|
||||||
|
return Artisan::output();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/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/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/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
|
// Client routes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue