Merge pull request #837 from romainneutron/fix-1618

[3.8] Fix user settings precedence
This commit is contained in:
Romain Neutron
2013-12-11 14:47:51 -08:00
2 changed files with 16 additions and 13 deletions

View File

@@ -1320,16 +1320,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return $this;
}
$sql = 'SELECT prop, value FROM usr_settings WHERE usr_id= :id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $this->id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
$this->_prefs[$row['prop']] = $row['value'];
}
foreach (self::$def_values as $k => $v) {
if (!isset($this->_prefs[$k])) {
if ($k == 'start_page_query' && $this->app['phraseanet.registry']->get('GV_defaultQuery')) {
@@ -1351,6 +1341,16 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
);
}
$sql = 'SELECT prop, value FROM usr_settings WHERE usr_id= :id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $this->id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
$this->_prefs[$row['prop']] = $row['value'];
}
$this->preferences_loaded = true;
return $this;

View File

@@ -92,11 +92,14 @@ class userTest extends PhraseanetPHPUnitAbstract
);
$user = $this->get_user();
$user->setPrefs('images_per_page', 35);
$user = new \User_Adapter($user->get_id(), self::$DI['app']);
$this->assertNull($user->getPrefs('lalala'));
$this->assertSame(666, $user->getPrefs('images_size'));
$this->assertSame(42, $user->getPrefs('images_per_page'));
$this->assertSame(\User_Adapter::$def_values['editing_top_box'], $user->getPrefs('editing_top_box'));
$this->assertEquals(666, $user->getPrefs('images_size'));
$this->assertEquals(35, $user->getPrefs('images_per_page'));
$this->assertEquals(\User_Adapter::$def_values['editing_top_box'], $user->getPrefs('editing_top_box'));
if (null === $data) {
unset(self::$DI['app']['phraseanet.configuration']['user-settings']);