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
* @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
{
/**
* @return void
*
**/
-
function __construct($id = null, $interval = 60,
$max_children = 2, $debug = null)
{
*
* @return string Name of the daemon.
*/
-
function name()
{
return ('synctwitterfriends.' . $this->_id);
}
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);
// XXX: Couldn't find a less brutal way to blow
// away a cached connection
-
global $_DB_DATAOBJECT;
unset($_DB_DATAOBJECT['CONNECTIONS']);
}
"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 false;
}
- $user = $flink->getUser();
+ $profile = $flink->getProfile();
foreach ($friends as $friend) {
// 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());
}
}
}
$syncer = new SyncTwitterFriendsDaemon($id, 60, 2, $debug);
$syncer->runOnce();
-