]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Handle the case where a screen name has shifted from one Twitter ID to another
authorZach Copley <zach@status.net>
Thu, 8 Jul 2010 21:17:10 +0000 (21:17 +0000)
committerZach Copley <zach@status.net>
Thu, 8 Jul 2010 21:17:11 +0000 (21:17 +0000)
classes/Foreign_user.php
plugins/TwitterBridge/twitter.php

index 0dd94ffb99789a38a344fc1f5936bd25a064f683..e98a16064a83cbd51b8f998cf4a95d1546dbbfed 100644 (file)
@@ -39,6 +39,22 @@ class Foreign_user extends Memcached_DataObject
         return null;
     }
 
+    static function getByNickname($nickname, $service)
+    {
+        if (empty($nickname) || empty($service)) {
+            return null;
+        } else {
+            $fuser = new Foreign_user();
+           $fuser->service = $service;
+           $fuser->nickname = $nickname;
+            $fuser->limit(1);
+
+            $result = $fuser->find(true);
+
+            return empty($result) ? null : $fuser;
+        }
+    }
+
     function updateKeys(&$orig)
     {
         $this->_connect();
index 896eee2dac485e87f9fd44434484a182290c48e4..306ba2442abc7ee572318bb18ec0522b4bce2f65 100644 (file)
@@ -75,8 +75,6 @@ function save_twitter_user($twitter_id, $screen_name)
 
     if (!empty($fuser)) {
 
-        $result = true;
-
         // Delete old record if Twitter user changed screen name
 
         if ($fuser->nickname != $screen_name) {
@@ -88,6 +86,25 @@ function save_twitter_user($twitter_id, $screen_name)
                                          $screen_name,
                                          $oldname));
         }
+
+    } else {
+
+        // Kill any old, invalid records for this screen name
+
+        $fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE);
+
+        if (!empty($fuser)) {
+            $fuser->delete();
+            common_log(
+                LOG_INFO,
+                sprintf(
+                    'Twitter bridge - deteted old record for Twitter ' .
+                    'screen name "%s" belonging to Twitter ID %d.',
+                    $screen_name,
+                    $fuser->id
+                )
+            );
+        }
     }
 
     return add_twitter_user($twitter_id, $screen_name);