]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/daemons/twitterstatusfetcher.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / TwitterBridge / daemons / twitterstatusfetcher.php
old mode 100755 (executable)
new mode 100644 (file)
index f86007b..fd3b576
@@ -23,7 +23,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
 // Tune number of processes and how often to poll Twitter
 // XXX: Should these things be in config.php?
 define('MAXCHILDREN', 2);
-define('POLL_INTERVAL', 60); // in seconds
+define('POLL_INTERVAL', 70); // in seconds, Twitter API v1.1 says 15 calls every 15 mins
 
 $shortoptions = 'di::';
 $longoptions = array('id::', 'debug');
@@ -36,11 +36,10 @@ Batch script for retrieving Twitter messages from foreign service.
 
 END_OF_TRIM_HELP;
 
-require_once INSTALLDIR . '/scripts/commandline.inc';
+require_once INSTALLDIR . '/scripts/commandline.inc.php';
 require_once INSTALLDIR . '/lib/common.php';
 require_once INSTALLDIR . '/lib/daemon.php';
-require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
-require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
+require_once dirname(__DIR__) . '/twitter.php';
 
 /**
  * Fetch statuses from Twitter
@@ -129,6 +128,7 @@ class TwitterStatusFetcher 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
 
@@ -137,7 +137,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         $conn = &$flink->getDatabaseConnection();
 
         $this->getTimeline($flink, 'home_timeline');
-        $this->getTimeline($flink, 'mentions');
+        $this->getTimeline($flink, 'mentions_timeline');
 
         $flink->last_friendsync = common_sql_now();
         $flink->update();
@@ -150,14 +150,8 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         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 .
                    ' timeline for Twitter user ' . $flink->foreign_id);
 
@@ -166,7 +160,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
             $token = TwitterOAuthClient::unpackToken($flink->credentials);
             $client = new TwitterOAuthClient($token->key, $token->secret);
-            common_log(LOG_DEBUG, $this->name() . ' - Grabbing ' . $timelineUri . ' timeline with OAuth.');
+            common_debug($this->name() . ' - Grabbing ' . $timelineUri . ' timeline with OAuth.');
         } else {
             common_log(LOG_ERR, "Skipping " . $timelineUri . " timeline for " .
                        $flink->foreign_id . " since not OAuth.");
@@ -176,7 +170,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
 
         $lastId = Twitter_synch_status::getLastId($flink->foreign_id, $timelineUri);
 
-        common_log(LOG_DEBUG, "Got lastId value '" . $lastId . "' for foreign id '" .
+        common_debug("Got lastId value '" . $lastId . "' for foreign id '" .
                      $flink->foreign_id . "' and timeline '" . $timelineUri. "'");
 
         try {
@@ -188,7 +182,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         }
 
         if (empty($timeline)) {
-            common_log(LOG_WARNING, $this->name() .  " - Empty '" . $timelineUri . "' timeline.");
+            common_log(LOG_DEBUG, $this->name() .  " - Empty '" . $timelineUri . "' timeline.");
             return;
         }
 
@@ -196,26 +190,18 @@ class TwitterStatusFetcher extends ParallelizingDaemon
                    ' - Retrieved ' . sizeof($timeline) . ' statuses from ' . $timelineUri . ' timeline' .
                    ' - for user ' . $flink->user_id);
 
-        /* @fixme make TwitterBridge use queueing system
-         *        to speed up timeline processing
-         *        as well as giving oportunity to use
-         *        usefull feature such as realtime
-         *        brodcast to clients
-         */
-        $importer = new TwitterImport();
-
-        // Reverse to preserve order
-
-        foreach (array_reverse($timeline) as $status) {
-            $notice = $importer->importStatus($status);
-
-            if (!empty($notice)) {
-                Inbox::insertNotice($flink->user_id, $notice->id);
+        if (!empty($timeline)) {
+            $qm = QueueManager::get();
+
+            // Reverse to preserve order
+            foreach (array_reverse($timeline) as $status) {
+                $data = array(
+                    'status' => $status,
+                    'for_user' => $flink->foreign_id,
+                );
+                $qm->enqueue($data, 'tweetin');
             }
-        }
-        /* @fixme ends here */
 
-        if (!empty($timeline)) {
             $lastId = twitter_id($timeline[0]);
             Twitter_synch_status::setLastId($flink->foreign_id, $timelineUri, $lastId);
             common_debug("Set lastId value '$lastId' for foreign id '{$flink->foreign_id}' and timeline '" .