function subscribeTwitterFriends(Foreign_link $flink) { try { $profile = $flink->getProfile(); } catch (NoResultException $e) { common_log(LOG_WARNING, 'Foreign_link has no matching local profile for local ID: ' . $flink->user_id); } $friends = $this->fetchTwitterFriends($flink); if (empty($friends)) { common_debug($this->name() . ' - Couldn\'t get friends from Twitter for ' . "Twitter user {$flink->foreign_id}."); return false; } foreach ($friends as $friend) { $friend_name = $friend->screen_name; $friend_id = (int) $friend->id; // Update or create the Foreign_user record for each // Twitter friend if (!save_twitter_user($friend_id, $friend_name)) { common_log(LOG_WARNING, $this->name() . " - Couldn't save {$screen_name}'s friend, {$friend_name}."); continue; } // Check to see if there's a related local user and try to subscribe try { $friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE); // Get associated user and subscribe her $friend_profile = $friend_flink->getProfile(); Subscription::start($profile, $friend_profile); common_log(LOG_INFO, $this->name() . ' - Subscribed ' . "{$friend_profile->nickname} to {$profile->nickname}."); } catch (NoResultException $e) { // either no foreign link for this friend's foreign ID or no profile found on local ID. } catch (Exception $e) { common_debug($this->name() . ' - Tried and failed subscribing ' . "{$friend_profile->nickname} to {$profile->nickname} - " . $e->getMessage()); } } return true; }