]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
correctly handle remote re-subscribe
authorEvan Prodromou <evan@prodromou.name>
Mon, 15 Dec 2008 13:48:24 +0000 (08:48 -0500)
committerEvan Prodromou <evan@prodromou.name>
Mon, 15 Dec 2008 13:48:24 +0000 (08:48 -0500)
darcs-hash:20081215134824-84dde-de48c99b6cb45cc461125a7f8f382eb57de0bf28.gz

actions/finishremotesubscribe.php

index 97f9720430dcd581d0b55cf08637b50eae8c92f9..58040683fdb44bed058e280b903633f382920902 100644 (file)
@@ -188,13 +188,31 @@ class FinishremotesubscribeAction extends Action {
         }
 
                $sub = new Subscription();
+
                $sub->subscriber = $remote->id;
                $sub->subscribed = $user->id;
+
+        $sub_exists = false;
+
+        if ($sub->find(true)) {
+            $sub_exists = true;
+            $orig_sub = clone($sub);
+        } else {
+            $sub_exists = false;
+            $sub->created = DB_DataObject_Cast::dateTime(); # current time
+        }
+
                $sub->token = $newtok;
                $sub->secret = $newsecret;
-               $sub->created = DB_DataObject_Cast::dateTime(); # current time
 
-               if (!$sub->insert()) {
+        if ($sub_exists) {
+            $result = $sub->update($orig_sub);
+        } else {
+            $result = $sub->insert();
+        }
+
+               if (!$result) {
+            common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
                        common_user_error(_('Couldn\'t insert new subscription.'));
                        return;
                }