X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FProfile_prefs.php;h=27034390f848d4293ff35f701b95d2ac2ef57a77;hb=0a2c51510ca785b5e3564fc0830518527929dc38;hp=97df488b6a342dafcf8a01a3bd79150ebb05f68f;hpb=f46d675a20bd1c70eeb492d7068fabae83e6a6f5;p=quix0rs-gnu-social.git diff --git a/classes/Profile_prefs.php b/classes/Profile_prefs.php index 97df488b6a..27034390f8 100644 --- a/classes/Profile_prefs.php +++ b/classes/Profile_prefs.php @@ -31,8 +31,8 @@ class Profile_prefs extends Managed_DataObject { public $__table = 'profile_prefs'; // table name public $profile_id; // int(4) primary_key not_null - public $namespace; // varchar(255) not_null - public $topic; // varchar(255) not_null + public $namespace; // varchar(191) not_null + public $topic; // varchar(191) not_null public $data; // text public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00 public $modified; // timestamp not_null default_CURRENT_TIMESTAMP @@ -42,8 +42,8 @@ class Profile_prefs extends Managed_DataObject return array( 'fields' => array( 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'), - 'namespace' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'namespace, like pluginname or category'), - 'topic' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'preference key, i.e. description, age...'), + 'namespace' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'namespace, like pluginname or category'), + 'topic' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'preference key, i.e. description, age...'), 'data' => array('type' => 'blob', 'description' => 'topic data, may be anything'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), @@ -112,15 +112,24 @@ class Profile_prefs extends Managed_DataObject return $pref; } - static function getData(Profile $profile, $namespace, $topic) { - $pref = self::getTopic($profile, $namespace, $topic); + static function getData(Profile $profile, $namespace, $topic, $def=null) { + try { + $pref = self::getTopic($profile, $namespace, $topic); + } catch (NoResultException $e) { + if ($def === null) { + // If no default value was set, continue the exception. + throw $e; + } + // If there was a default value, return that. + return $def; + } return $pref->data; } static function getConfigData(Profile $profile, $namespace, $topic) { try { $data = self::getData($profile, $namespace, $topic); - } catch (Exception $e) { + } catch (NoResultException $e) { $data = common_config($namespace, $topic); } return $data; @@ -159,8 +168,9 @@ class Profile_prefs extends Managed_DataObject $pref->namespace = $namespace; $pref->topic = $topic; $pref->data = $data; + $pref->created = common_sql_now(); - if (!$pref->insert()) { + if ($pref->insert() === false) { throw new ServerException('Could not save profile preference.'); } return true;