Exception handling regarding Foreign_link
This commit is contained in:
parent
b609a3610f
commit
e0084a6fdf
|
@ -136,12 +136,12 @@ class Foreign_link extends Managed_DataObject
|
||||||
|
|
||||||
function getUser()
|
function getUser()
|
||||||
{
|
{
|
||||||
return User::getKV($this->user_id);
|
return Profile::getByID($this->user_id)->getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProfile()
|
function getProfile()
|
||||||
{
|
{
|
||||||
return Profile::getKV('id', $this->user_id);
|
return Profile::getByID($this->user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we only ever delete one record at a time
|
// Make sure we only ever delete one record at a time
|
||||||
|
|
|
@ -519,13 +519,10 @@ class FacebookfinishloginAction extends Action
|
||||||
|
|
||||||
function tryLogin()
|
function tryLogin()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
|
$flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
|
||||||
|
|
||||||
if (!empty($flink)) {
|
|
||||||
$user = $flink->getUser();
|
$user = $flink->getUser();
|
||||||
|
|
||||||
if (!empty($user)) {
|
|
||||||
|
|
||||||
common_log(
|
common_log(
|
||||||
LOG_INFO,
|
LOG_INFO,
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -544,9 +541,8 @@ class FacebookfinishloginAction extends Action
|
||||||
setcookie('fb_access_token', '', time() - 3600); // one hour ago
|
setcookie('fb_access_token', '', time() - 3600); // one hour ago
|
||||||
|
|
||||||
$this->goHome($user->nickname);
|
$this->goHome($user->nickname);
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} catch (NoResultException $e) {
|
||||||
$this->showForm(null, $this->bestNewNickname());
|
$this->showForm(null, $this->bestNewNickname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,13 +66,12 @@ class Facebookclient
|
||||||
$this->notice = $notice;
|
$this->notice = $notice;
|
||||||
|
|
||||||
$profile_id = $profile ? $profile->id : $notice->profile_id;
|
$profile_id = $profile ? $profile->id : $notice->profile_id;
|
||||||
$this->flink = Foreign_link::getByUserID(
|
try {
|
||||||
$profile_id,
|
$this->flink = Foreign_link::getByUserID($profile_id, FACEBOOK_SERVICE);
|
||||||
FACEBOOK_SERVICE
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!empty($this->flink)) {
|
|
||||||
$this->user = $this->flink->getUser();
|
$this->user = $this->flink->getUser();
|
||||||
|
} catch (NoResultException $e) {
|
||||||
|
// at least $this->flink could've gotten set to something,
|
||||||
|
// but the logic that was here before didn't care, so let's not care either
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -553,20 +553,19 @@ class TwitterauthorizationAction extends FormAction
|
||||||
$flink = Foreign_link::getByForeignID($this->twuid, TWITTER_SERVICE);
|
$flink = Foreign_link::getByForeignID($this->twuid, TWITTER_SERVICE);
|
||||||
$user = $flink->getUser();
|
$user = $flink->getUser();
|
||||||
|
|
||||||
if ($user instanceof User) {
|
|
||||||
common_debug('TwitterBridge Plugin - ' .
|
common_debug('TwitterBridge Plugin - ' .
|
||||||
"Logged in Twitter user $flink->foreign_id as user $user->id ($user->nickname)");
|
"Logged in Twitter user $flink->foreign_id as user $user->id ($user->nickname)");
|
||||||
|
|
||||||
common_set_user($user);
|
common_set_user($user);
|
||||||
common_real_login(true);
|
common_real_login(true);
|
||||||
$this->goHome($user->nickname);
|
$this->goHome($user->nickname);
|
||||||
}
|
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
// Either no Foreign_link was found or not the user connected to it.
|
// Either no Foreign_link was found or not the user connected to it.
|
||||||
// Let's just continue to allow creating or logging in as a new user.
|
// Let's just continue to allow creating or logging in as a new user.
|
||||||
}
|
}
|
||||||
common_debug("TwitterBridge Plugin - No flink found for twuid: {$this->twuid} - new user");
|
common_debug("TwitterBridge Plugin - No flink found for twuid: {$this->twuid} - new user");
|
||||||
|
|
||||||
|
// FIXME: what do we want to do here? I forgot
|
||||||
return;
|
return;
|
||||||
throw new ServerException(_m('No foreign link found for Twitter user'));
|
throw new ServerException(_m('No foreign link found for Twitter user'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ class TwittersettingsAction extends ProfileSettingsAction
|
||||||
|
|
||||||
$this->elementEnd('ul');
|
$this->elementEnd('ul');
|
||||||
|
|
||||||
if ($this->flink) {
|
if ($this->flink instanceof Foreign_link) {
|
||||||
// TRANS: Button text for saving Twitter integration settings.
|
// TRANS: Button text for saving Twitter integration settings.
|
||||||
$this->submit('save', _m('BUTTON','Save'));
|
$this->submit('save', _m('BUTTON','Save'));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -104,6 +104,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
|
||||||
return $flinks;
|
return $flinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: make it so we can force a Foreign_link here without colliding with parent
|
||||||
function childTask($flink) {
|
function childTask($flink) {
|
||||||
// Each child ps needs its own DB connection
|
// Each child ps needs its own DB connection
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
|
||||||
unset($_DB_DATAOBJECT['CONNECTIONS']);
|
unset($_DB_DATAOBJECT['CONNECTIONS']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchTwitterFriends($flink)
|
function fetchTwitterFriends(Foreign_link $flink)
|
||||||
{
|
{
|
||||||
$friends = array();
|
$friends = array();
|
||||||
|
|
||||||
|
@ -192,8 +193,14 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
|
||||||
return $friends;
|
return $friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscribeTwitterFriends($flink)
|
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);
|
$friends = $this->fetchTwitterFriends($flink);
|
||||||
|
|
||||||
if (empty($friends)) {
|
if (empty($friends)) {
|
||||||
|
@ -203,8 +210,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$profile = $flink->getProfile();
|
|
||||||
|
|
||||||
foreach ($friends as $friend) {
|
foreach ($friends as $friend) {
|
||||||
|
|
||||||
$friend_name = $friend->screen_name;
|
$friend_name = $friend->screen_name;
|
||||||
|
@ -219,24 +224,19 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if there's a related local user
|
// Check to see if there's a related local user and try to subscribe
|
||||||
|
try {
|
||||||
$friend_flink = Foreign_link::getByForeignID($friend_id,
|
$friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE);
|
||||||
TWITTER_SERVICE);
|
|
||||||
|
|
||||||
if (!empty($friend_flink)) {
|
|
||||||
|
|
||||||
// Get associated user and subscribe her
|
// Get associated user and subscribe her
|
||||||
|
$friend_profile = $friend_flink->getProfile();
|
||||||
|
|
||||||
$friend_profile = Profile::getKV('id', $friend_flink->user_id);
|
|
||||||
|
|
||||||
if ($friend_profile instanceof Profile) {
|
|
||||||
try {
|
|
||||||
$other = Profile::getKV('id', $invites->user_id);
|
|
||||||
Subscription::start($profile, $friend_profile);
|
Subscription::start($profile, $friend_profile);
|
||||||
common_log(LOG_INFO,
|
common_log(LOG_INFO,
|
||||||
$this->name() . ' - Subscribed ' .
|
$this->name() . ' - Subscribed ' .
|
||||||
"{$friend_profile->nickname} to {$profile->nickname}.");
|
"{$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) {
|
} catch (Exception $e) {
|
||||||
common_debug($this->name() .
|
common_debug($this->name() .
|
||||||
' - Tried and failed subscribing ' .
|
' - Tried and failed subscribing ' .
|
||||||
|
@ -244,8 +244,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
|
||||||
$e->getMessage());
|
$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
|
||||||
return $flinks;
|
return $flinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: make it so we can force a Foreign_link here without colliding with parent
|
||||||
function childTask($flink) {
|
function childTask($flink) {
|
||||||
// Each child ps needs its own DB connection
|
// Each child ps needs its own DB connection
|
||||||
|
|
||||||
|
@ -149,14 +150,8 @@ class TwitterStatusFetcher extends ParallelizingDaemon
|
||||||
unset($_DB_DATAOBJECT['CONNECTIONS']);
|
unset($_DB_DATAOBJECT['CONNECTIONS']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimeline($flink, $timelineUri = 'home_timeline')
|
function getTimeline(Foreign_link $flink, $timelineUri = 'home_timeline')
|
||||||
{
|
{
|
||||||
if (empty($flink)) {
|
|
||||||
common_log(LOG_ERR, $this->name() .
|
|
||||||
" - Can't retrieve Foreign_link for foreign ID $fid");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
common_log(LOG_DEBUG, $this->name() . ' - Trying to get ' . $timelineUri .
|
common_log(LOG_DEBUG, $this->name() . ' - Trying to get ' . $timelineUri .
|
||||||
' timeline for Twitter user ' . $flink->foreign_id);
|
' timeline for Twitter user ' . $flink->foreign_id);
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,8 @@ class TweetInQueueHandler extends QueueHandler
|
||||||
$importer = new TwitterImport();
|
$importer = new TwitterImport();
|
||||||
$notice = $importer->importStatus($status);
|
$notice = $importer->importStatus($status);
|
||||||
if ($notice instanceof Notice) {
|
if ($notice instanceof Notice) {
|
||||||
|
try {
|
||||||
$flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE);
|
$flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE);
|
||||||
if ($flink instanceof Foreign_link) {
|
|
||||||
common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice ".
|
common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice ".
|
||||||
$notice->id." to attentions for user ".$flink->user_id);
|
$notice->id." to attentions for user ".$flink->user_id);
|
||||||
try {
|
try {
|
||||||
|
@ -63,7 +63,7 @@ class TweetInQueueHandler extends QueueHandler
|
||||||
common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " .
|
common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " .
|
||||||
$e->getMessage());
|
$e->getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} catch (NoResultException $e) {
|
||||||
common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user ".$receiver);
|
common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user ".$receiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,17 +542,17 @@ class TwitterImport
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($status->entities->user_mentions as $mention) {
|
foreach ($status->entities->user_mentions as $mention) {
|
||||||
|
try {
|
||||||
$flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE);
|
$flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE);
|
||||||
if (!empty($flink)) {
|
$user = $flink->getUser();
|
||||||
$user = User::getKV('id', $flink->user_id);
|
|
||||||
if (!empty($user)) {
|
|
||||||
$reply = new Reply();
|
$reply = new Reply();
|
||||||
$reply->notice_id = $notice->id;
|
$reply->notice_id = $notice->id;
|
||||||
$reply->profile_id = $user->id;
|
$reply->profile_id = $user->id;
|
||||||
$reply->modified = $notice->created;
|
$reply->modified = $notice->created;
|
||||||
common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}");
|
common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}");
|
||||||
$id = $reply->insert();
|
$id = $reply->insert();
|
||||||
}
|
} catch (NoResultException $e) {
|
||||||
|
common_log(LOG_WARNING, 'No local user found for Foreign_link with local User id: '.$flink->user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,12 +62,7 @@ if (have_option('n')) {
|
||||||
*/
|
*/
|
||||||
function twitterAuthForUser(User $user)
|
function twitterAuthForUser(User $user)
|
||||||
{
|
{
|
||||||
$flink = Foreign_link::getByUserID($user->id,
|
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
|
||||||
TWITTER_SERVICE);
|
|
||||||
if (!$flink) {
|
|
||||||
throw new ServerException("No Twitter config for this user.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
throw new ServerException("No Twitter OAuth credentials for this user.");
|
throw new ServerException("No Twitter OAuth credentials for this user.");
|
||||||
|
|
|
@ -63,12 +63,7 @@ if (have_option('n')) {
|
||||||
*/
|
*/
|
||||||
function twitterAuthForUser(User $user)
|
function twitterAuthForUser(User $user)
|
||||||
{
|
{
|
||||||
$flink = Foreign_link::getByUserID($user->id,
|
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
|
||||||
TWITTER_SERVICE);
|
|
||||||
if (!$flink) {
|
|
||||||
throw new ServerException("No Twitter config for this user.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
throw new ServerException("No Twitter OAuth credentials for this user.");
|
throw new ServerException("No Twitter OAuth credentials for this user.");
|
||||||
|
|
|
@ -181,11 +181,15 @@ function twitter_id($status, $field='id')
|
||||||
*/
|
*/
|
||||||
function broadcast_twitter($notice)
|
function broadcast_twitter($notice)
|
||||||
{
|
{
|
||||||
$flink = Foreign_link::getByUserID($notice->profile_id,
|
try {
|
||||||
TWITTER_SERVICE);
|
$flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE);
|
||||||
|
} catch (NoResultException $e) {
|
||||||
|
// Alright so don't broadcast it then! (since there's no foreign link)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't bother with basic auth, since it's no longer allowed
|
// Don't bother with basic auth, since it's no longer allowed
|
||||||
if (!empty($flink) && TwitterOAuthClient::isPackedToken($flink->credentials)) {
|
if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
|
||||||
if (is_twitter_bound($notice, $flink)) {
|
if (is_twitter_bound($notice, $flink)) {
|
||||||
if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) {
|
if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) {
|
||||||
$retweet = retweet_notice($flink, Notice::getKV('id', $notice->repeat_of));
|
$retweet = retweet_notice($flink, Notice::getKV('id', $notice->repeat_of));
|
||||||
|
@ -273,8 +277,13 @@ function twitter_update_params($notice)
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
function broadcast_oauth($notice, $flink) {
|
function broadcast_oauth($notice, Foreign_link $flink) {
|
||||||
|
try {
|
||||||
$user = $flink->getUser();
|
$user = $flink->getUser();
|
||||||
|
} catch (ServerException $e) {
|
||||||
|
common_log(LOG_WARNING, 'Discarding broadcast_oauth for notice '.$notice->id.' because of exception: '.$e->getMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$statustxt = format_status($notice);
|
$statustxt = format_status($notice);
|
||||||
$params = twitter_update_params($notice);
|
$params = twitter_update_params($notice);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user