phpvms/modules/Updater/Http/Controllers/UpdateController.php
Nabeel S e862537a20
Split the importer module out from the installer module (#468)
* Split the importer module out from the installer module

* Cleanup of unused imports

* Move updater into separate module #453

* Remove unused imports/formatting

* Disable the install and importer modules at the end of the setup

* Unused imports; update IJ style

* test explicit stage for php+mysql

* add more to matrix

* Add different MariaDB versions

* undo
2019-12-12 15:07:35 -05:00

92 lines
2.1 KiB
PHP

<?php
namespace Modules\Updater\Http\Controllers;
use App\Contracts\Controller;
use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService;
use function count;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class UpdateController extends Controller
{
private $migrationSvc;
private $seederSvc;
/**
* @param MigrationService $migrationSvc
* @param SeederService $seederSvc
*/
public function __construct(
MigrationService $migrationSvc,
SeederService $seederSvc
) {
$this->migrationSvc = $migrationSvc;
$this->seederSvc = $seederSvc;
}
/**
* Display a listing of the resource.
*/
public function index()
{
return view('updater::index-start');
}
/**
* Step 1. Check if there's an update available. Check if there
* are any unrun migrations
*
* @param Request $request
*
* @return mixed
*/
public function step1(Request $request)
{
$migrations = $this->migrationSvc->migrationsAvailable();
if (count($migrations) > 0) {
Log::info('No migrations found');
}
return view('updater::steps/step1-update-available');
}
/**
* Step 2 Run all of the migrations
*
* @param Request $request
*
* @return mixed
*/
public function run_migrations(Request $request)
{
Log::info('Update: run_migrations', $request->post());
$migrations = $this->migrationSvc->migrationsAvailable();
if (count($migrations) === 0) {
$this->seederSvc->syncAllSeeds();
return view('updater::steps/step3-update-complete');
}
$output = $this->migrationSvc->runAllMigrations();
$this->seederSvc->syncAllSeeds();
return view('updater::steps/step2-migrations-done', [
'console_output' => $output,
]);
}
/**
* Final step
*
* @param Request $request
*
* @return mixed
*/
public function complete(Request $request)
{
return redirect('/login');
}
}