瀏覽代碼

Serialize option types whose values are not scalar. At first, I strongly considered simply serializing ALL prefs when they are written to the pref backend, because that method automates prefs better and the user (developer) needn't concern themselves with the details thereof (with this solution, they have to know to unserialize certain prefs after calling getPref()). I changed my mind, though, primarily because calling unserialize() for every pref that is loaded and serialize() for every pref that is stored seems like unnecessary overhead, and serializing prefs now might unstabilize what seems to be a fairly stable pref storage system to date. Secondarily, I didn't want to screw everybody's pref files up. The other bonus is that this can be backported to STABLE (which I just might do). Again, this solution does mean that developers do have to manually unserialize any non-scalar pref settings.

pdontthink 17 年之前
父節點
當前提交
77166d8c0c
共有 1 個文件被更改,包括 16 次插入3 次删除
  1. 16 3
      functions/options.php

+ 16 - 3
functions/options.php

@@ -526,16 +526,29 @@ class SquirrelOption {
 } /* End of SquirrelOption class*/
 
 /**
- * Saves option
+ * Saves the option value (this is the default save function
+ * unless overridden by the user)
+ *
  * @param object $option object that holds option name and new_value
  */
 function save_option($option) {
+
+    // Can't save the pref if we don't have the username
+    //
     if ( !sqgetGlobalVar('username', $username, SQ_SESSION ) ) {
-        /* Can't save the pref if we don't have the username */
         return;
     }
+
     global $data_dir;
-    setPref($data_dir, $username, $option->name, $option->new_value);
+
+    // Certain option types need to be serialized because
+    // they are not scalar
+    //
+    if ($option->type == SMOPT_TYPE_FLDRLIST_MULTI)
+        setPref($data_dir, $username, $option->name, serialize($option->new_value));
+    else
+        setPref($data_dir, $username, $option->name, $option->new_value);
+
 }
 
 /**