Skip to content

Commit

Permalink
Replace one year ago query with PostDAO::getOnThisDayFlashbackPosts
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Jun 18, 2012
1 parent 1a64cee commit cfffa73
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
42 changes: 35 additions & 7 deletions tests/TestOfPostMySQLDAO.php
Expand Up @@ -2831,7 +2831,7 @@ public function testUpdatePostText() {
$this->assertEqual($post->post_text, 'This is updated post 10');
}

public function testGetAllPostsFromThisDayYearAgo(){
public function testGetOnThisDayFlashbackPosts(){
// Generate the date string for 1 year ago today
$year_ago_date = date(date( 'Y-m-d H:i:s' , strtotime("today -1 year")));

Expand All @@ -2848,6 +2848,35 @@ public function testGetAllPostsFromThisDayYearAgo(){
// Add a link for this post
$link_builder = FixtureBuilder::build('links', array('post_key'=>$post_key, 'url'=>'http://bit.ly/blah'));

// Add a post from 2 years ago that's not a reply or retweet
$two_years_ago_date = date(date( 'Y-m-d H:i:s' , strtotime("today -2 year")));
$post_builder2 = FixtureBuilder::build('posts', array('post_id'=>'149', 'author_user_id'=>'20',
'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>$two_years_ago_date, 'location'=>'England',
'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Park', 'place_id'=>'12345a',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
'in_reply_to_user_id' =>null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id'=>null,
'geo'=>'52.477192843264,-1.484333726346'));

$post_key = $post_builder2->columns['last_insert_id'];
// Add a link for this post
$link_builder2 = FixtureBuilder::build('links', array('post_key'=>$post_key, 'url'=>'http://bit.ly/blahb'));

// Add a post from today that's not a reply or retweet
$today_date = date(date( 'Y-m-d H:i:s' , strtotime("today")));

$post_builder3 = FixtureBuilder::build('posts', array('post_id'=>'150', 'author_user_id'=>'20',
'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>$today_date, 'location'=>'England',
'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Park', 'place_id'=>'12345a',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
'in_reply_to_user_id' =>null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id'=>null,
'geo'=>'52.477192843264,-1.484333726346'));

$post_key = $post_builder3->columns['last_insert_id'];
// Add a link for this post
$link_builder3 = FixtureBuilder::build('links', array('post_key'=>$post_key, 'url'=>'http://bit.ly/blahb'));

/* Add the place information for future foursquare checkin test (We do it this way due to the fixture builder
not being able to handle the MySQL point type
// Set all possible fields
Expand Down Expand Up @@ -2883,12 +2912,11 @@ public function testGetAllPostsFromThisDayYearAgo(){
// Query the database for last year's post
$post_dao = new PostMySQLDAO();
// Get the year to query for
$query_year = date(date( 'Y' , strtotime("today -1 year")));
$res = $post_dao->getPostsFromThisDayThatYear(20, 'foursquare', $query_year);
$res = $post_dao->getOnThisDayFlashbackPosts(20, 'foursquare');

//print_r($res);
$this->debug(Utils::varDumpToString($res));
// Check only the 1 checkin we inserted is returned
$this->assertEqual(sizeof($res), 1);
$this->assertEqual(sizeof($res), 2);
// Check the author user id was set correctly
$this->assertEqual($res[0]->author_user_id, '20');
// Check the username was set correctly
Expand All @@ -2900,7 +2928,7 @@ public function testGetAllPostsFromThisDayYearAgo(){
// Check the post text was set correctly
$this->assertEqual($res[0]->post_text, 'I just checked in');
// Check the pub date was set correctly
$this->assertEqual($res[0]->pub_date, $year_ago_date);
$this->assertEqual($res[0]->pub_date, $two_years_ago_date);
// Check the location was set correctly
$this->assertEqual($res[0]->location, 'England');
// Check the place was set correctly
Expand Down Expand Up @@ -2930,6 +2958,6 @@ public function testGetAllPostsFromThisDayYearAgo(){
*/

// Check the link URL was set correctly
$this->assertEqual($res[0]->links[0]->url, 'http://bit.ly/blah');
$this->assertEqual($res[0]->links[0]->url, 'http://bit.ly/blahb');
}
}
9 changes: 4 additions & 5 deletions webapp/_lib/model/class.PostMySQLDAO.php
Expand Up @@ -1673,9 +1673,8 @@ public function updatePostText($post_id, $network, $post_text) {
return $this->getUpdateCount($ps);
}

public function getPostsFromThisDayThatYear($author_id, $network, $year, $from_date=null) {
public function getOnThisDayFlashbackPosts($author_id, $network, $from_date=null) {
$vars = array(
':year'=> $year,
':author'=> $author_id,
':network'=>$network
);
Expand All @@ -1689,8 +1688,8 @@ public function getPostsFromThisDayThatYear($author_id, $network, $year, $from_d
$q .= "pl.place_type, pl.name, pl.full_name, pl.country_code, pl.country, pl.longlat, pl.bounding_box ";
$q .= "FROM #prefix#posts po ";
$q .= "LEFT JOIN #prefix#places pl ON po.place_id = pl.place_id ";
$q .= "WHERE (YEAR(pub_date)=:year) AND ";
$q .= "(DAYOFMONTH(pub_date)=DAYOFMONTH($from_date)) AND (MONTH(pub_date)=MONTH($from_date)) AND ";
$q .= "WHERE (YEAR(pub_date)!=YEAR(CURRENT_DATE())) ";
$q .= "AND (DAYOFMONTH(pub_date)=DAYOFMONTH($from_date)) AND (MONTH(pub_date)=MONTH($from_date)) AND ";
$q .= "author_user_id=:author AND po.network=:network AND ";
$q .= "in_reply_to_post_id IS null AND in_reply_to_user_id IS NULL AND ";
$q .= "in_retweet_of_post_id IS NULL AND in_rt_of_user_id IS NULL ";
Expand Down Expand Up @@ -1721,6 +1720,6 @@ public function getPostsFromThisDayThatYear($author_id, $network, $year, $from_d
}
$all_posts[] = $post;
}
return $all_posts;
return array_reverse($all_posts);
}
}
5 changes: 2 additions & 3 deletions webapp/_lib/model/interface.PostDAO.php
Expand Up @@ -565,12 +565,11 @@ public function getPostsToUser($user_id, $network, $count = 15, $page = 1, $is_p
public function getPostsToUserIterator($user_id, $network, $count, $is_public=false);

/**
* Get posts from this day in a given year that aren't replies or reshares/retweets.
* Get posts from this day in every year except this one that aren't replies or reshares/retweets.
* @param str $author_id
* @param str $network
* @param str $year For example, '2009' or '2005'.
* @param str $from_date If not specified, defaults to current date
* @return array Post objects
*/
public function getPostsFromThisDayThatYear($author_id, $network, $year, $from_date=null);
public function getOnThisDayFlashbackPosts($author_id, $network, $from_date=null);
}

0 comments on commit cfffa73

Please sign in to comment.