]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/daemons/synctwitterfriends.php
TwitterBridge: don't array_merge() non-arrays
[quix0rs-gnu-social.git] / plugins / TwitterBridge / daemons / synctwitterfriends.php
index 02546a02cad93538d11ecb3d4ffb5d14c3952aa9..a3862eedfde45e9fcd67da1aa4101cb71b8fd87a 100755 (executable)
@@ -31,9 +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/twitteroauthclient.php';
+require_once dirname(__DIR__) . '/twitter.php';
 
 /**
  * Daemon to sync local friends with Twitter friends
@@ -45,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
 {
     /**
@@ -59,7 +56,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
      * @return void
      *
      **/
-
     function __construct($id = null, $interval = 60,
                          $max_children = 2, $debug = null)
     {
@@ -71,7 +67,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
      *
      * @return string Name of the daemon.
      */
-
     function name()
     {
         return ('synctwitterfriends.' . $this->_id);
@@ -110,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);
@@ -127,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']);
     }
@@ -191,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);
+                }
             }
         }
 
@@ -209,7 +203,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
             return false;
         }
 
-        $user = $flink->getUser();
+        $profile = $flink->getProfile();
 
         foreach ($friends as $friend) {
 
@@ -234,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());
                     }
                 }
             }
@@ -277,4 +271,3 @@ if (have_option('d') || have_option('debug')) {
 
 $syncer = new SyncTwitterFriendsDaemon($id, 60, 2, $debug);
 $syncer->runOnce();
-