Example #1
0
 public function addVideo($vals)
 {
     $res = null;
     // Check all the fields we need are set
     if (self::hasAllRequiredFields($vals)) {
         // Insert the values which go into the post table
         $row_id = parent::addPost($vals);
         // If the post insertion went fine insert the values that go into the videos table
         if ($row_id != null) {
             //SQL variables to bind
             $vars = array();
             //SQL query
             $q = "INSERT IGNORE INTO #prefix#videos SET ";
             //Set up required fields
             foreach ($this->REQUIRED_VIDEO_FIELDS as $field) {
                 $q .= $field . "=:" . $field . ", ";
                 $vars[':' . $field] = $vals[$field];
             }
             // Append the internal post ID
             $q .= 'post_key=:post_key';
             $vars[':post_key'] = $row_id;
             // Try to insert the video
             if ($this->profiler_enabled) {
                 Profiler::setDAOMethod(__METHOD__);
             }
             $ps = $this->execute($q, $vars);
             $res = $this->getInsertId($ps);
         } else {
             // If the video was already in the database, update the counts
             $res = self::updateVideoCounts($vals);
         }
     }
     return $res;
 }
Example #2
0
 public function addPhoto($vals)
 {
     if (self::hasAllRequiredFields($vals)) {
         // Insert values into the post table
         $post_key = parent::addPost($vals);
         // If the post insertion went fine insert the values that go into the photos table
         if ($post_key) {
             //SQL variables to bind
             $vars = array();
             //SQL query
             $q = "INSERT IGNORE INTO #prefix#photos SET ";
             //Set up required fields
             foreach ($this->REQUIRED_PHOTO_FIELDS as $field) {
                 $q .= $field . "=:" . $field . ", ";
                 $vars[':' . $field] = $vals[$field];
             }
             //Set up any optional fields
             foreach ($this->OPTIONAL_PHOTO_FIELDS as $field) {
                 if (isset($vals[$field]) && $vals[$field] != '') {
                     $q .= $field . "=:" . $field . ", ";
                     $vars[':' . $field] = $vals[$field];
                 }
             }
             // Append the internal post ID
             $q .= 'post_key=:post_key;';
             $vars[':post_key'] = $post_key;
             // Insert the photo in the database
             if ($this->profiler_enabled) {
                 Profiler::setDAOMethod(__METHOD__);
             }
             $ps = $this->execute($q, $vars);
             $res = $this->getInsertId($ps);
             return $res;
         }
     } else {
         $status_message = "Could not insert photo ID " . $vals["post_id"] . ", missing values";
         $this->logger->logError($status_message, __METHOD__ . ',' . __LINE__);
         //doesn't have all req'd values
         return false;
     }
 }
 /**
  * Test that detection of an old-style RT for an already-stored post is properly processed
  */
 public function testCatchOldStyleRT()
 {
     $pdao = new PostMySQLDAO();
     $builders = array();
     $builders[] = FixtureBuilder::build('posts', array('id' => 5000, 'post_id' => '13708601491193856', 'author_user_id' => 100, 'author_username' => 'user100', 'retweet_count_cache' => 2, 'retweet_count_api' => 5, 'old_retweet_count_cache' => 0, 'post_text' => "People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5", 'network' => 'twitter', 'in_retweet_of_post_id' => null));
     // store an old-style RT post w/out the in_retweet_of_post_id field set.
     $builders[] = FixtureBuilder::build('posts', array('id' => 5001, 'post_id' => 12345, 'author_user_id' => 1234, 'author_username' => 'user1234', 'post_text' => "RT @user100: People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5", 'network' => 'twitter', 'in_retweet_of_post_id' => null));
     $post = $pdao->getPost(12345, 'twitter');
     $this->assertEqual($post->in_retweet_of_post_id, null);
     $post = $pdao->getPost('13708601491193856', 'twitter');
     $this->assertEqual($post->old_retweet_count_cache, 0);
     // now try adding that post again with the in_retweet_of_post_id field set.
     // the old_retweet_count_cache value of the original should be updated in
     // the process
     $vals = array();
     $vals['post_id'] = 12345;
     $vals['author_user_id'] = 1234;
     $vals['user_id'] = 1234;
     $vals['author_username'] = "******";
     $vals['user_name'] = "user1234";
     $vals['author_fullname'] = "User 1234";
     $vals['full_name'] = "User 1234";
     $vals['author_avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
     $vals['avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
     $vals['location'] = 'Austin, TX';
     $vals['description'] = 'this is a bio';
     $vals['url'] = '';
     $vals['is_protected'] = 0;
     $vals['follower_count'] = 1000;
     $vals['friend_count'] = 1000;
     $vals['post_count'] = 2000;
     $vals['joined'] = '2007-03-29 02:13:08';
     $vals['post_text'] = "RT @user100: People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5";
     $vals['pub_date'] = '2010-12-12 14:15:27';
     $vals['favorites_count'] = 1500;
     $vals['in_reply_to_post_id'] = '';
     $vals['in_reply_to_user_id'] = '';
     $vals['source'] = '<a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a>';
     $vals['geo'] = '';
     $vals['place'] = '';
     $vals['network'] = 'twitter';
     $vals['in_retweet_of_post_id'] = '13708601491193856';
     $vals['in_rt_of_user_id'] = 100;
     $pdao->addPost($vals);
     $post = $pdao->getPost(12345, 'twitter');
     $this->assertEqual($post->in_retweet_of_post_id, '13708601491193856');
     $post = $pdao->getPost('13708601491193856', 'twitter');
     $this->assertEqual($post->old_retweet_count_cache, 1);
     $this->assertEqual($post->retweet_count_cache, 2);
     // repeat, make sure no duplication now that the in_retweet_of_post_id IS set
     $pdao->addPost($vals);
     $post = $pdao->getPost('13708601491193856', 'twitter');
     $this->assertEqual($post->old_retweet_count_cache, 1);
     $this->assertEqual($post->retweet_count_cache, 2);
 }
 public function testAddRetweetOfPostByFriend()
 {
     //@ev ID 13, @shutterbug ID 18
     $builder = FixtureBuilder::build('follows', array('user_id' => 13, 'follower_id' => 18));
     //reply to shutterbug by ev
     // post id 41 is by shutterbug
     $vals['post_id'] = 1000;
     $vals['author_username'] = '******';
     $vals['author_fullname'] = "Ev Williams";
     $vals['author_avatar'] = 'avatar.jpg';
     $vals['author_user_id'] = 13;
     $vals['post_text'] = "RT @shutterbug Nice shot";
     $vals['pub_date'] = '3/1/2010';
     $vals['source'] = 'web';
     $vals['network'] = 'twitter';
     $vals['in_retweet_of_post_id'] = 41;
     $vals['is_protected'] = 0;
     $dao = new PostMySQLDAO();
     $dao->addPost($vals);
     $stmt = PostMySQLDAO::$PDO->query("select * from " . $this->prefix . 'posts where post_id=1000');
     $data = $stmt->fetch();
     $this->assertEqual($data['is_retweet_by_friend'], 1);
 }
Example #5
0
 /**
  * Test addPost
  */
 function testAddPost()
 {
     $dao = new PostMySQLDAO();
     $vals = array();
     $vals['post_id'] = 250;
     $vals['user_name'] = 'quoter';
     $vals['full_name'] = "Quoter of Quotables";
     $vals['avatar'] = 'avatar.jpg';
     //test add post without all the req'd fields set
     $this->assertEqual($dao->addPost($vals), 0, "Post not inserted, not all values set");
     $vals['user_id'] = 22;
     $vals['post_text'] = "Go confidently in the direction of your dreams! Live the life you've imagined.";
     $vals['location'] = "New Delhi";
     $vals['place'] = "Dwarka, New Delhi";
     $vals['geo'] = "10.0000 20.0000";
     $vals['pub_date'] = '3/1/2010';
     $vals['source'] = 'web';
     $vals['network'] = 'twitter';
     $vals['in_reply_to_post_id'] = '';
     //test add straight post that doesn't exist
     $this->assertEqual($dao->addPost($vals), 1, "Post inserted");
     $post = $dao->getPost(250);
     $this->assertEqual($post->post_id, 250);
     $this->assertEqual($post->author_user_id, 22);
     $this->assertEqual($post->author_username, 'quoter');
     $this->assertEqual($post->author_fullname, 'Quoter of Quotables');
     $this->assertEqual($post->author_avatar, 'avatar.jpg');
     $this->assertEqual($post->post_text, "Go confidently in the direction of your dreams! Live the life you've imagined.");
     $this->assertEqual($post->location, "New Delhi");
     $this->assertEqual($post->place, "Dwarka, New Delhi");
     $this->assertEqual($post->geo, "10.0000 20.0000");
     $this->assertEqual($post->source, 'web');
     $this->assertEqual($post->network, 'twitter');
     $this->assertEqual($post->mention_count_cache, 0);
     $this->assertEqual($post->retweet_count_cache, 0);
     $this->assertEqual($post->in_reply_to_post_id, null);
     //test add post that does exist
     $vals['post_id'] = 129;
     $this->assertEqual($dao->addPost($vals), 0, "Post exists, nothing inserted");
     //test add reply, check cache count
     $vals['post_id'] = 251;
     $vals['in_reply_to_post_id'] = 129;
     $this->assertEqual($dao->addPost($vals), 1, "Reply inserted");
     $post = $dao->getPost(129);
     $this->assertEqual($post->mention_count_cache, 1, "reply count got updated");
     //test add retweet, check cache count
     $vals['post_id'] = 252;
     $vals['in_reply_to_post_id'] = '';
     $vals['in_retweet_of_post_id'] = 128;
     $this->assertEqual($dao->addPost($vals), 1, "Retweet inserted");
     $post = $dao->getPost(128);
     $this->assertEqual($post->retweet_count_cache, 1, "retweet count got updated");
 }
 /**
  * Test RT and RT count processing.
  * in this test the API RT count is higher than the cached database count, and is maxed out at threshold.
  * This test includes 2 old-style RTs as well as native RTs.
  */
 public function testAddManyNativeRetweetsOfPost2()
 {
     $counter = 0;
     $postbase = 100000;
     $userbase = 1000;
     $dao = new PostMySQLDAO();
     while ($counter < 10) {
         $vals = array();
         $vals['post_id'] = $postbase + $counter;
         $vals['author_user_id'] = $userbase + $counter;
         $vals['user_id'] = $userbase + $counter;
         $vals['author_username'] = "******" . $userbase + $counter;
         $vals['user_name'] = "user" . $userbase + $counter;
         $vals['author_fullname'] = "User " . $userbase + $counter;
         $vals['full_name'] = "User " . $userbase + $counter;
         $vals['author_avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
         $vals['avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
         $vals['location'] = 'Austin, TX';
         $vals['description'] = 'this is a bio';
         $vals['url'] = '';
         $vals['is_protected'] = 0;
         $vals['follower_count'] = 1000;
         $vals['friend_count'] = 1000;
         $vals['post_count'] = 2000;
         $vals['joined'] = '2007-03-29 02:13:08';
         $vals['post_text'] = "RT @user100: People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5";
         $vals['pub_date'] = '2010-12-12 14:15:27';
         $vals['favorites_count'] = 1500;
         $vals['in_reply_to_post_id'] = '';
         $vals['in_reply_to_user_id'] = '';
         $vals['source'] = '<a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a>';
         $vals['geo'] = '';
         $vals['place'] = '';
         $vals['network'] = 'twitter';
         $vals['in_retweet_of_post_id'] = 13708601491193856.0;
         $vals['in_rt_of_user_id'] = 20542737;
         // for a native RT, the RT'd post info includes the original post
         $retweeted_post = array();
         $rtp = array();
         $rtp['post_id'] = 13708601491193856.0;
         $rtp['author_user_id'] = 20542737;
         $rtp['user_id'] = 20542737;
         $rtp['author_username'] = '******';
         $rtp['user_name'] = 'user100';
         $rtp['author_fullname'] = 'User 100';
         $rtp['full_name'] = 'User 100';
         $rtp['author_avatar'] = 'http://a3.twimg.com/profile_images/86835447/10947_normal.jpg';
         $rtp['avatar'] = 'http://a3.twimg.com/profile_images/86835447/10947_normal.jpg';
         $rtp['location'] = 'San Jose, CA';
         $rtp['description'] = '';
         $rtp['url'] = '';
         $rtp['is_protected'] = 0;
         $rtp['follower_count'] = 3376;
         $rtp['friend_count'] = 248;
         $rtp['post_count'] = 3681;
         $rtp['joined'] = '2009-02-10 20:30:11';
         $rtp['post_text'] = "People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5";
         $rtp['pub_date'] = '2010-12-11 21:35:59';
         $rtp['favorites_count'] = 2;
         $rtp['in_reply_to_post_id'] = '';
         $rtp['in_reply_to_user_id'] = '';
         $rtp['source'] = '<a href="http://www.tweetdeck.com" rel="nofollow">TweetDeck</a>';
         $rtp['geo'] = '';
         $rtp['place'] = '';
         $rtp['network'] = 'twitter';
         $rtp['retweet_count_api'] = 100;
         $retweeted_post['content'] = $rtp;
         $vals['retweeted_post'] = $retweeted_post;
         $dao->addPost($vals);
         $counter++;
     }
     // now add a couple of non-native RTs.
     $vals = array();
     $vals['post_id'] = $postbase + $counter;
     $vals['author_user_id'] = $userbase + $counter;
     $vals['user_id'] = $userbase + $counter;
     $vals['author_username'] = "******" . $userbase + $counter;
     $vals['user_name'] = "user" . $userbase + $counter;
     $vals['author_fullname'] = "User " . $userbase + $counter;
     $vals['full_name'] = "User " . $userbase + $counter;
     $vals['author_avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
     $vals['avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
     $vals['location'] = 'Austin, TX';
     $vals['description'] = 'this is a bio';
     $vals['url'] = '';
     $vals['is_protected'] = 0;
     $vals['follower_count'] = 1000;
     $vals['friend_count'] = 1000;
     $vals['post_count'] = 2000;
     $vals['joined'] = '2007-03-29 02:13:08';
     $vals['post_text'] = "RT @user100: People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5";
     $vals['pub_date'] = '2010-12-12 14:15:27';
     $vals['favorites_count'] = 1500;
     $vals['in_reply_to_post_id'] = '';
     $vals['in_reply_to_user_id'] = '';
     $vals['source'] = '<a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a>';
     $vals['geo'] = '';
     $vals['place'] = '';
     $vals['network'] = 'twitter';
     $vals['in_retweet_of_post_id'] = 13708601491193856.0;
     $vals['in_rt_of_user_id'] = 20542737;
     $dao->addPost($vals);
     $counter++;
     $vals = array();
     $vals['post_id'] = $postbase + $counter;
     $vals['author_user_id'] = $userbase + $counter;
     $vals['user_id'] = $userbase + $counter;
     $vals['author_username'] = "******" . $userbase + $counter;
     $vals['user_name'] = "user" . $userbase + $counter;
     $vals['author_fullname'] = "User " . $userbase + $counter;
     $vals['full_name'] = "User " . $userbase + $counter;
     $vals['author_avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
     $vals['avatar'] = 'http://a2.twimg.com/profile_images/1146326394/ears_crosshatch_normal.jpg';
     $vals['location'] = 'Austin, TX';
     $vals['description'] = 'this is a bio';
     $vals['url'] = '';
     $vals['is_protected'] = 0;
     $vals['follower_count'] = 1000;
     $vals['friend_count'] = 1000;
     $vals['post_count'] = 2000;
     $vals['joined'] = '2007-03-29 02:13:08';
     $vals['post_text'] = "RT @user100: People in non-gender typical jobs judged " . "more harshly for their mistakes. http://is.gd/izUl5";
     $vals['pub_date'] = '2010-12-12 14:15:27';
     $vals['favorites_count'] = 1500;
     $vals['in_reply_to_post_id'] = '';
     $vals['in_reply_to_user_id'] = '';
     $vals['source'] = '<a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a>';
     $vals['geo'] = '';
     $vals['place'] = '';
     $vals['network'] = 'twitter';
     $vals['in_retweet_of_post_id'] = 13708601491193856.0;
     $vals['in_rt_of_user_id'] = 20542737;
     $dao->addPost($vals);
     $counter++;
     $post = $dao->getPost(13708601491193856.0, 'twitter');
     $this->assertEqual($post->retweet_count_cache, 10);
     $this->assertEqual($post->old_retweet_count_cache, 2);
     $this->assertEqual($post->retweet_count_api, 100);
     // this is the value displayed in the UI-- the sum should be the higher reported value from twitter
     // for the native RTs, plus the old-style rt count.
     $this->assertEqual($post->all_retweets, 102);
     $this->assertEqual($post->rt_threshold, 1);
 }