@@ -158,9 +158,11 @@ function get_prefs()
158158 * Write the given user prefs to the user's record
159159 *
160160 * @param array $a_user_prefs User prefs to save
161+ * @param bool $no_session Simplified language/preferences handling
162+ *
161163 * @return boolean True on success, False on failure
162164 */
163- function save_prefs ($ a_user_prefs )
165+ function save_prefs ($ a_user_prefs, $ no_session = false )
164166 {
165167 if (!$ this ->ID )
166168 return false ;
@@ -187,33 +189,40 @@ function save_prefs($a_user_prefs)
187189 }
188190
189191 $ save_prefs = serialize ($ save_prefs );
192+ if (!$ no_session ) {
193+ $ this ->language = $ _SESSION ['language ' ];
194+ }
190195
191196 $ this ->db ->query (
192197 "UPDATE " .$ this ->db ->table_name ('users ' ).
193198 " SET preferences = ? " .
194199 ", language = ? " .
195200 " WHERE user_id = ? " ,
196201 $ save_prefs ,
197- $ _SESSION [ ' language ' ] ,
202+ $ this -> language ,
198203 $ this ->ID );
199204
200- $ this ->language = $ _SESSION ['language ' ];
201-
202205 // Update success
203206 if ($ this ->db ->affected_rows () !== false ) {
204- $ config ->set_user_prefs ($ a_user_prefs );
205207 $ this ->data ['preferences ' ] = $ save_prefs ;
206208
207- if (isset ($ _SESSION ['preferences ' ])) {
208- $ this ->rc ->session ->remove ('preferences ' );
209- $ this ->rc ->session ->remove ('preferences_time ' );
209+ if (!$ no_session ) {
210+ $ config ->set_user_prefs ($ a_user_prefs );
211+
212+ if (isset ($ _SESSION ['preferences ' ])) {
213+ $ this ->rc ->session ->remove ('preferences ' );
214+ $ this ->rc ->session ->remove ('preferences_time ' );
215+ }
210216 }
217+
211218 return true ;
212219 }
213220 // Update error, but we are using replication (we have read-only DB connection)
214221 // and we are storing session not in the SQL database
215222 // we can store preferences in session and try to write later (see get_prefs())
216- else if ($ this ->db ->is_replicated () && $ config ->get ('session_storage ' , 'db ' ) != 'db ' ) {
223+ else if (!$ no_session && $ this ->db ->is_replicated ()
224+ && $ config ->get ('session_storage ' , 'db ' ) != 'db '
225+ ) {
217226 $ _SESSION ['preferences ' ] = $ save_prefs ;
218227 $ _SESSION ['preferences_time ' ] = time ();
219228 $ config ->set_user_prefs ($ a_user_prefs );
0 commit comments