UserModel::saveToSerializedColumn PHP Method

saveToSerializedColumn() public method

This method throws exceptions when errors are encountered. Use try catch blocks to capture these exceptions.
public saveToSerializedColumn ( string $Column, integer $UserID, mixed $Name, mixed $Value = '' )
$Column string The name of the serialized column to save to. At the time of this writing there are three serialized columns on the user table: Permissions, Preferences, and Attributes.
$UserID integer The UserID to save.
$Name mixed The name of the value being saved, or an associative array of name => value pairs to be saved. If this is an associative array, the $Value argument will be ignored.
$Value mixed The value being saved.
    public function saveToSerializedColumn($Column, $UserID, $Name, $Value = '')
    {
        // Load the existing values
        $UserData = $this->getID($UserID, DATASET_TYPE_OBJECT);
        if (!$UserData) {
            throw new Exception(sprintf('User %s not found.', $UserID));
        }
        $Values = val($Column, $UserData);
        if (!is_array($Values) && !is_object($Values)) {
            $Values = dbdecode($UserData->{$Column});
        }
        // Throw an exception if the field was not empty but is also not an object or array
        if (is_string($Values) && $Values != '') {
            throw new Exception(sprintf(t('Serialized column "%s" failed to be unserialized.'), $Column));
        }
        if (!is_array($Values)) {
            $Values = [];
        }
        // Hook for plugins
        $this->EventArguments['CurrentValues'] =& $Values;
        $this->EventArguments['Column'] =& $Column;
        $this->EventArguments['UserID'] =& $UserID;
        $this->EventArguments['Name'] =& $Name;
        $this->EventArguments['Value'] =& $Value;
        $this->fireEvent('BeforeSaveSerialized');
        // Assign the new value(s)
        if (!is_array($Name)) {
            $Name = [$Name => $Value];
        }
        $RawValues = array_merge($Values, $Name);
        $Values = [];
        foreach ($RawValues as $Key => $RawValue) {
            if (!is_null($RawValue)) {
                $Values[$Key] = $RawValue;
            }
        }
        $Values = dbencode($Values);
        // Save the values back to the db
        $SaveResult = $this->SQL->put('User', [$Column => $Values], ['UserID' => $UserID]);
        $this->clearCache($UserID, ['user']);
        return $SaveResult;
    }
UserModel