[wp-trac] [WordPress Trac] #57271: Cron unschedule / reschedule event errors
WordPress Trac
noreply at wordpress.org
Sun Feb 16 17:47:13 UTC 2025
#57271: Cron unschedule / reschedule event errors
--------------------------------------+------------------------------
Reporter: domainsupport | Owner: audrasjb
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: 6.0
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------------
Comment (by Andy Schmidt):
Ultimately, one problem is a lack of differentiating the possible outcome
of database updates:
- WHERE matched, and value set.
- WHERE matched, and **value already set.**
- WHERE did not match.
In most situations, the third outcome would truly be "unintended" and
require error handling.
However, the **second outcome** might be "unexpected", but still perfectly
ACCEPTABLE for the subsequent program flow (after all the value still DOES
have the intended value once the UPDATE was issued).
Ideally, the WPDB class would offer an additional method/property that
returns the mysqli_info, similar to this:
{{{
if ( 1 === preg_match(
'/^(?:.+\s+)*([\w]+):\s+(\d+)\s+([\w]+):\s+(\d+)\s+([\w]+):\s+(\d+)\s*$/U',
strtolower( (string) mysqli_info( $this->dbh ) ), $matches,
PREG_UNMATCHED_AS_NULL ) ) {
$this->mysql_info = array( $matches[1] => (int) $matches[2],
$matches[3] => (int) $matches[4], $matches[5] => (int) $matches[6] );
}
}}}
This way, callers could opt to confirm
{{{
$wpdb->mysql_info['matched'] > 1
}}}
whenever mysqli_affected_rows === 0, and treat this as an acceptable
outcome.
I realize that it's unlikely that WPDB be improved - so for now, I'm
trying this patch to cron.php:
{{{
function _set_cron_array( $cron, $wp_error = false ) {
if ( ! is_array( $cron ) ) {
$cron = array();
}
$cron['version'] = 2;
$result = update_option( 'cron', $cron );
/* PATCH: Allow option_value to already contain intended value
************* */
if ( 0 === $result ) {
// Qualify why 0 rows were affected.
global $wpdb;
if ( 1 === sscanf( (string) mysqli_info( $wpdb->dbh ),
'Rows matched: %d', $mysql_matched ) and $mysql_matched > 0 )
// Rows did match; fields just had intended
content already.
return $result;
}
/* PATCH END
**************************************************************** */
if ( $wp_error && ! $result ) {
return new WP_Error(
'could_not_set',
__( 'The cron event list could not be saved.' )
);
}
return $result;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57271#comment:93>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list