New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent unexpected missed schedules when generating new posts #418
Merged
danielbachhuber
merged 11 commits into
wp-cli:main
from
rafaelzaleski:fix/268-generate-posts-create-scheduled-posts
Sep 18, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6596e92
Use default wp_insert_post behavior on post_date
rafaelzaleski 5e2aea5
Add test case
rafaelzaleski c28bedf
Fix hyphenated dates
rafaelzaleski e529043
Fix coding style
rafaelzaleski f6d53df
Fix cs errors
rafaelzaleski 83b9db9
Assign a value to the post date if it is empty.
rafaelzaleski 26e64cb
Replace isset for empty in value checks
rafaelzaleski 2446ecd
Add fix for only date.
rafaelzaleski 0040988
Add time to date if empty
rafaelzaleski 5a61aeb
Add comments and fix PHP CS
rafaelzaleski 0c1a185
Remove whitespace EOL
rafaelzaleski File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new behavior? Can you share more detail about it? It seems like a new behavior to me, and a different change than the original issue describes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's actually done to ensure compatibility with previous versions. The docs advises using a datetime string with a hyphen between the date and time. If we don't remove this hyphen before calling
wp_insert_post
, the timestamp will be saved as 0.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelzaleski Ok, great. Can you include some additional tests to capture this behavior then?
Also, it looks like your test introduces one break in a different test...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already here and here.
I'm not sure how to reproduce it locally. Do you have any ideas? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to get tests running against PHP 5.6 locally and failed 😕
First, I tried this act tool. It was able to run the unit tests but not the functional tests:
I think this is the specific failure:
Next, I tried to install PHP 5.6 directly on my machine:
Something is funky with the tests, though:
I then manually tried to install WordPress 3.7, but received this MySQL error:
My guess is that something changed in the behavior of
wp_insert_post()
between WP 3.7 and today.Based on the failed test, it looks like your code changes the result of
--post_date="2018-07-01"`` from
2018-07-01 00:00:00to
1970-01-01 00:00:00`There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @danielbachhuber. I think I was able to fix the edge cases on WP 3.7 and I have requested a new review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelzaleski Out of curiosity, how did you end up debugging/fixing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I encountered some challenges installing
3.7
locally too, mainly because of database issues.So I went through the failed test data and reviewed the
wp_insert_post
source code from tag3.7
. This helped me understand the nuances of the test data processing and the root cause of the failures.To ensure the solutions were working, I validated them using CI checks on my cloned repository.