]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix for errant deletion of all Twitter foreign_links
authorZach Copley <zach@status.net>
Fri, 5 Mar 2010 02:27:01 +0000 (02:27 +0000)
committerZach Copley <zach@status.net>
Fri, 5 Mar 2010 02:27:01 +0000 (02:27 +0000)
plugins/TwitterBridge/twitter.php
plugins/TwitterBridge/twitterauthorization.php
plugins/TwitterBridge/twittersettings.php

index ceb83b037f23dc714b02fe6cda5b2b6bd3d0c616..42db3c673d92d1cdf2898b9c458086d8042386fd 100644 (file)
@@ -264,7 +264,16 @@ function remove_twitter_link($flink)
     common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' .
                "user $user->nickname (user id: $user->id).");
 
-    $result = $flink->delete();
+    $result = false;
+
+    // Be extra careful to make sure we have a good flink
+    // before deleting
+    if (!empty($flink->user_id)
+                && !empty($flink->foreign_id)
+                && !empty($flink->service))
+    {
+                $result = $flink->delete();
+    }
 
     if (empty($result)) {
         common_log(LOG_ERR, 'Could not remove Twitter bridge ' .
index c93f6666bcc3f718ae42e3ede404abd849005783..029c3a44b489bc55ffd5e10536d0adb91a75989a 100644 (file)
@@ -273,7 +273,13 @@ class TwitterauthorizationAction extends Action
 
         $flink->user_id = $user_id;
         $flink->service = TWITTER_SERVICE;
-        $flink->delete(); // delete stale flink, if any
+
+        // delete stale flink, if any
+        $result = $flink->find(true);
+
+        if (!empty($result)) {
+            $flink->delete();
+        }
 
         $flink->user_id     = $user_id;
         $flink->foreign_id  = $twuid;
@@ -455,6 +461,11 @@ class TwitterauthorizationAction extends Action
 
         $user = User::register($args);
 
+        if (empty($user)) {
+            $this->serverError(_('Error registering user.'));
+            return;
+        }
+
         $result = $this->saveForeignLink($user->id,
                                          $this->twuid,
                                          $this->access_token);
index 0137060e9c04f300ba5726ad8ae8880059f80e2a..f22a059f74fceb0fdc9a82b609643c77c1a2e8f2 100644 (file)
@@ -250,7 +250,16 @@ class TwittersettingsAction extends ConnectSettingsAction
         $user = common_current_user();
         $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
 
-        $result = $flink->delete();
+        $result = false;
+
+        // Be extra careful to make sure we have a good flink
+        // before deleting
+        if (!empty($flink->user_id)
+            && !empty($flink->foreign_id)
+            && !empty($flink->service))
+        {
+            $result = $flink->delete();
+        }
 
         if (empty($result)) {
             common_log_db_error($flink, 'DELETE', __FILE__);