2018-02-06 06:16:24 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Installer\Http\Controllers;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Controller;
|
2019-04-08 07:53:24 +08:00
|
|
|
use App\Services\Installer\MigrationService;
|
2018-02-06 06:16:24 +08:00
|
|
|
use Illuminate\Http\Request;
|
2018-03-20 09:50:40 +08:00
|
|
|
use Log;
|
2019-04-08 07:53:24 +08:00
|
|
|
|
2018-02-06 06:16:24 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class UpdaterController
|
|
|
|
* @package Modules\Installer\Http\Controllers
|
|
|
|
*/
|
2018-02-06 06:16:24 +08:00
|
|
|
class UpdaterController extends Controller
|
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
private $migrationSvc;
|
2018-02-06 06:16:24 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* UpdaterController constructor.
|
|
|
|
* @param MigrationService $migrationSvc
|
|
|
|
*/
|
2018-02-06 06:16:24 +08:00
|
|
|
public function __construct(
|
|
|
|
MigrationService $migrationSvc
|
|
|
|
) {
|
|
|
|
$this->migrationSvc = $migrationSvc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('installer::update/index-start');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step 1. Check if there's an update available. Check if there
|
|
|
|
* are any unrun migrations
|
2019-04-08 07:53:24 +08:00
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2018-02-06 06:16:24 +08:00
|
|
|
*/
|
|
|
|
public function step1(Request $request)
|
|
|
|
{
|
|
|
|
$migrations = $this->migrationSvc->migrationsAvailable();
|
|
|
|
if(\count($migrations) > 0) {
|
2018-09-03 01:18:32 +08:00
|
|
|
Log::info('No migrations found');
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
2018-09-03 01:18:32 +08:00
|
|
|
return view('installer::update/steps/step1-update-available');
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step 2 Run all of the migrations
|
2019-04-08 07:53:24 +08:00
|
|
|
*
|
2018-02-06 06:16:24 +08:00
|
|
|
* @param Request $request
|
2019-04-08 07:53:24 +08:00
|
|
|
*
|
2018-02-06 06:16:24 +08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function run_migrations(Request $request)
|
|
|
|
{
|
|
|
|
Log::info('Update: run_migrations', $request->post());
|
|
|
|
|
|
|
|
$migrations = $this->migrationSvc->migrationsAvailable();
|
|
|
|
if(\count($migrations) === 0) {
|
2019-04-08 07:53:24 +08:00
|
|
|
$this->migrationSvc->syncAllSeeds();
|
2018-09-03 01:18:32 +08:00
|
|
|
return view('installer::update/steps/step3-update-complete');
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = $this->migrationSvc->runAllMigrations();
|
2019-04-08 07:53:24 +08:00
|
|
|
$this->migrationSvc->syncAllSeeds();
|
2018-02-06 06:16:24 +08:00
|
|
|
|
|
|
|
return view('installer::update/steps/step2-migrations-done', [
|
|
|
|
'console_output' => $output,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Final step
|
2019-04-08 07:53:24 +08:00
|
|
|
*
|
2018-02-06 06:16:24 +08:00
|
|
|
* @param Request $request
|
2019-04-08 07:53:24 +08:00
|
|
|
*
|
2018-02-06 06:16:24 +08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function complete(Request $request)
|
|
|
|
{
|
|
|
|
return redirect('/login');
|
|
|
|
}
|
|
|
|
}
|