Last active
April 16, 2025 10:54
-
-
Save bor0/636e86637fd848313205276879bb582a to your computer and use it in GitHub Desktop.
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 | |
function get_product_ids() { | |
$output = shell_exec( "vip wp -a woocommerce -e staging -y -- db query \"SELECT id FROM wp_posts WHERE post_type = 'product' AND post_status = 'publish'\" --skip-column-names" ); | |
$output = str_replace( array( '|', '-', '+' ), '', $output ); | |
$lines = explode( "\n", trim( $output ) ); | |
return array_map( 'intval', array_filter( $lines ) ); | |
} | |
function generate_scripts( $ids, $chunks = 2 ) { | |
$ids = array_chunk( $ids, $chunks ); | |
foreach ( $ids as $index => $chunk ) { | |
$data = "#!/bin/bash\n"; | |
$data .= "set -x\n"; | |
foreach ( $chunk as $id ) { | |
$data .= sprintf( "vip wp -a woocommerce -e staging -y -- wccom ai-utilities generate_product_features %d\n", $id ); | |
$data .= sprintf( "vip wp -a woocommerce -e staging -y -- wccom ai-utilities generate_search_keywords %d\n", $id ); | |
$data .= sprintf( "vip wp -a woocommerce -e staging -y -- wccom ai-utilities generate_product_compatibility %d\n", $id ); | |
} | |
$filename = __FILE__ . '_part_' . $index . '.sh'; | |
if ( file_put_contents( $filename, $data ) ) { | |
printf( "Written to file '%s'\n", $filename ); | |
} else { | |
printf( "Error outputting to file '%s', aborting\n", $filename ); | |
exit(); | |
} | |
} | |
} | |
$chunks = 331; // For 1324/1291 staging/prod products, this generates about 4 parallel processes, which works fine against VIP limitations | |
$ids = get_product_ids(); | |
printf( "Found %d products. With the current setting, this will generate approximately %d parallel processes\n", count( $ids ), ceil( count( $ids ) / $chunks ) ); | |
generate_scripts( $ids, $chunks ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment