-
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
|
|
||
| // Now we try to get it from the saved interval in case the schedule disappears. | ||
| if ( 0 === $interval ) { | ||
| if ( 0 === (int) $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.
This will be true when the $interval is false. I'm not sure if that is desirable or not.
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.
When this function eventually falls through to wp_schedule_event() the following code is run:
wordpress-develop/src/wp-includes/cron.php
Lines 235 to 245 in 8b0250c
| // Make sure timestamp is a positive integer. | |
| if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { | |
| if ( $wp_error ) { | |
| return new WP_Error( | |
| 'invalid_timestamp', | |
| __( 'Event timestamp must be a valid Unix timestamp.' ) | |
| ); | |
| } | |
| return false; | |
| } |
This will change the behavior if the interval has been changed to false in wp_get_schedules() in an attempt to prevent the rescheduling of events so is probably undesirable.
| __( '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; | |
| } | |
| } |
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.
|
|
||
| // Now we try to get it from the saved interval in case the schedule disappears. | ||
| if ( 0 === $interval ) { | ||
| if ( 0 === (int) $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.
When this function eventually falls through to wp_schedule_event() the following code is run:
wordpress-develop/src/wp-includes/cron.php
Lines 235 to 245 in 8b0250c
| // Make sure timestamp is a positive integer. | |
| if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { | |
| if ( $wp_error ) { | |
| return new WP_Error( | |
| 'invalid_timestamp', | |
| __( 'Event timestamp must be a valid Unix timestamp.' ) | |
| ); | |
| } | |
| return false; | |
| } |
This will change the behavior if the interval has been changed to false in wp_get_schedules() in an attempt to prevent the rescheduling of events so is probably undesirable.
|
|
||
| // 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()
| __( '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; | |
| } | |
| } |
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.