diff options
author | zach <zach@controlyourself.ca> | 2008-11-14 00:30:44 -0500 |
---|---|---|
committer | zach <zach@controlyourself.ca> | 2008-11-14 00:30:44 -0500 |
commit | fed15bd6b7bcbca6d4707dc4ccedd8784fcadfb2 (patch) | |
tree | 48a6030a320a74476a17622f0a79ff78134cecd9 /actions/twittersettings.php | |
parent | 65b22d2fdfdabc5c4916b0d96cde6f8869053994 (diff) |
Twitter bridge - don't delete Twitter users. Update them instead.
darcs-hash:20081114053044-462f3-30e2d27261bca1977b89dee409383e178f446149.gz
Diffstat (limited to 'actions/twittersettings.php')
-rw-r--r-- | actions/twittersettings.php | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/actions/twittersettings.php b/actions/twittersettings.php index cf50be62a..1115708a5 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -138,16 +138,45 @@ class TwittersettingsAction extends SettingsAction { return; } - $fuser = DB_DataObject::factory('foreign_user'); - $fuser->id = $twitter_id; - $fuser->service = 1; // Twitter - $fuser->uri = "http://www.twitter.com/$twitter_username"; - $fuser->nickname = $twitter_username; - $fuser->created = common_sql_now(); - $result = $fuser->insert(); + $fuser = null; + $result = null; + + // Check to see whether the Twitter user is already in the system, + // and update its username and uri if so. + $fuser = Foreign_User::getForeignUser($twitter_id, 1); + + if ($fuser) { + + $original = clone($fuser); + + $fuser->nickname = $twitter_username; + $fuser->uri = "http://www.twitter.com/$twitter_username"; + + $result = $fuser->updateKeys($original); + + if (!$result) { + common_log_db_error($fuser, 'UPDATE', __FILE__); + } + + } else { + + // Otherwise, add the Twitter user + $fuser = DB_DataObject::factory('foreign_user'); + + $fuser->nickname = $twitter_username; + $fuser->uri = "http://www.twitter.com/$twitter_username"; + $fuser->id = $twitter_id; + $fuser->service = 1; // Twitter + $fuser->created = common_sql_now(); + $result = $fuser->insert(); + + if (!$result) { + common_log_db_error($fuser, 'INSERT', __FILE__); + } + + } if (!$result) { - common_log_db_error($fuser, 'INSERT', __FILE__); $this->show_form(_('Unable to save your Twitter settings!')); return; } @@ -162,7 +191,7 @@ class TwittersettingsAction extends SettingsAction { $flink->created = common_sql_now(); $this->set_flags($flink, $noticesync, $replysync, $friendsync); - + $flink_id = $flink->insert(); if (!$flink_id) { @@ -179,7 +208,6 @@ class TwittersettingsAction extends SettingsAction { // For now we assume one Twitter acct per Laconica acct $flink = Foreign_link::getForeignLink($user->id, 1); - $fuser = Foreign_user::getForeignUser($flink->foreign_id, 1); $flink_foreign_id = $this->arg('flink_foreign_id'); if (!$flink) { @@ -193,14 +221,6 @@ class TwittersettingsAction extends SettingsAction { return; } - $result = $fuser->delete(); - - if (!$result) { - common_log_db_error($fuser, 'DELETE', __FILE__); - $this->show_form(_('Couldn\'t remove Twitter user.')); - return; - } - $result = $flink->delete(); if (!$result) { @@ -229,7 +249,7 @@ class TwittersettingsAction extends SettingsAction { $flink->query('BEGIN'); $original = clone($flink); - + $this->set_flags($flink, $noticesync, $replysync, $friendsync); $result = $flink->update($original); @@ -318,7 +338,7 @@ class TwittersettingsAction extends SettingsAction { } else { $flink->noticesync &= ~FOREIGN_NOTICE_SEND; } - + if ($replysync) { $flink->noticesync |= FOREIGN_NOTICE_SEND_REPLY; } else { @@ -330,7 +350,7 @@ class TwittersettingsAction extends SettingsAction { } else { $flink->friendsync &= ~FOREIGN_FRIEND_RECV; } - + $flink->profilesync = 0; // XXX: leave as default? } }
\ No newline at end of file |