Created
October 22, 2021 18:45
-
-
Save devinsays/c91fa5202ba501aeccd4d7477ef4599e to your computer and use it in GitHub Desktop.
Example script that sets post_content = 'renewal' for renewal orders
This file contains hidden or 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
<?php | |
/** | |
* Flag historical renewal orders. | |
* | |
* wp eval-file flag-renewal-orders.php | |
*/ | |
global $wpdb; | |
$last_processed = (int) get_transient( 'uy_last_processed_for_flagging' ); | |
$limit_query = 10000; | |
while ( true ) { | |
WP_CLI::log( "Processing $limit_query orders above $last_processed." ); | |
$sql = "SELECT post_id FROM $wpdb->postmeta | |
WHERE post_id > $last_processed | |
AND meta_key = '_subscription_renewal' | |
ORDER BY post_id ASC | |
LIMIT $limit_query"; | |
$renewal_orders = $wpdb->get_results( $sql, ARRAY_A ); | |
if ( ! $renewal_orders ) { | |
WP_CLI::log("Finished!"); | |
break; | |
} | |
$renewal_order_ids = array_map( | |
static function ( $el ) { | |
return $el['post_id']; | |
}, | |
$renewal_orders | |
); | |
WP_CLI::log( print_r( $renewal_order_ids, true ) ); | |
$sql = "UPDATE $wpdb->posts | |
SET post_content = 'renewal' | |
WHERE ID IN (" . implode(',', $renewal_order_ids) . ")"; | |
$wpdb->get_results( $sql ); | |
$last_processed = end( $renewal_order_ids ); | |
set_transient( 'uy_last_processed_for_flagging', $last_processed, DAY_IN_SECONDS ); | |
WP_CLI::log("Set uy_last_processed_for_flagging to $last_processed. Sleeping for 3 seconds."); | |
WP_CLI::log("---"); | |
sleep(3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment