-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Handle bad interval for cron schedule #10619
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
base: trunk
Are you sure you want to change the base?
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…into trac-64404
src/wp-includes/cron.php
Outdated
| __( 'Event schedule does not exist.' ) | ||
| sprintf( | ||
| /* translators: %s is the interval encoded as JSON */ | ||
| __( 'Event schedule is invalid. Interval must be positive integer, but got: %s' ), |
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.
Maybe the $recurrence should be included here as well?
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 think this would be good if a named schedule is used, ie if the code doesn't fall back to
wordpress-develop/src/wp-includes/cron.php
Lines 361 to 368 in 8b0250c
| // Now we try to get it from the saved interval in case the schedule disappears. | |
| if ( 0 === $interval ) { | |
| $scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp ); | |
| if ( $scheduled_event && isset( $scheduled_event->interval ) ) { | |
| $interval = $scheduled_event->interval; | |
| } | |
| } |
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.
Not like 063c21e?
peterwilsoncc
left a comment
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've added a few notes inline.
src/wp-includes/cron.php
Outdated
|
|
||
| // Now we assume something is wrong and fail to schedule. | ||
| if ( 0 === $interval ) { | ||
| if ( ! is_int( $interval ) || $interval <= 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.
| if ( ! is_int( $interval ) || $interval <= 0 ) { | |
| if ( ! is_numeric( $interval ) || $interval <= 0 ) { |
Matches the behaivour of the existing check in wp_schedule_event()
src/wp-includes/cron.php
Outdated
| __( 'Event schedule does not exist.' ) | ||
| sprintf( | ||
| /* translators: %s is the interval encoded as JSON */ | ||
| __( 'Event schedule is invalid. Interval must be positive integer, but got: %s' ), |
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 think this would be good if a named schedule is used, ie if the code doesn't fall back to
wordpress-develop/src/wp-includes/cron.php
Lines 361 to 368 in 8b0250c
| // Now we try to get it from the saved interval in case the schedule disappears. | |
| if ( 0 === $interval ) { | |
| $scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp ); | |
| if ( $scheduled_event && isset( $scheduled_event->interval ) ) { | |
| $interval = $scheduled_event->interval; | |
| } | |
| } |
…into trac-64404
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
|
There's a failing test: |
src/wp-includes/cron.php
Outdated
| __( 'Event schedule with recurrence "%$1s" does not exist or has is invalid. Interval must be positive integer, but got: %$2s' ), | ||
| $recurrence, | ||
| wp_json_encode( $interval ) | ||
| ) |
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 took me a couple of reads to understand what this is trying to tell me. The interval is an internal implementation detail that's not used by anyone calling this function, so I'm not sure it's an actionable message.
Is it possible to reliably distinguish between a schedule that doesn't exist and a schedule that exists but has an invalid interval? If so, let's use two separate error messages, one for each case, then make each error message clearer.
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.
How about c6efb67?
…into trac-64404
Co-authored-by: John Blackbourn <[email protected]>
… wp_reschedule_event() Co-authored-by: John Blackbourn <[email protected]>
Trac ticket: https://core.trac.wordpress.org/ticket/64404
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.