/**
  * Fetch instance user friends by user IDs.
  * @param int $uid
  * @param FollowDAO $fd
  */
 private function fetchUserFriendsByIDs($uid, $fd)
 {
     $continue_fetching = true;
     $status_message = "";
     while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching) {
         $args = array();
         $friend_ids = $this->api->cURL_source['following_ids'];
         if (!isset($next_cursor)) {
             $next_cursor = -1;
         }
         $args['cursor'] = strval($next_cursor);
         $args['user_id'] = strval($uid);
         list($cURL_status, $twitter_data) = $this->api->apiRequest($friend_ids, $args);
         if ($cURL_status > 200) {
             $continue_fetching = false;
         } else {
             $status_message = "Parsing XML. ";
             $status_message .= "Cursor " . $next_cursor . ":";
             $ids = $this->api->parseXML($twitter_data);
             $next_cursor = $this->api->getNextCursor();
             $status_message .= count($ids) . " friend IDs queued to update. ";
             $this->logger->logInfo($status_message, __METHOD__ . ',' . __LINE__);
             $status_message = "";
             if (count($ids) == 0) {
                 $continue_fetching = false;
             }
             $updated_follow_count = 0;
             $inserted_follow_count = 0;
             foreach ($ids as $id) {
                 // add/update follow relationship
                 if ($fd->followExists($id['id'], $uid, 'twitter')) {
                     //update it
                     if ($fd->update($id['id'], $uid, 'twitter', Utils::getURLWithParams($friend_ids, $args))) {
                         $updated_follow_count++;
                     }
                 } else {
                     //insert it
                     if ($fd->insert($id['id'], $uid, 'twitter', Utils::getURLWithParams($friend_ids, $args))) {
                         $inserted_follow_count++;
                     }
                 }
             }
             $status_message .= "{$updated_follow_count} existing follows updated; " . $inserted_follow_count . " new follows inserted.";
             $this->logger->logUserInfo($status_message, __METHOD__ . ',' . __LINE__);
         }
     }
 }
Beispiel #2
0
 function testInsert()
 {
     $dao = new FollowDAO($this->db, $this->logger);
     $this->assertTrue($dao->insert(12, 13));
     $this->assertTrue($dao->followExists(12, 13));
 }
 function fetchInstanceUserFriends()
 {
     $fd = new FollowDAO($this->db, $this->logger);
     $this->instance->total_friends_in_system = $fd->getTotalFriends($this->owner_object->id);
     if ($this->instance->total_friends_in_system < $this->owner_object->friend_count) {
         $this->instance->is_archive_loaded_friends = false;
         $this->logger->logStatus($this->instance->total_friends_in_system . " friends in system, " . $this->owner_object->friend_count . " friends according to Twitter; Friend archive is not loaded", get_class($this));
     } else {
         $this->instance->is_archive_loaded_friends = true;
         $this->logger->logStatus("Friend archive loaded", get_class($this));
     }
     $status_message = "";
     # Fetch friend pages
     $continue_fetching = true;
     while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching && !$this->instance->is_archive_loaded_friends) {
         $friend_ids = $this->api->cURL_source['following'];
         $args = array();
         if (!isset($next_cursor)) {
             $next_cursor = -1;
         }
         $args['cursor'] = strval($next_cursor);
         list($cURL_status, $twitter_data) = $this->api->apiRequest($friend_ids, $this->logger, $args);
         if ($cURL_status > 200) {
             $continue_fetching = false;
         } else {
             try {
                 $status_message = "Parsing XML. ";
                 $status_message .= "Cursor " . $next_cursor . ":";
                 $users = $this->api->parseXML($twitter_data);
                 $next_cursor = $this->api->getNextCursor();
                 $status_message .= count($users) . " friends queued to update. ";
                 $this->logger->logStatus($status_message, get_class($this));
                 $status_message = "";
                 $updated_follow_count = 0;
                 $inserted_follow_count = 0;
                 if (count($users) == 0) {
                     $this->instance->is_archive_loaded_friends = true;
                 }
                 foreach ($users as $u) {
                     $utu = new User($u, 'Friends');
                     $this->ud->updateUser($utu, $this->logger);
                     # add/update follow relationship
                     if ($fd->followExists($utu->user_id, $this->instance->twitter_user_id)) {
                         //update it
                         if ($fd->update($utu->user_id, $this->instance->twitter_user_id)) {
                             $updated_follow_count++;
                         }
                     } else {
                         //insert it
                         if ($fd->insert($utu->user_id, $this->instance->twitter_user_id)) {
                             $inserted_follow_count++;
                         }
                     }
                 }
                 $status_message .= "{$updated_follow_count} existing friends updated; {$inserted_follow_count} new friends inserted.";
             } catch (Exception $e) {
                 $status_message = 'Could not parse friends XML for $crawler_twitter_username';
             }
             $this->logger->logStatus($status_message, get_class($this));
             $status_message = "";
         }
         $this->logger->logStatus($status_message, get_class($this));
         $status_message = "";
     }
 }
Beispiel #4
0
 /**
  * Fetch instance user friends by user IDs.
  * @param int $uid
  * @param FollowDAO $follow_dao
  */
 private function fetchUserFriendsByIDs($uid, $follow_dao)
 {
     $continue_fetching = true;
     $status_message = "";
     while ($continue_fetching) {
         $args = array();
         $endpoint = $this->api->endpoints['following_ids'];
         if (!isset($next_cursor)) {
             $next_cursor = -1;
         }
         $args['cursor'] = strval($next_cursor);
         $args['user_id'] = strval($uid);
         try {
             list($http_status, $payload) = $this->api->apiRequest($endpoint, $args);
         } catch (APICallLimitExceededException $e) {
             $this->logger->logInfo($e->getMessage(), __METHOD__ . ',' . __LINE__);
             break;
         }
         if ($http_status > 200) {
             $continue_fetching = false;
         } else {
             $status_message = "Parsing JSON. ";
             $status_message .= "Cursor " . $next_cursor . ":";
             $ids = $this->api->parseJSONIDs($payload);
             $next_cursor = $this->api->getNextCursor();
             $status_message .= count($ids) . " friend IDs queued to update. ";
             $this->logger->logInfo($status_message, __METHOD__ . ',' . __LINE__);
             $status_message = "";
             if (count($ids) == 0) {
                 $continue_fetching = false;
             }
             $updated_follow_count = 0;
             $inserted_follow_count = 0;
             foreach ($ids as $id) {
                 // add/update follow relationship
                 if ($follow_dao->followExists($id['id'], $uid, 'twitter')) {
                     //update it
                     if ($follow_dao->update($id['id'], $uid, 'twitter')) {
                         $updated_follow_count++;
                     }
                 } else {
                     //insert it
                     if ($follow_dao->insert($id['id'], $uid, 'twitter')) {
                         $inserted_follow_count++;
                     }
                 }
             }
             $status_message .= "{$updated_follow_count} existing follows updated; " . $inserted_follow_count . " new follows inserted.";
             $this->logger->logUserInfo($status_message, __METHOD__ . ',' . __LINE__);
         }
     }
 }