Do not cache version info in the sessions
If the session is cleared and closed for whatever reason the loadVersion will write to the session anyways. This will lead to an exception. This should fix #1303 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
571c5aac5e
commit
028c668293
|
@ -66,6 +66,9 @@ class OC_Util {
|
||||||
private static $rootMounted = false;
|
private static $rootMounted = false;
|
||||||
private static $fsSetup = false;
|
private static $fsSetup = false;
|
||||||
|
|
||||||
|
/** @var array Local cache of version.php */
|
||||||
|
private static $versionCache = null;
|
||||||
|
|
||||||
protected static function getAppManager() {
|
protected static function getAppManager() {
|
||||||
return \OC::$server->getAppManager();
|
return \OC::$server->getAppManager();
|
||||||
}
|
}
|
||||||
|
@ -397,7 +400,7 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function getVersion() {
|
public static function getVersion() {
|
||||||
OC_Util::loadVersion();
|
OC_Util::loadVersion();
|
||||||
return \OC::$server->getSession()->get('OC_Version');
|
return self::$versionCache['OC_Version'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -407,7 +410,7 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function getVersionString() {
|
public static function getVersionString() {
|
||||||
OC_Util::loadVersion();
|
OC_Util::loadVersion();
|
||||||
return \OC::$server->getSession()->get('OC_VersionString');
|
return self::$versionCache['OC_VersionString'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -424,7 +427,7 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function getChannel() {
|
public static function getChannel() {
|
||||||
OC_Util::loadVersion();
|
OC_Util::loadVersion();
|
||||||
return \OC::$server->getSession()->get('OC_Channel');
|
return self::$versionCache['OC_Channel'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -433,41 +436,41 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function getBuild() {
|
public static function getBuild() {
|
||||||
OC_Util::loadVersion();
|
OC_Util::loadVersion();
|
||||||
return \OC::$server->getSession()->get('OC_Build');
|
return self::$versionCache['OC_Build'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description load the version.php into the session as cache
|
* @description load the version.php into the session as cache
|
||||||
*/
|
*/
|
||||||
private static function loadVersion() {
|
private static function loadVersion() {
|
||||||
|
if (self::$versionCache !== null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$timestamp = filemtime(OC::$SERVERROOT . '/version.php');
|
$timestamp = filemtime(OC::$SERVERROOT . '/version.php');
|
||||||
if (!\OC::$server->getSession()->exists('OC_Version') or OC::$server->getSession()->get('OC_Version_Timestamp') != $timestamp) {
|
require OC::$SERVERROOT . '/version.php';
|
||||||
require OC::$SERVERROOT . '/version.php';
|
/** @var $timestamp int */
|
||||||
$session = \OC::$server->getSession();
|
self::$versionCache['OC_Version_Timestamp'] = $timestamp;
|
||||||
/** @var $timestamp int */
|
/** @var $OC_Version string */
|
||||||
$session->set('OC_Version_Timestamp', $timestamp);
|
self::$versionCache['OC_Version'] = $OC_Version;
|
||||||
/** @var $OC_Version string */
|
/** @var $OC_VersionString string */
|
||||||
$session->set('OC_Version', $OC_Version);
|
self::$versionCache['OC_VersionString'] = $OC_VersionString;
|
||||||
/** @var $OC_VersionString string */
|
/** @var $OC_Build string */
|
||||||
$session->set('OC_VersionString', $OC_VersionString);
|
self::$versionCache['OC_Build'] = $OC_Build;
|
||||||
/** @var $OC_Build string */
|
|
||||||
$session->set('OC_Build', $OC_Build);
|
|
||||||
|
|
||||||
// Allow overriding update channel
|
// Allow overriding update channel
|
||||||
|
if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
|
||||||
|
$channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel');
|
||||||
|
} else {
|
||||||
|
/** @var $OC_Channel string */
|
||||||
|
$channel = $OC_Channel;
|
||||||
|
}
|
||||||
|
|
||||||
if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
|
if (!is_null($channel)) {
|
||||||
$channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel');
|
self::$versionCache['OC_Channel'] = $channel;
|
||||||
} else {
|
} else {
|
||||||
/** @var $OC_Channel string */
|
/** @var $OC_Channel string */
|
||||||
$channel = $OC_Channel;
|
self::$versionCache['OC_Channel'] = $OC_Channel;
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($channel)) {
|
|
||||||
$session->set('OC_Channel', $channel);
|
|
||||||
} else {
|
|
||||||
/** @var $OC_Channel string */
|
|
||||||
$session->set('OC_Channel', $OC_Channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue