Skip to content

Commit

Permalink
Add basic upgrader route, controller and view
Browse files Browse the repository at this point in the history
  • Loading branch information
johannac committed Jan 19, 2023
1 parent a018c87 commit 2e70e5d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
63 changes: 57 additions & 6 deletions app/Http/Controllers/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Timezone;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand All @@ -13,6 +14,7 @@
use Illuminate\Support\Facades\Log;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Str;
use Utils;

class InstallerController extends Controller
{
Expand All @@ -27,6 +29,15 @@ class InstallerController extends Controller
*/
private $data;


protected function constructInstallerData(): void
{
$this->addDefaultConfig();
$this->addWritablePaths();
$this->addPHPExtensions();
$this->addPHPOptionalExtensions();
}

/**
* Show the application installer
*
Expand Down Expand Up @@ -114,12 +125,52 @@ public function postInstaller(Request $request)
return redirect()->route('showSignup', ['first_run' => 'yup']);
}

protected function constructInstallerData(): void
/**
* Show the application upgrader
*
* @return mixed
*/
public function showUpgrader()
{
/**
* If we haven't yet installed, redirect to installer page.
*/

if (!self::isInstalled()) {
$this->constructInstallerData();
return view('Installer.Installer', $this->data);
}

$data = [
'remote_version' => null,
'local_version' => null,
'installed_version' => null
];

try {
$http_client = new Client();
$response = $http_client->get('https://raw.githubusercontent.com/Attendize/Attendize/master/VERSION');
$data["remote_version"] = Utils::parse_version((string)$response->getBody());
} catch (\Exception $exception) {
\Log::warn("Error retrieving the latest Attendize version. InstallerController.getVersionInfo()");
\Log::warn($exception);
return false;
}

$data["local_version"] = trim(file_get_contents(base_path('VERSION')));
$data["installed_version"] = trim(file_get_contents(base_path('installed')));

return view('Installer.Upgrader', $data);
}

/**
* Attempts to upgrade the system
*
* @param Request $request
* @return JsonResponse|RedirectResponse
*/
public function postUpgrader(Request $request)
{
$this->addDefaultConfig();
$this->addWritablePaths();
$this->addPHPExtensions();
$this->addPHPOptionalExtensions();
}

/**
Expand Down Expand Up @@ -416,7 +467,7 @@ protected function writeEnvFile(): void
*/
protected function createInstalledFile(): void
{
$version = file_get_contents(base_path('VERSION'));
$version = trim(file_get_contents(base_path('VERSION')));
$fp = fopen(base_path().DIRECTORY_SEPARATOR.'installed', 'wb');
fwrite($fp, $version);
fclose($fp);
Expand Down
27 changes: 27 additions & 0 deletions resources/views/Installer/Upgrader.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@extends('Shared.Layouts.MasterWithoutMenus')

@section('title')
@lang("Installer.title")
@stop
@section('content')
<div class="row">
<div class="col-md-7 col-md-offset-2">
<div class="panel">
<div class="panel-body">
<div class="logo">
{!!Html::image('assets/images/logo-dark.png')!!}
</div>

<h1>Upgrade</h1>
@if(version_compare($local_version, $remote_version) === -1)
New version available for download.
@elseif(version_compare($local_version, $remote_version) === 0 && version_compare($installed_version, $local_version) === -1)
New version ready to install.
@else
Nothing to upgrade!
@endif
</div>
</div>
</div>
</div>
@stop
8 changes: 8 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
[InstallerController::class, 'postInstaller']
)->name('postInstaller');

Route::get('upgrade',
[InstallerController::class, 'showUpgrader']
)->name('showUpgrader');

Route::post('upgrade',
[InstallerController::class, 'postUpgrader']
)->name('postUpgrader');

/*
* Logout
*/
Expand Down

0 comments on commit 2e70e5d

Please sign in to comment.