2018-02-06 06:16:24 +08:00
|
|
|
<?php
|
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
namespace Modules\Updater\Http\Controllers;
|
2018-02-06 06:16:24 +08:00
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Controller;
|
2020-01-31 01:44:59 +08:00
|
|
|
use App\Services\Installer\InstallerService;
|
2019-04-08 07:53:24 +08:00
|
|
|
use App\Services\Installer\MigrationService;
|
2019-08-05 20:27:53 +08:00
|
|
|
use App\Services\Installer\SeederService;
|
2019-07-18 21:26:33 +08:00
|
|
|
use function count;
|
2018-02-06 06:16:24 +08:00
|
|
|
use Illuminate\Http\Request;
|
2019-11-27 22:19:20 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-04-08 07:53:24 +08:00
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
class UpdateController extends Controller
|
2018-02-06 06:16:24 +08:00
|
|
|
{
|
2020-01-31 01:44:59 +08:00
|
|
|
private $installerSvc;
|
2018-03-20 09:50:40 +08:00
|
|
|
private $migrationSvc;
|
2019-08-05 20:27:53 +08:00
|
|
|
private $seederSvc;
|
2018-02-06 06:16:24 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
2020-01-31 01:44:59 +08:00
|
|
|
* @param InstallerService $installerSvc
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param MigrationService $migrationSvc
|
2019-08-05 20:27:53 +08:00
|
|
|
* @param SeederService $seederSvc
|
2018-03-20 09:50:40 +08:00
|
|
|
*/
|
2018-02-06 06:16:24 +08:00
|
|
|
public function __construct(
|
2020-01-31 01:44:59 +08:00
|
|
|
InstallerService $installerSvc,
|
2019-08-05 20:27:53 +08:00
|
|
|
MigrationService $migrationSvc,
|
|
|
|
SeederService $seederSvc
|
2018-02-06 06:16:24 +08:00
|
|
|
) {
|
|
|
|
$this->migrationSvc = $migrationSvc;
|
2019-08-05 20:27:53 +08:00
|
|
|
$this->seederSvc = $seederSvc;
|
2020-01-31 01:44:59 +08:00
|
|
|
$this->installerSvc = $installerSvc;
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2019-12-13 04:07:35 +08:00
|
|
|
return view('updater::index-start');
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2019-12-13 04:07:35 +08:00
|
|
|
* @return mixed
|
2018-02-06 06:16:24 +08:00
|
|
|
*/
|
|
|
|
public function step1(Request $request)
|
|
|
|
{
|
2020-01-31 03:59:48 +08:00
|
|
|
$this->installerSvc->clearCaches();
|
|
|
|
|
2020-01-31 01:44:59 +08:00
|
|
|
if ($this->installerSvc->isUpgradePending()) {
|
|
|
|
Log::info('Upgrade is pending');
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
return view('updater::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
|
|
|
*
|
2019-12-13 04:07:35 +08:00
|
|
|
* @return mixed
|
2018-02-06 06:16:24 +08:00
|
|
|
*/
|
|
|
|
public function run_migrations(Request $request)
|
|
|
|
{
|
|
|
|
Log::info('Update: run_migrations', $request->post());
|
|
|
|
|
|
|
|
$migrations = $this->migrationSvc->migrationsAvailable();
|
2019-08-27 00:32:46 +08:00
|
|
|
if (count($migrations) === 0) {
|
2019-08-05 20:27:53 +08:00
|
|
|
$this->seederSvc->syncAllSeeds();
|
2019-12-13 04:07:35 +08:00
|
|
|
return view('updater::steps/step3-update-complete');
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = $this->migrationSvc->runAllMigrations();
|
2019-08-05 20:27:53 +08:00
|
|
|
$this->seederSvc->syncAllSeeds();
|
2018-02-06 06:16:24 +08:00
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
return view('updater::steps/step2-migrations-done', [
|
2018-02-06 06:16:24 +08:00
|
|
|
'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
|
|
|
*
|
2019-12-13 04:07:35 +08:00
|
|
|
* @return mixed
|
2018-02-06 06:16:24 +08:00
|
|
|
*/
|
|
|
|
public function complete(Request $request)
|
|
|
|
{
|
|
|
|
return redirect('/login');
|
|
|
|
}
|
|
|
|
}
|