]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile_prefs.php
Add check after oembed API call. In case of error, returned value is false which...
[quix0rs-gnu-social.git] / classes / Profile_prefs.php
index 85894852864bd5ad3568e35bc8e0a68591c3d18e..37ccf4fb9677263aceca5e31f6071282eb4f6680 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
@@ -84,7 +84,11 @@ class Profile_prefs extends Managed_DataObject
 
     static function getAll(Profile $profile)
     {
-        $prefs = self::listFind('profile_id', $profile->id);
+        try {
+            $prefs = self::listFind('profile_id', $profile->id);
+        } catch (NoResultException $e) {
+            return array();
+        }
 
         $list = array();
         while ($entry = $prefs->fetch()) {
@@ -97,8 +101,12 @@ class Profile_prefs extends Managed_DataObject
     }
 
     static function getTopic(Profile $profile, $namespace, $topic) {
-        $pref = self::pkeyGet(array('profile_id'=>$profile->id, 'namespace'=>$namespace, 'topic'=>$topic));
-        if (is_null($pref)) {
+        $pref = new Profile_prefs;
+        $pref->profile_id = $profile->id;
+        $pref->namespace  = $namespace;
+        $pref->topic      = $topic;
+
+        if (!$pref->find(true)) {
             throw new NoResultException($pref);
         }
         return $pref;
@@ -112,7 +120,7 @@ class Profile_prefs extends Managed_DataObject
     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;
@@ -152,7 +160,7 @@ class Profile_prefs extends Managed_DataObject
         $pref->topic      = $topic;
         $pref->data       = $data;
         
-        if (!$pref->insert()) {
+        if ($pref->insert() === false) {
             throw new ServerException('Could not save profile preference.');
         }
         return true;