From 5e149fdd05cfaf0626c297695d006a11ed76c997 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Thu, 15 May 2014 16:31:12 +0300 Subject: [PATCH] fixed 'cacheTimestamp' for config changes --- application/Espo/Controllers/Settings.php | 2 -- application/Espo/Core/DataManager.php | 4 +--- application/Espo/Core/Utils/Config.php | 25 +++++++++++++++++++++++ tests/testData/Utils/Config/config.php | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/application/Espo/Controllers/Settings.php b/application/Espo/Controllers/Settings.php index 3c495fe137..f84300637b 100644 --- a/application/Espo/Controllers/Settings.php +++ b/application/Espo/Controllers/Settings.php @@ -43,8 +43,6 @@ class Settings extends \Espo\Core\Controllers\Base throw new Error('Cannot save settings'); } - $this->getContainer()->get('dataManager')->updateCacheTimestamp(); - return $this->getConfig()->getData($this->getUser()->isAdmin()); } } diff --git a/application/Espo/Core/DataManager.php b/application/Espo/Core/DataManager.php index 10e3ffeceb..5a1f3a8a68 100644 --- a/application/Espo/Core/DataManager.php +++ b/application/Espo/Core/DataManager.php @@ -121,9 +121,7 @@ class DataManager */ public function updateCacheTimestamp() { - $config = $this->getContainer()->get('config'); - - return $config->set('cacheTimestamp', time()); + return $this->getContainer()->get('config')->updateCacheTimestamp(); } diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index 933211ace7..ddc3bb62a7 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -34,6 +34,8 @@ class Config protected $configPath = 'data/config.php'; + private $cacheTimestamp = 'cacheTimestamp'; + /** * Array of admin items * @@ -121,6 +123,10 @@ class Config return false; } + if (!isset($values[$this->cacheTimestamp])) { + $values = array_merge($this->updateCacheTimestamp(true), $values); + } + $result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, true); $this->loadConfig(true); @@ -192,6 +198,25 @@ class Config return $this->setArray($values); } + /** + * Update cache timestamp + * + * @param $onlyValue - If need to return just timestamp array + * @return bool | array + */ + public function updateCacheTimestamp($onlyValue = false) + { + $timestamp = array( + $this->cacheTimestamp => time(), + ); + + if ($onlyValue) { + return $timestamp; + } + + return $this->set($timestamp); + } + /** * Get admin items * diff --git a/tests/testData/Utils/Config/config.php b/tests/testData/Utils/Config/config.php index e0a3a722af..2aae4eb795 100644 --- a/tests/testData/Utils/Config/config.php +++ b/tests/testData/Utils/Config/config.php @@ -144,7 +144,7 @@ return array ( 10 => 'cron', ), 'isInstalled' => true, - 'cacheTimestamp' => 1399456816, + 'cacheTimestamp' => 1400160414, 'testOption' => 'Another Wrong Value', 'testOption2' => 'Test2', );