Improve update handling

This commit is contained in:
grandeljay 2022-03-27 10:47:48 +02:00
parent de2493069c
commit 3501e1194d
2 changed files with 23 additions and 12 deletions

View file

@ -132,12 +132,6 @@ if (!$options || !$options->getOption('isInstalled')) {
if ($options && $options->getOption('isInstalled')) { if ($options && $options->getOption('isInstalled')) {
if (-1 === version_compare($options->version, VERSION)) { if (-1 === version_compare($options->version, VERSION)) {
$options->setOption('updateAvailable', true); $options->setOption('updateAvailable', true);
if (isset($user->power) && 100 === $user->power) {
$page = 'update';
} else {
$page = 'maintenance';
}
} }
} }

View file

@ -116,18 +116,19 @@ class Page
/** /**
* Session * Session
*/ */
global $user; global $user, $options;
$disableRedirect = array( $ignorePower = array(
'home', 'home',
'login', 'login',
'register', 'register',
'install' 'install',
'maintenance',
); );
if ( if (
!isset($_SESSION['user']) !isset($_SESSION['user'])
&& isset($_GET['page']) && isset($_GET['page'])
&& !in_array($_GET['page'], $disableRedirect) && !in_array($_GET['page'], $ignorePower)
) { ) {
redirect('/?page=login'); redirect('/?page=login');
} }
@ -139,11 +140,27 @@ class Page
redirect('/?page=power&required=' . $this->power); redirect('/?page=power&required=' . $this->power);
} }
/**
* Update
*/
$ignoreUpdateRedirect = array(
'maintenance',
'login',
'logout',
'update',
);
if ($options && $options->getOption('updateAvailable') && !in_array($this->name, $ignoreUpdateRedirect)) {
if (100 === $user->power) {
redirect('/?page=update');
} else {
redirect('/?page=maintenance');
}
}
/** /**
* Redirect * Redirect
*/ */
global $options;
if ($options && $options->getOption('isInstalled') && isset($_SERVER['QUERY_STRING'])) { if ($options && $options->getOption('isInstalled') && isset($_SERVER['QUERY_STRING'])) {
$url = new URL($_SERVER['QUERY_STRING']); $url = new URL($_SERVER['QUERY_STRING']);
$redirect_to = $url->getPretty(); $redirect_to = $url->getPretty();