]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
A better way to safely delete Foreign_links
authorZach Copley <zach@status.net>
Fri, 5 Mar 2010 03:14:40 +0000 (03:14 +0000)
committerZach Copley <zach@status.net>
Fri, 5 Mar 2010 03:14:40 +0000 (03:14 +0000)
classes/Foreign_link.php
plugins/TwitterBridge/twitter.php
plugins/TwitterBridge/twitterauthorization.php
plugins/TwitterBridge/twittersettings.php

index ae8c22fd84742b6b0c48ece953f364a87d3f7993..e47b2e3096c7c2d88c99739ef37c64f263318655 100644 (file)
@@ -113,4 +113,21 @@ class Foreign_link extends Memcached_DataObject
         return User::staticGet($this->user_id);
     }
 
+    // Make sure we only ever delete one record at a time
+    function safeDelete()
+    {
+        if (!empty($this->user_id)
+            && !empty($this->foreign_id)
+            && !empty($this->service))
+        {
+            return $this->delete();
+        } else {
+            common_debug(LOG_WARNING,
+                'Foreign_link::safeDelete() tried to delete a '
+                . 'Foreign_link without a fully specified compound key: '
+                . var_export($this, true));
+            return false;
+        }
+    }
+
 }
index 42db3c673d92d1cdf2898b9c458086d8042386fd..5086999394257fe0089b46407b3ec8140059a279 100644 (file)
@@ -264,16 +264,7 @@ function remove_twitter_link($flink)
     common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' .
                "user $user->nickname (user id: $user->id).");
 
-    $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();
-    }
+    $result = $flink->safeDelete();
 
     if (empty($result)) {
         common_log(LOG_ERR, 'Could not remove Twitter bridge ' .
index 029c3a44b489bc55ffd5e10536d0adb91a75989a..bc004cb955f6082308823a764d4f5487d410a793 100644 (file)
@@ -278,7 +278,7 @@ class TwitterauthorizationAction extends Action
         $result = $flink->find(true);
 
         if (!empty($result)) {
-            $flink->delete();
+            $flink->safeDelete();
         }
 
         $flink->user_id     = $user_id;
index f22a059f74fceb0fdc9a82b609643c77c1a2e8f2..631b29f52a83f1ab294162af689d3a30e20679ef 100644 (file)
@@ -250,16 +250,7 @@ class TwittersettingsAction extends ConnectSettingsAction
         $user = common_current_user();
         $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
 
-        $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();
-        }
+        $result = $flink->safeDelete();
 
         if (empty($result)) {
             common_log_db_error($flink, 'DELETE', __FILE__);