setValue() public method

Sets the given preference to the specified value if the preference is modifiable.
public setValue ( string $pref, string $val, array $opts = [] ) : boolean
$pref string The preference name to modify.
$val string The preference value (UTF-8).
$opts array Additional options:
  - force: (boolean) If true, will set the value disregarding the
           current locked status of the pref. (@since 2.5.0)
           DEFAULT: false
  - nosave: (boolean) If true, the preference will not be saved to the
            storage backend(s).
            DEFAULT: false
return boolean True if the value was successfully set, false on a failure.
Esempio n. 1
0
 /**
  * Upgrades the given preferences from the old H3 way of storing
  * serialized data.
  * OLD method: convert charset, serialize, store.
  * NEW method: serialize, convert charset, store.
  *
  * @param Horde_Prefs $prefs_ob  The preferences object.
  * @param array $names           The list of names to upgrade.
  */
 public function upgradeSerialized($prefs_ob, array $names)
 {
     /* Only do upgrade for SQL driver. */
     foreach ($prefs_ob->getStorage() as $storage) {
         if ($storage instanceof Horde_Prefs_Storage_Sql) {
             break;
         }
     }
     if (!$storage instanceof Horde_Prefs_Storage_Sql) {
         return;
     }
     /* Only do upgrade if charset is not UTF-8. */
     $charset = $storage->getCharset();
     if (strcasecmp($charset, 'UTF-8') === 0) {
         return;
     }
     foreach ($names as $name) {
         if (!$prefs_ob->isDefault($name)) {
             $data = $prefs_ob->getValue($name);
             /* Need to convert only if unserialize fails. If it succeeds,
              * the data has already been converted or there is no need
              * to convert. */
             if (@unserialize($data) === false) {
                 /* Re-convert to original charset. */
                 $data = Horde_String::convertCharset($data, 'UTF-8', $charset);
                 /* Unserialize. If we fail here, remove the value
                  * outright since it is invalid and can not be fixed. */
                 if (($data = @unserialize($data)) !== false) {
                     $data = Horde_String::convertCharset($data, $charset, 'UTF-8');
                     /* Re-save in the prefs backend in the new format. */
                     $prefs_ob->setValue($name, serialize($data));
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Saves all identities in the prefs backend.
  */
 public function save()
 {
     $this->_prefs->setValue($this->_prefnames['identities'], serialize($this->_identities));
     $this->_prefs->setValue($this->_prefnames['default_identity'], $this->_default);
 }