X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2FTwitterBridge%2Fdaemons%2Fsynctwitterfriends.php;h=fd7f9c28f1242a48042cb8f930b01dfc978b6d46;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hp=38a8b89ebb815acbd6147bba088f242c58a63dc2;hpb=ba6538ed78df3049fa59aed0855b0e3af54c994f;p=quix0rs-gnu-social.git diff --git a/plugins/TwitterBridge/daemons/synctwitterfriends.php b/plugins/TwitterBridge/daemons/synctwitterfriends.php old mode 100755 new mode 100644 index 38a8b89ebb..fd7f9c28f1 --- a/plugins/TwitterBridge/daemons/synctwitterfriends.php +++ b/plugins/TwitterBridge/daemons/synctwitterfriends.php @@ -30,10 +30,8 @@ Batch script for synching local friends with Twitter friends. END_OF_TRIM_HELP; -require_once INSTALLDIR . '/scripts/commandline.inc'; -require_once INSTALLDIR . '/lib/parallelizingdaemon.php'; -require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; -require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; +require_once INSTALLDIR . '/scripts/commandline.inc.php'; +require_once dirname(__DIR__) . '/twitter.php'; /** * Daemon to sync local friends with Twitter friends @@ -106,6 +104,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon return $flinks; } + // FIXME: make it so we can force a Foreign_link here without colliding with parent function childTask($flink) { // Each child ps needs its own DB connection @@ -126,7 +125,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon unset($_DB_DATAOBJECT['CONNECTIONS']); } - function fetchTwitterFriends($flink) + function fetchTwitterFriends(Foreign_link $flink) { $friends = array(); @@ -185,15 +184,23 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon "of Twitter user $flink->foreign_id friends."); continue; } else { - $friends = array_merge($friends, $more_friends); + if (is_array($more_friends)) { + $friends = array_merge($friends, $more_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); if (empty($friends)) { @@ -203,8 +210,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon return false; } - $user = $flink->getUser(); - foreach ($friends as $friend) { $friend_name = $friend->screen_name; @@ -219,31 +224,24 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon continue; } - // Check to see if there's a related local user - - $friend_flink = Foreign_link::getByForeignID($friend_id, - TWITTER_SERVICE); - - if (!empty($friend_flink)) { + // 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_user = User::staticGet('id', $friend_flink->user_id); - - if (!empty($friend_user)) { - $result = subs_subscribe_to($user, $friend_user); - - if ($result === true) { - common_log(LOG_INFO, - $this->name() . ' - Subscribed ' . - "$friend_user->nickname to $user->nickname."); - } else { - common_debug($this->name() . - ' - Tried subscribing ' . - "$friend_user->nickname to $user->nickname - " . - $result); - } - } + $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()); } }