]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Profile creation always failed because we didn't COMMIT
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 20 Oct 2013 15:22:20 +0000 (17:22 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 20 Oct 2013 15:22:44 +0000 (17:22 +0200)
plugins/OStatus/classes/Ostatus_profile.php

index 4b81de92d895e8d5d7eb4eb3e6c5bb1ba311148a..6ad3023cb2150deaba7786ddd01d47deb995962e 100644 (file)
@@ -1511,21 +1511,51 @@ class Ostatus_profile extends Managed_DataObject
             self::updateProfile($profile, $object, $hints);
 
             $oprofile->profile_id = $profile->insert();
-            if (!$oprofile->profile_id) {
+            if ($oprofile->profile_id === false) {
                 // TRANS: Server exception.
                 throw new ServerException(_m('Cannot save local profile.'));
             }
         } else if ($object->type == ActivityObject::GROUP) {
+            $profile = new Profile();
+            $profile->query('BEGIN');
+
             $group = new User_group();
             $group->uri = $homeuri;
             $group->created = common_sql_now();
             self::updateGroup($group, $object, $hints);
 
+            // TODO: We should do this directly in User_group->insert()!
+            // currently it's duplicated in User_group->update()
+            // AND User_group->register()!!!
+            $fields = array(/*group field => profile field*/
+                        'nickname'      => 'nickname',
+                        'fullname'      => 'fullname',
+                        'mainpage'      => 'profileurl',
+                        'homepage'      => 'homepage',
+                        'description'   => 'bio',
+                        'location'      => 'location',
+                        'created'       => 'created',
+                        'modified'      => 'modified',
+                        );
+            foreach ($fields as $gf=>$pf) {
+                $profile->$pf = $group->$gf;
+            }
+            $profile_id = $profile->insert();
+            if ($profile_id === false) {
+                $profile->query('ROLLBACK');
+                throw new ServerException(_('Profile insertion failed.'));
+            }
+
+            $group->profile_id = $profile_id;
+
             $oprofile->group_id = $group->insert();
-            if (!$oprofile->group_id) {
+            if ($oprofile->group_id === false) {
+                $profile->query('ROLLBACK');
                 // TRANS: Server exception.
                 throw new ServerException(_m('Cannot save local profile.'));
             }
+
+            $profile->query('COMMIT');
         } else if ($object->type == ActivityObject::_LIST) {
             $ptag = new Profile_list();
             $ptag->uri = $homeuri;
@@ -1533,15 +1563,15 @@ class Ostatus_profile extends Managed_DataObject
             self::updatePeopletag($ptag, $object, $hints);
 
             $oprofile->peopletag_id = $ptag->insert();
-            if (!$oprofile->peopletag_id) {
-            // TRANS: Server exception.
+            if ($oprofile->peopletag_id === false) {
+                // TRANS: Server exception.
                 throw new ServerException(_m('Cannot save local list.'));
             }
         }
 
         $ok = $oprofile->insert();
 
-        if (!$ok) {
+        if ($ok === false) {
             // TRANS: Server exception.
             throw new ServerException(_m('Cannot save OStatus profile.'));
         }
@@ -1654,7 +1684,7 @@ class Ostatus_profile extends Managed_DataObject
         }
     }
 
-    protected static function updateGroup($group, $object, $hints=array())
+    protected static function updateGroup(User_group $group, $object, $hints=array())
     {
         $orig = clone($group);
 
@@ -1672,7 +1702,7 @@ class Ostatus_profile extends Managed_DataObject
         $group->location = self::getActivityObjectLocation($object, $hints);
         $group->homepage = self::getActivityObjectHomepage($object, $hints);
 
-        if ($group->id) {
+        if ($group->id) {   // If no id, we haven't called insert() yet, so don't run update()
             common_log(LOG_DEBUG, "Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
             $group->update($orig);
         }