/** * 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__); } } }
function testUpdate() { $dao = new FollowDAO($this->db, $this->logger); $this->assertTrue(!$dao->update(12, 13)); $this->assertTrue($dao->update(13, 12)); }
function cleanUpFollows() { $fd = new FollowDAO($this->db, $this->logger); $continue_fetching = true; while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching) { $oldfollow = $fd->getOldestFollow(); $friendship_call = $this->api->cURL_source['show_friendship']; $args = array(); $args["source_id"] = $oldfollow["followee_id"]; $args["target_id"] = $oldfollow["follower_id"]; list($cURL_status, $twitter_data) = $this->api->apiRequest($friendship_call, $this->logger, $args); if ($cURL_status == 200) { try { $friendship = $this->api->parseXML($twitter_data); if ($friendship['source_follows_target'] == 'true') { $fd->update($oldfollow["followee_id"], $oldfollow["follower_id"]); } else { $fd->deactivate($oldfollow["followee_id"], $oldfollow["follower_id"]); } if ($friendship['target_follows_source'] == 'true') { $fd->update($oldfollow["follower_id"], $oldfollow["followee_id"]); } else { $fd->deactivate($oldfollow["follower_id"], $oldfollow["followee_id"]); } } catch (Exception $e) { $status_message = 'Could not parse friendship XML'; } } else { $continue_fetching = false; } } }
/** * 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__); } } }