rows_affected // return contract is verified by AtomicCasTest.php. /** * Atomically mark an auth-code row as completed IF it is not already completed. * * @since 0.1.0 * @param int $id Auth-log row primary key. * @param string $now Current timestamp (mysql format, GMT). * @return bool True iff exactly this call redeemed the row (rows_affected = 1). */ public function redeem_atomic( int $id, string $now ): bool { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( $wpdb->prepare( 'UPDATE %i SET completed_at = %s, status = %s WHERE id = %d AND completed_at IS NULL', $wpdb->prefix . 'acrossai_mcp_cli_auth_logs', $now, 'completed', $id ) ); return 1 === (int) $wpdb->rows_affected; } /** * Bulk delete expired OAuth auth-code rows for the FR-019c retention cron. * * @since 0.1.0 * @param string $cutoff Datetime string (mysql format, GMT). Rows created before this are deleted. * @return int Number of rows deleted. */ public function delete_expired_oauth_codes( string $cutoff ): int { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE created_at < %s AND completed_at IS NULL', $wpdb->prefix . 'acrossai_mcp_cli_auth_logs', $cutoff ) ); return is_int( $result ) ? $result : 0; } }