Skip to content

Commit

Permalink
Add actual upgrade process and confirmation page
Browse files Browse the repository at this point in the history
  • Loading branch information
johannac committed Jan 26, 2023
1 parent ed66123 commit 4585a0c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
80 changes: 66 additions & 14 deletions app/Http/Controllers/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,17 @@ public function postInstaller(Request $request)
}

/**
* Show the application upgrader
* Get data needed before upgrading the system
*
* @return mixed
* @return array
*/
public function showUpgrader()
protected function constructUpgraderData()
{
/**
* 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
'installed_version' => null,
'upgrade_done' => false
];

try {
Expand All @@ -154,11 +146,30 @@ public function showUpgrader()
} 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 $data;
}

/**
* 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 = $this->constructUpgraderData();

return view('Installer.Upgrader', $data);
}
Expand All @@ -171,6 +182,28 @@ public function showUpgrader()
*/
public function postUpgrader(Request $request)
{
// Do not run the installation if it is already installed
if (!$this->canUpgrade()) {
// Return 409 Conflict HTTP Code and a friendly message
abort(409, trans('Installer.no_updgrade'));
}

// Increase PHP time limit
set_time_limit(300);

// Run any migrations
Artisan::call('migrate', ['--force' => true]);

// Update the "installed" file with latest version
$this->createInstalledFile();

// Reload the configuration file (very useful if you use php artisan serve)
Artisan::call('config:clear');

$data = $this->constructUpgraderData();
$data["upgrade_done"] = true;

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

/**
Expand Down Expand Up @@ -270,6 +303,25 @@ public static function isInstalled(): bool
return file_exists(base_path('installed'));
}

/**
* Check if an upgrade is possible
*
* @return bool true if upgrade possible false if not
*/
public function canUpgrade(): bool
{
$data = $this->constructUpgraderData();
if (
(version_compare($data['local_version'], $data['remote_version']) === -1) ||
(
version_compare($data['local_version'], $data['remote_version']) === 0 &&
version_compare($data['installed_version'], $data['local_version']) === -1
)) {
return true;
}
return false;
}

/**
* Checks the database and returns a JSON response with the result
*
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
'download_version' => 'There is a newer version available :version on <a href="https://github.com/attendize/attendize">GitHub</a>. Please download the code, copy it onto your server, and return to this page.',
'new_version_ready' => 'New version ready to install.',
'now_installing' => 'You\'ll now be installing the new version :version',
'upgrade_complete' => 'Upgrade Complete!',
'no_upgrade' => 'Nothing to upgrade!',
);
5 changes: 4 additions & 1 deletion resources/views/Installer/Upgrader.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
</div>

<h1>@lang("Installer.upgrade")</h1>
@if(version_compare($local_version, $remote_version) === -1)
@if($upgrade_done === true)
<h3>@lang("Installer.upgrade_complete")</h3>
<p>@lang("Installer.current_version", ["version" => $local_version])</p>
@elseif(version_compare($local_version, $remote_version) === -1)
<h3>@lang("Installer.new_version")</h3>
<p>@lang("Installer.current_version", ["version" => $local_version])</p>
<p>@lang("Installer.download_version", ["version" => $remote_version])</p>
Expand Down

0 comments on commit 4585a0c

Please sign in to comment.