Delete old Twitter user record when user changes screen name instead of updating. Simpler.

This commit is contained in:
Zach Copley 2010-02-06 06:46:00 +00:00
parent 558934d1dd
commit 70abea3ac4
1 changed files with 8 additions and 46 deletions

View File

@ -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/twitterbasicauthclient.php';
require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.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) 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 // Creates or Updates a Twitter user
function save_twitter_user($twitter_id, $screen_name) function save_twitter_user($twitter_id, $screen_name)
{ {
// Check to see whether the Twitter user is already in the system, // Check to see whether the Twitter user is already in the system,
// and update its screen name and uri if so. // and update its screen name and uri if so.
@ -115,25 +82,20 @@ function save_twitter_user($twitter_id, $screen_name)
$result = true; $result = true;
// Only update if Twitter screen name has changed // Delete old record if Twitter user changed screen name
if ($fuser->nickname != $screen_name) { if ($fuser->nickname != $screen_name) {
$result = updateTwitter_user($twitter_id, $screen_name); $oldname = $fuser->nickname;
$fuser->delete();
common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' . common_log(LOG_INFO, sprintf('Twitter bridge - Updated nickname (and URI) ' .
"$fuser->id to $screen_name, was $fuser->nickname"); '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); return add_twitter_user($twitter_id, $screen_name);
} }
$fuser->free();
unset($fuser);
return true;
} }
function is_twitter_bound($notice, $flink) { function is_twitter_bound($notice, $flink) {