diff --git a/admin_index.php b/admin_index.php index e6f1a9c5..8038c7fb 100644 --- a/admin_index.php +++ b/admin_index.php @@ -254,6 +254,7 @@ if ($page == 'overview') { 'id' => $userinfo['adminid'], 'def_language' => $def_language ])->update(); + CurrentUser::setField('language', $def_language); } catch (Exception $e) { Response::dynamicError($e->getMessage()); } diff --git a/customer_index.php b/customer_index.php index 0569587f..9ec5f27c 100644 --- a/customer_index.php +++ b/customer_index.php @@ -215,6 +215,7 @@ if ($page == 'overview') { 'id' => $userinfo['customerid'], 'def_language' => $def_language ])->update(); + CurrentUser::setField('language', $def_language); } catch (Exception $e) { Response::dynamicError($e->getMessage()); } diff --git a/install/updates/froxlor/update_0.11.inc.php b/install/updates/froxlor/update_0.11.inc.php index a4396f3b..fea8d799 100644 --- a/install/updates/froxlor/update_0.11.inc.php +++ b/install/updates/froxlor/update_0.11.inc.php @@ -82,7 +82,6 @@ if (Froxlor::isFroxlorVersion('0.10.99')) { } Update::lastStepStatus(0); - Update::showUpdateStep("Cleaning up old files"); $to_clean = array( "install/lib", @@ -134,6 +133,7 @@ if (Froxlor::isFroxlorVersion('0.10.99')) { $system_distribution = isset($_POST['system_distribution']) ? $_POST['system_distribution'] : ''; Settings::AddNew("system.distribution", $system_distribution); Settings::AddNew("system.update_channel", 'stable'); + Settings::AddNew("system.updatecheck_data", ''); Update::lastStepStatus(0); Update::showUpdateStep("Adjusting existing settings"); @@ -152,9 +152,5 @@ if (Froxlor::isFroxlorVersion('0.10.99')) { Settings::Set('panel.standardlanguage', $lang_map[Settings::Get('panel_standardlanguage')] ?? 'en'); Update::lastStepStatus(0); - - if (Froxlor::isFroxlorVersion('0.10.99')) { - Update::showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false); - Froxlor::updateToVersion('0.11.0-dev1'); - } + Froxlor::updateToVersion('0.11.0-dev1'); } diff --git a/lib/Froxlor/Api/Commands/Froxlor.php b/lib/Froxlor/Api/Commands/Froxlor.php index a0888c04..ebb99c2d 100644 --- a/lib/Froxlor/Api/Commands/Froxlor.php +++ b/lib/Froxlor/Api/Commands/Froxlor.php @@ -32,6 +32,7 @@ use Froxlor\Database\Database; use Froxlor\Database\IntegrityCheck; use Froxlor\FroxlorLogger; use Froxlor\Install\AutoUpdate; +use Froxlor\Install\Update; use Froxlor\Settings; use Froxlor\SImExporter; use Froxlor\System\Cronjob; @@ -49,9 +50,13 @@ use ReflectionMethod; class Froxlor extends ApiCommand { + const UPDATE_CHECK_INTERVAL = 21600; // 6 hrs + /** * checks whether there is a newer version of froxlor available * + * @param bool $force optional, force live update-check + * * @access admin * @return string json-encoded array * @throws Exception @@ -60,50 +65,62 @@ class Froxlor extends ApiCommand { if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) { - // log our actions - $this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] checking for updates"); + $uc_data = Update::getUpdateCheckData(); - // check for new version - $aucheck = AutoUpdate::checkVersion(); + $force_ucheck = $this->getBoolParam('force', true, 0); + $response = $uc_data['data']; - if ($aucheck == 1) { - // anzeige über version-status mit ggfls. formular - // zum update schritt #1 -> download - $text = 'There is a newer ' . (Settings::Get('system.update_channel') == 'testing' ? 'testing ' : '') . 'version available: "' . AutoUpdate::getFromResult('version') . '" (Your current version is: ' . $this->version . ')'; - return $this->response([ - 'isnewerversion' => (int) !AutoUpdate::getFromResult('has_latest'), - 'version' => $this->version, - 'message' => $text, - 'link' => AutoUpdate::getFromResult('url'), - 'additional_info' => AutoUpdate::getFromResult('info') - ]); - } else if ($aucheck < 0 || $aucheck > 1) { - // errors - if ($aucheck < 0) { - $errmsg = AutoUpdate::getLastError(); - } else { - if ($aucheck == 3) { - $errmsg = lng('error.customized_version'); + if (empty($uc_data) || $uc_data['ts'] + self::UPDATE_CHECK_INTERVAL < time() || $uc_data['channel'] != Settings::Get('system.update_channel') || $force_ucheck) { + // log our actions + $this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] checking for updates"); + + // check for new version + $aucheck = AutoUpdate::checkVersion(); + + $response = []; + if ($aucheck == 1) { + // anzeige über version-status mit ggfls. formular + // zum update schritt #1 -> download + $text = lng('update.uc_newinfo', [(Settings::Get('system.update_channel') == 'testing' ? 'testing ' : ''), AutoUpdate::getFromResult('version'), $this->version]); + $response = [ + 'isnewerversion' => (int) !AutoUpdate::getFromResult('has_latest'), + 'version' => $this->version, + 'message' => $text, + 'link' => AutoUpdate::getFromResult('url'), + 'additional_info' => AutoUpdate::getFromResult('info') + ]; + } else if ($aucheck < 0 || $aucheck > 1) { + // errors + if ($aucheck < 0) { + $errmsg = AutoUpdate::getLastError(); } else { - $errmsg = lng('error.autoupdate_' . $aucheck); + if ($aucheck == 3) { + $errmsg = lng('error.customized_version'); + } else { + $errmsg = lng('error.autoupdate_' . $aucheck); + } } + $response = [ + 'isnewerversion' => 0, + 'version' => $this->version, + 'message' => '', + 'link' => '', + 'additional_info' => $errmsg + ]; + } else { + $response = [ + 'isnewerversion' => 0, + 'version' => $this->version, + 'message' => '', + 'link' => '', + 'additional_info' => lng('update.noupdatesavail', [(Settings::Get('system.update_channel') == 'testing' ? lng('serversettings.uc_testing') . ' ' : '')]) + ]; } - return $this->response([ - 'isnewerversion' => 0, - 'version' => $this->version, - 'message' => '', - 'link' => '', - 'additional_info' => $errmsg - ]); - } else { - return $this->response([ - 'isnewerversion' => 0, - 'version' => $this->version, - 'message' => '', - 'link' => '', - 'additional_info' => lng('update.noupdatesavail', [(Settings::Get('system.update_channel') == 'testing' ? lng('serversettings.uc_testing') . ' ' : '')]) - ]); + + Update::storeUpdateCheckData($response); } + + return $this->response($response); } throw new Exception("Not allowed to execute given command.", 403); } diff --git a/lib/Froxlor/Install/Update.php b/lib/Froxlor/Install/Update.php index 46b21fe4..c1c21584 100644 --- a/lib/Froxlor/Install/Update.php +++ b/lib/Froxlor/Install/Update.php @@ -27,6 +27,7 @@ namespace Froxlor\Install; use Froxlor\Froxlor; use Froxlor\FroxlorLogger; +use Froxlor\Settings; class Update { @@ -106,4 +107,24 @@ class Update return Froxlor::versionCompare2($current_version, $version_to_check) == -1; } + + public static function storeUpdateCheckData(array $response) + { + $data = [ + 'ts' => time(), + 'channel' => Settings::Get('system.update_channel'), + 'data' => $response + ]; + Settings::Set('system.updatecheck_data', json_encode($data)); + } + + public static function getUpdateCheckData() + { + $uc_data = Settings::Get('system.updatecheck_data'); + if (!empty($uc_data)) { + $data = json_decode($uc_data, true); + return $data; + } + return null; + } } diff --git a/lib/Froxlor/Language.php b/lib/Froxlor/Language.php index a7e76977..e4f8304f 100644 --- a/lib/Froxlor/Language.php +++ b/lib/Froxlor/Language.php @@ -119,5 +119,6 @@ class Language public static function setLanguage(string $string) { self::$requestedLanguage = $string; + self::$lng = null; } } diff --git a/lng/de.lng.php b/lng/de.lng.php index 4c37d8ea..18f70094 100644 --- a/lng/de.lng.php +++ b/lng/de.lng.php @@ -2116,6 +2116,7 @@ Vielen Dank, Ihr Administrator', ], 'noupdatesavail' => 'Die genutzte %sVersion von Froxlor ist aktuell.', 'description' => 'Aktualisierung der froxlor Datenbank', + 'uc_newinfo' => 'Eine neuere %sVersion ist verfügbar: "%s" (Aktuell installierte Version: %s)', ], 'usersettings' => [ 'custom_notes' => [ diff --git a/lng/en.lng.php b/lng/en.lng.php index 98caad49..68d1fd2f 100644 --- a/lng/en.lng.php +++ b/lng/en.lng.php @@ -2501,6 +2501,7 @@ Yours sincerely, your administrator', ], 'noupdatesavail' => 'You already have the latest %sversion of Froxlor installed.', 'description' => 'Running database updates for your froxlor installation', + 'uc_newinfo' => 'There is a newer %sversion available: "%s" (Your current version is: %s)', ], 'usersettings' => [ 'custom_notes' => [ diff --git a/templates/Froxlor/userarea.html.twig b/templates/Froxlor/userarea.html.twig index 1b7de701..21f6199c 100644 --- a/templates/Froxlor/userarea.html.twig +++ b/templates/Froxlor/userarea.html.twig @@ -34,7 +34,7 @@