X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FTwitterBridge%2Fdaemons%2Fsynctwitterfriends.php;h=a3862eedfde45e9fcd67da1aa4101cb71b8fd87a;hb=74d4e2fa10f8dc5bbe2b8a6298d0b8ddf5eecb02;hp=671e3c7afa35cb721a8195aadcc2953fd414dbca;hpb=a2b830392597d88c435baf54ad0df4ecda02dc41;p=quix0rs-gnu-social.git diff --git a/plugins/TwitterBridge/daemons/synctwitterfriends.php b/plugins/TwitterBridge/daemons/synctwitterfriends.php index 671e3c7afa..a3862eedfd 100755 --- a/plugins/TwitterBridge/daemons/synctwitterfriends.php +++ b/plugins/TwitterBridge/daemons/synctwitterfriends.php @@ -31,10 +31,7 @@ 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/twitterbasicauthclient.php'; -require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; +require_once dirname(__DIR__) . '/twitter.php'; /** * Daemon to sync local friends with Twitter friends @@ -46,7 +43,6 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - class SyncTwitterFriendsDaemon extends ParallelizingDaemon { /** @@ -60,7 +56,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon * @return void * **/ - function __construct($id = null, $interval = 60, $max_children = 2, $debug = null) { @@ -72,7 +67,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon * * @return string Name of the daemon. */ - function name() { return ('synctwitterfriends.' . $this->_id); @@ -111,12 +105,10 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon } function childTask($flink) { - // Each child ps needs its own DB connection // Note: DataObject::getDatabaseConnection() creates // a new connection if there isn't one already - $conn = &$flink->getDatabaseConnection(); $this->subscribeTwitterFriends($flink); @@ -128,7 +120,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon // XXX: Couldn't find a less brutal way to blow // away a cached connection - global $_DB_DATAOBJECT; unset($_DB_DATAOBJECT['CONNECTIONS']); } @@ -144,8 +135,8 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon $client = new TwitterOAuthClient($token->key, $token->secret); common_debug($this->name() . '- Grabbing friends IDs with OAuth.'); } else { - $client = new TwitterBasicAuthClient($flink); - common_debug($this->name() . '- Grabbing friends IDs with basic auth.'); + common_debug("Skipping Twitter friends for {$flink->user_id} since not OAuth."); + return $friends; } try { @@ -192,7 +183,9 @@ 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); + } } } @@ -210,7 +203,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon return false; } - $user = $flink->getUser(); + $profile = $flink->getProfile(); foreach ($friends as $friend) { @@ -221,7 +214,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon // Twitter friend if (!save_twitter_user($friend_id, $friend_name)) { - common_log(LOG_WARNING, $this-name() . + common_log(LOG_WARNING, $this->name() . " - Couldn't save $screen_name's friend, $friend_name."); continue; } @@ -235,20 +228,20 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon // Get associated user and subscribe her - $friend_user = User::staticGet('id', $friend_flink->user_id); + $friend_profile = Profile::getKV('id', $friend_flink->user_id); - if (!empty($friend_user)) { - $result = subs_subscribe_to($user, $friend_user); - - if ($result === true) { + if ($friend_profile instanceof Profile) { + try { + $other = Profile::getKV('id', $invites->user_id); + Subscription::start($profile, $friend_profile); common_log(LOG_INFO, $this->name() . ' - Subscribed ' . - "$friend_user->nickname to $user->nickname."); - } else { + "{$friend_profile->nickname} to {$profile->nickname}."); + } catch (Exception $e) { common_debug($this->name() . - ' - Tried subscribing ' . - "$friend_user->nickname to $user->nickname - " . - $result); + ' - Tried and failed subscribing ' . + "{$friend_profile->nickname} to {$profile->nickname} - " . + $e->getMessage()); } } } @@ -278,4 +271,3 @@ if (have_option('d') || have_option('debug')) { $syncer = new SyncTwitterFriendsDaemon($id, 60, 2, $debug); $syncer->runOnce(); -