From 029b8c90142e08b0ed44f0528ddea7d4dcc32980 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 02:27:01 +0000 Subject: Fix for errant deletion of all Twitter foreign_links --- plugins/TwitterBridge/twitter.php | 11 ++++++++++- plugins/TwitterBridge/twitterauthorization.php | 13 ++++++++++++- plugins/TwitterBridge/twittersettings.php | 11 ++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index ceb83b037..42db3c673 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -264,7 +264,16 @@ function remove_twitter_link($flink) common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' . "user $user->nickname (user id: $user->id)."); - $result = $flink->delete(); + $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(); + } if (empty($result)) { common_log(LOG_ERR, 'Could not remove Twitter bridge ' . diff --git a/plugins/TwitterBridge/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php index c93f6666b..029c3a44b 100644 --- a/plugins/TwitterBridge/twitterauthorization.php +++ b/plugins/TwitterBridge/twitterauthorization.php @@ -273,7 +273,13 @@ class TwitterauthorizationAction extends Action $flink->user_id = $user_id; $flink->service = TWITTER_SERVICE; - $flink->delete(); // delete stale flink, if any + + // delete stale flink, if any + $result = $flink->find(true); + + if (!empty($result)) { + $flink->delete(); + } $flink->user_id = $user_id; $flink->foreign_id = $twuid; @@ -455,6 +461,11 @@ class TwitterauthorizationAction extends Action $user = User::register($args); + if (empty($user)) { + $this->serverError(_('Error registering user.')); + return; + } + $result = $this->saveForeignLink($user->id, $this->twuid, $this->access_token); diff --git a/plugins/TwitterBridge/twittersettings.php b/plugins/TwitterBridge/twittersettings.php index 0137060e9..f22a059f7 100644 --- a/plugins/TwitterBridge/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -250,7 +250,16 @@ class TwittersettingsAction extends ConnectSettingsAction $user = common_current_user(); $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE); - $result = $flink->delete(); + $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(); + } if (empty($result)) { common_log_db_error($flink, 'DELETE', __FILE__); -- cgit v1.2.3-54-g00ecf From 6a377a4ba409083e05d16b163013f0f09c606170 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 03:14:40 +0000 Subject: A better way to safely delete Foreign_links --- classes/Foreign_link.php | 17 +++++++++++++++++ plugins/TwitterBridge/twitter.php | 11 +---------- plugins/TwitterBridge/twitterauthorization.php | 2 +- plugins/TwitterBridge/twittersettings.php | 11 +---------- 4 files changed, 20 insertions(+), 21 deletions(-) (limited to 'plugins') diff --git a/classes/Foreign_link.php b/classes/Foreign_link.php index ae8c22fd8..e47b2e309 100644 --- a/classes/Foreign_link.php +++ b/classes/Foreign_link.php @@ -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; + } + } + } diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index 42db3c673..508699939 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -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 ' . diff --git a/plugins/TwitterBridge/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php index 029c3a44b..bc004cb95 100644 --- a/plugins/TwitterBridge/twitterauthorization.php +++ b/plugins/TwitterBridge/twitterauthorization.php @@ -278,7 +278,7 @@ class TwitterauthorizationAction extends Action $result = $flink->find(true); if (!empty($result)) { - $flink->delete(); + $flink->safeDelete(); } $flink->user_id = $user_id; diff --git a/plugins/TwitterBridge/twittersettings.php b/plugins/TwitterBridge/twittersettings.php index f22a059f7..631b29f52 100644 --- a/plugins/TwitterBridge/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -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__); -- cgit v1.2.3-54-g00ecf From 89e313e45b1b08fc80ab908e4dd531689319aa6f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 5 Mar 2010 10:55:07 -0800 Subject: OStatus fix: send the feed's root element, not the DOM document, down to low-level feed processing as entry context on PuSH input. --- plugins/OStatus/classes/Ostatus_profile.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index fcca1a252..abc8100ce 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -428,10 +428,18 @@ class Ostatus_profile extends Memcached_DataObject * Currently assumes that all items in the feed are new, * coming from a PuSH hub. * - * @param DOMDocument $feed + * @param DOMDocument $doc + * @param string $source identifier ("push") */ - public function processFeed($feed, $source) + public function processFeed(DOMDocument $doc, $source) { + $feed = $doc->documentElement; + + if ($feed->localName != 'feed' || $feed->namespaceURI != Activity::ATOM) { + common_log(LOG_ERR, __METHOD__ . ": not an Atom feed, ignoring"); + return; + } + $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); if ($entries->length == 0) { common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring"); @@ -449,6 +457,7 @@ class Ostatus_profile extends Memcached_DataObject * * @param DOMElement $entry * @param DOMElement $feed for context + * @param string $source identifier ("push" or "salmon") */ public function processEntry($entry, $feed, $source) { -- cgit v1.2.3-54-g00ecf From 5355c3b7b579f803bb18913db3b4d9cf380f17ac Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 5 Mar 2010 15:00:27 -0800 Subject: OpenID fix: - avoid notice on insert (missing sequenceKeys()) - avoid cache corruption on delete (user_id was missing from keys list, cache not cleared for user_id lookups) --- plugins/OpenID/User_openid.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/OpenID/User_openid.php b/plugins/OpenID/User_openid.php index 801b49ecc..5ef05b4c7 100644 --- a/plugins/OpenID/User_openid.php +++ b/plugins/OpenID/User_openid.php @@ -39,9 +39,21 @@ class User_openid extends Memcached_DataObject ); } + /** + * List primary and unique keys in this table. + * Unique keys used for lookup *MUST* be listed to ensure proper caching. + */ function keys() { - return array('canonical' => 'K', 'display' => 'U'); + return array('canonical' => 'K', 'display' => 'U', 'user_id' => 'U'); + } + + /** + * No sequence keys in this table. + */ + function sequenceKey() + { + return array(false, false, false); } Static function hasOpenID($user_id) -- cgit v1.2.3-54-g00ecf