2018-02-06 06:16:24 +08:00
|
|
|
<?php
|
|
|
|
|
2020-10-19 22:10:28 +08:00
|
|
|
namespace App\Http\Controllers\System;
|
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-06-04 22:36:55 +08:00
|
|
|
use App\Services\AnalyticsService;
|
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;
|
2020-10-19 22:10:28 +08:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
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;
|
2020-10-19 22:10:28 +08:00
|
|
|
use Illuminate\View\View;
|
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-06-04 22:36:55 +08:00
|
|
|
private $analyticsSvc;
|
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-06-04 22:36:55 +08:00
|
|
|
* @param AnalyticsService $analyticsSvc
|
2020-01-31 01:44:59 +08:00
|
|
|
* @param InstallerService $installerSvc
|
2020-06-04 22:36:55 +08:00
|
|
|
* @param KvpRepository $kvpRepo
|
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 UpdaterManager $updateManager
|
2018-03-20 09:50:40 +08:00
|
|
|
*/
|
2018-02-06 06:16:24 +08:00
|
|
|
public function __construct(
|
2020-06-04 22:36:55 +08:00
|
|
|
AnalyticsService $analyticsSvc,
|
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
|
|
|
) {
|
2020-06-04 22:36:55 +08:00
|
|
|
$this->analyticsSvc = $analyticsSvc;
|
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()
|
|
|
|
{
|
2020-10-19 22:10:28 +08:00
|
|
|
return view('system.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
|
|
|
*
|
2019-12-13 04:07:35 +08:00
|
|
|
* @return mixed
|
2018-02-06 06:16:24 +08:00
|
|
|
*/
|
2020-10-19 22:10:28 +08:00
|
|
|
public function step1()
|
2018-02-06 06:16:24 +08:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-19 22:10:28 +08:00
|
|
|
return view('system.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();
|
2020-10-19 22:10:28 +08:00
|
|
|
return view('system.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
|
|
|
|
2020-10-19 22:10:28 +08:00
|
|
|
return view('system.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
|
|
|
*
|
2019-12-13 04:07:35 +08:00
|
|
|
* @return mixed
|
2018-02-06 06:16:24 +08:00
|
|
|
*/
|
2020-10-19 22:10:28 +08:00
|
|
|
public function complete()
|
2018-02-06 06:16:24 +08:00
|
|
|
{
|
|
|
|
return redirect('/login');
|
|
|
|
}
|
2020-02-11 06:47:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the update page with the latest version
|
|
|
|
*
|
2020-10-19 22:10:28 +08:00
|
|
|
* @return Factory|View
|
2020-02-11 06:47:46 +08:00
|
|
|
*/
|
2020-10-19 22:10:28 +08:00
|
|
|
public function updater()
|
2020-02-11 06:47:46 +08:00
|
|
|
{
|
|
|
|
$version = $this->kvpRepo->get('latest_version_tag');
|
|
|
|
|
2020-10-19 22:10:28 +08:00
|
|
|
return view('system.updater.downloader/downloader', [
|
2020-02-11 06:47:46 +08:00
|
|
|
'version' => $version,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download the actual update and then forward the user to the updater page
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-10-19 22:10:28 +08:00
|
|
|
public function update_download()
|
2020-02-11 06:47:46 +08:00
|
|
|
{
|
|
|
|
$version = $this->kvpRepo->get('latest_version_tag');
|
2020-05-21 23:06:27 +08:00
|
|
|
if (empty($version)) {
|
2020-10-19 22:10:28 +08:00
|
|
|
return view('system.updater.steps.step1-no-update');
|
2020-05-21 23:06:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$release = $this->updateManager->source('github')->fetch($version);
|
|
|
|
$this->updateManager->source('github')->update($release);
|
2020-06-04 22:36:55 +08:00
|
|
|
$this->analyticsSvc->sendUpdate();
|
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
|
|
|
}
|