Resolves issue #98 where if no posts exist oldest year is set to 1970… #100

Merged
merged 3 commits into from Jan 8, 2017

Projects

None yet

2 participants

@mdbitz
Contributor
mdbitz commented Jan 6, 2017

Pull requests updates logic for get_post_year_range to handle an empty db. Initially set oldest post date to current year and only update if query returns a result.

Matthew Denton Resolves issue #98 where if no posts exist oldest year is set to 1970…
…. Set the oldest year equals to the current year and updates if post_date is returned from query.
ebb4338
msm-sitemap.php
- $oldest_post_year = date( 'Y', strtotime( $oldest_post_date_gmt ) );
- $current_year = date( 'Y' );
+
+ $oldest_post_year = $current_year = date( 'Y' );
@mjangda
mjangda Jan 6, 2017 Member

Shouldn't we return false instead of the current year when there are no posts?

@mdbitz
mdbitz Jan 6, 2017 Contributor

Returning false would cause an exception to be thrown in "check_year_has_posts" as it uses the return value of get_post_years_range directly in a foreach statement. I've updated the branch in the pull request so that an empty array is returned and will play nice with existing code and return values for the function.

Thoughts?

@mjangda
mjangda Jan 6, 2017 Member

Yep, that makes sense.

msm-sitemap.php
+ $oldest_post_year = date( 'Y', strtotime( $oldest_post_date_gmt ) );
+ $current_year = date( 'Y' );
+ return range( $oldest_post_year, $current_year );
+ } else {
@mjangda
mjangda Jan 6, 2017 Member

Minor, but we can remove the else block here since the if returns.

@mjangda
Member
mjangda commented Jan 6, 2017

One small comment and I think we're good to merge.

@mdbitz
Contributor
mdbitz commented Jan 7, 2017

@mjangda > method updated with removal of else statement. Thanks.

@mjangda
Member
mjangda commented Jan 8, 2017

Nice, thanks!

@mjangda mjangda merged commit f12a8af into Automattic:master Jan 8, 2017

1 check failed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment