]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile_prefs.php
Merge commit 'refs/merge-requests/43' of https://gitorious.org/social/mainline into...
[quix0rs-gnu-social.git] / classes / Profile_prefs.php
index 7ad6233c5514a59c0015db77924526f6169815d9..ee0fa0e27cce09c96a5e2d568a9c9558397bf518 100644 (file)
@@ -20,7 +20,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Data
- * @package   GNUSocial
+ * @package   GNUsocial
  * @author    Mikael Nordfeldth <mmn@hethane.se>
  * @copyright 2013 Free Software Foundation, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
@@ -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;