Do not cache app settings in session

This commit is contained in:
Frederic Guillot
2016-01-14 21:42:28 -05:00
parent a8f404421f
commit 9e24bb2ef0
8 changed files with 196 additions and 118 deletions

View File

@@ -14,32 +14,6 @@ use Kanboard\Core\Session\SessionManager;
*/
class Config extends Setting
{
/**
* Get available currencies
*
* @access public
* @return array
*/
public function getCurrencies()
{
return array(
'USD' => t('USD - US Dollar'),
'EUR' => t('EUR - Euro'),
'GBP' => t('GBP - British Pound'),
'CHF' => t('CHF - Swiss Francs'),
'CAD' => t('CAD - Canadian Dollar'),
'AUD' => t('AUD - Australian Dollar'),
'NZD' => t('NZD - New Zealand Dollar'),
'INR' => t('INR - Indian Rupee'),
'JPY' => t('JPY - Japanese Yen'),
'RSD' => t('RSD - Serbian dinar'),
'SEK' => t('SEK - Swedish Krona'),
'NOK' => t('NOK - Norwegian Krone'),
'BAM' => t('BAM - Konvertible Mark'),
'RUB' => t('RUB - Russian Ruble'),
);
}
/**
* Get available timezones
*
@@ -59,6 +33,31 @@ class Config extends Setting
return $listing;
}
/**
* Get current timezone
*
* @access public
* @return string
*/
public function getCurrentTimezone()
{
if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) {
return $this->sessionStorage->user['timezone'];
}
return $this->get('application_timezone', 'UTC');
}
/**
* Set timezone
*
* @access public
*/
public function setupTimezone()
{
date_default_timezone_set($this->getCurrentTimezone());
}
/**
* Get available languages
*
@@ -156,43 +155,6 @@ class Config extends Setting
return $this->get('application_language', 'en_US');
}
/**
* Get a config variable from the session or the database
*
* @access public
* @param string $name Parameter name
* @param string $default_value Default value of the parameter
* @return string
*/
public function get($name, $default_value = '')
{
if (! SessionManager::isOpen()) {
return $this->getOption($name, $default_value);
}
// Cache config in session
if (! isset($this->sessionStorage->config[$name])) {
$this->sessionStorage->config = $this->getAll();
}
if (! empty($this->sessionStorage->config[$name])) {
return $this->sessionStorage->config[$name];
}
return $default_value;
}
/**
* Reload settings in the session and the translations
*
* @access public
*/
public function reload()
{
$this->sessionStorage->config = $this->getAll();
$this->setupTranslations();
}
/**
* Load translations
*
@@ -204,28 +166,27 @@ class Config extends Setting
}
/**
* Get current timezone
* Get a config variable from the session or the database
*
* @access public
* @param string $name Parameter name
* @param string $default_value Default value of the parameter
* @return string
*/
public function getCurrentTimezone()
public function get($name, $default_value = '')
{
if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) {
return $this->sessionStorage->user['timezone'];
}
return $this->get('application_timezone', 'UTC');
$options = $this->memoryCache->proxy($this, 'getAll');
return isset($options[$name]) && $options[$name] !== '' ? $options[$name] : $default_value;
}
/**
* Set timezone
* Reload settings in the session and the translations
*
* @access public
*/
public function setupTimezone()
public function reload()
{
date_default_timezone_set($this->getCurrentTimezone());
$this->setupTranslations();
}
/**
@@ -236,7 +197,7 @@ class Config extends Setting
*/
public function optimizeDatabase()
{
return $this->db->getconnection()->exec("VACUUM");
return $this->db->getconnection()->exec('VACUUM');
}
/**
@@ -266,10 +227,11 @@ class Config extends Setting
*
* @access public
* @param string $option Parameter name
* @return boolean
*/
public function regenerateToken($option)
{
$this->save(array($option => Token::getToken()));
return $this->save(array($option => Token::getToken()));
}
/**

View File

@@ -17,6 +17,32 @@ class Currency extends Base
*/
const TABLE = 'currencies';
/**
* Get available application currencies
*
* @access public
* @return array
*/
public function getCurrencies()
{
return array(
'USD' => t('USD - US Dollar'),
'EUR' => t('EUR - Euro'),
'GBP' => t('GBP - British Pound'),
'CHF' => t('CHF - Swiss Francs'),
'CAD' => t('CAD - Canadian Dollar'),
'AUD' => t('AUD - Australian Dollar'),
'NZD' => t('NZD - New Zealand Dollar'),
'INR' => t('INR - Indian Rupee'),
'JPY' => t('JPY - Japanese Yen'),
'RSD' => t('RSD - Serbian dinar'),
'SEK' => t('SEK - Swedish Krona'),
'NOK' => t('NOK - Norwegian Krone'),
'BAM' => t('BAM - Konvertible Mark'),
'RUB' => t('RUB - Russian Ruble'),
);
}
/**
* Get all currency rates
*

View File

@@ -47,10 +47,12 @@ abstract class Setting extends Base
*/
public function getOption($name, $default = '')
{
return $this->db
$value = $this->db
->table(self::TABLE)
->eq('option', $name)
->findOneColumn('value') ?: $default;
->findOneColumn('value');
return $value === null || $value === false || $value === '' ? $default : $value;
}
/**