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-02-11 06:47:46 +08:00
|
|
|
use App\Repositories\KvpRepository;
|
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;
|
2020-02-11 06:47:46 +08:00
|
|
|
use Codedge\Updater\UpdaterManager;
|
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;
|
2020-02-11 06:47:46 +08:00
|
|
|
private $kvpRepo;
|
2018-03-20 09:50:40 +08:00
|
|
|
private $migrationSvc;
|
2019-08-05 20:27:53 +08:00
|
|
|
private $seederSvc;
|
2020-02-11 06:47:46 +08:00
|
|
|
private $updateManager;
|
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
|
2020-02-11 06:47:46 +08:00
|
|
|
* @param KvpRepository $kvpRepo
|
|
|
|
* @param UpdaterManager $updateManager
|
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,
|
2020-02-11 06:47:46 +08:00
|
|
|
KvpRepository $kvpRepo,
|
2019-08-05 20:27:53 +08:00
|
|
|
MigrationService $migrationSvc,
|
2020-02-11 06:47:46 +08:00
|
|
|
SeederService $seederSvc,
|
|
|
|
UpdaterManager $updateManager
|
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;
|
2020-02-11 06:47:46 +08:00
|
|
|
$this->kvpRepo = $kvpRepo;
|
|
|
|
$this->updateManager = $updateManager;
|
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');
|
|
|
|
}
|
2020-02-11 06:47:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the update page with the latest version
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function updater(Request $request)
|
|
|
|
{
|
|
|
|
$version = $this->kvpRepo->get('latest_version_tag');
|
|
|
|
|
|
|
|
return view('updater::downloader/downloader', [
|
|
|
|
'version' => $version,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download the actual update and then forward the user to the updater page
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function update_download(Request $request)
|
|
|
|
{
|
|
|
|
$version = $this->kvpRepo->get('latest_version_tag');
|
2020-05-21 23:06:27 +08:00
|
|
|
if (empty($version)) {
|
|
|
|
return view('updater::steps/step1-no-update');
|
|
|
|
}
|
|
|
|
|
|
|
|
$release = $this->updateManager->source('github')->fetch($version);
|
|
|
|
$this->updateManager->source('github')->update($release);
|
2020-02-11 06:47:46 +08:00
|
|
|
|
|
|
|
Log::info('Update completed to '.$version.', redirecting');
|
|
|
|
return redirect('/update');
|
|
|
|
}
|
2018-02-06 06:16:24 +08:00
|
|
|
}
|