summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-02-06 06:46:00 +0000
committerZach Copley <zach@status.net>2010-02-08 12:16:55 -0800
commitc83d0b5e98fc6e59632a0fa1335b3586996929e2 (patch)
treec2f5c0d11357210369772c22ba53c494478725b6
parent21c0e75a2e52d63eb46de6f5938b00c4c9ba8323 (diff)
Delete old Twitter user record when user changes screen name instead of updating. Simpler.
-rw-r--r--plugins/TwitterBridge/twitter.php54
1 files changed, 8 insertions, 46 deletions
diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php
index 33dfb788b..de30d9ebf 100644
--- a/plugins/TwitterBridge/twitter.php
+++ b/plugins/TwitterBridge/twitter.php
@@ -26,38 +26,6 @@ define('TWITTER_SERVICE', 1); // Twitter is foreign_service ID 1
require_once INSTALLDIR . '/plugins/TwitterBridge/twitterbasicauthclient.php';
require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
-function updateTwitter_user($twitter_id, $screen_name)
-{
- $uri = 'http://twitter.com/' . $screen_name;
- $fuser = new Foreign_user();
-
- $fuser->query('BEGIN');
-
- // Dropping down to SQL because regular DB_DataObject udpate stuff doesn't seem
- // to work so good with tables that have multiple column primary keys
-
- // Any time we update the uri for a forein user we have to make sure there
- // are no dupe entries first -- unique constraint on the uri column
-
- $qry = 'UPDATE foreign_user set uri = \'\' WHERE uri = ';
- $qry .= '\'' . $uri . '\'' . ' AND service = ' . TWITTER_SERVICE;
-
- $fuser->query($qry);
-
- // Update the user
-
- $qry = 'UPDATE foreign_user SET nickname = ';
- $qry .= '\'' . $screen_name . '\'' . ', uri = \'' . $uri . '\' ';
- $qry .= 'WHERE id = ' . $twitter_id . ' AND service = ' . TWITTER_SERVICE;
-
- $fuser->query('COMMIT');
-
- $fuser->free();
- unset($fuser);
-
- return true;
-}
-
function add_twitter_user($twitter_id, $screen_name)
{
@@ -105,7 +73,6 @@ function add_twitter_user($twitter_id, $screen_name)
// Creates or Updates a Twitter user
function save_twitter_user($twitter_id, $screen_name)
{
-
// Check to see whether the Twitter user is already in the system,
// and update its screen name and uri if so.
@@ -115,25 +82,20 @@ function save_twitter_user($twitter_id, $screen_name)
$result = true;
- // Only update if Twitter screen name has changed
+ // Delete old record if Twitter user changed screen name
if ($fuser->nickname != $screen_name) {
- $result = updateTwitter_user($twitter_id, $screen_name);
-
- common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' .
- "$fuser->id to $screen_name, was $fuser->nickname");
+ $oldname = $fuser->nickname;
+ $fuser->delete();
+ common_log(LOG_INFO, sprintf('Twitter bridge - Updated nickname (and URI) ' .
+ 'for Twitter user %1$d - %2$s, was %3$s.',
+ $fuser->id,
+ $screen_name,
+ $oldname));
}
- return $result;
-
- } else {
return add_twitter_user($twitter_id, $screen_name);
}
-
- $fuser->free();
- unset($fuser);
-
- return true;
}
function is_twitter_bound($notice, $flink) {