File: //var/www/innodrive/migrations/migrate_programs.php
<?php
if( php_sapi_name() !== 'cli' ) {
die("Meant to be run from command line");
}
if (!empty($argv[1])) {
define('APPLICATION_ENV', $argv[1]);
} else {
define('APPLICATION_ENV', 'production');
}
define( 'BASE_PATH', './public/' );
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header, $wpdb;
require(BASE_PATH . 'wp-load.php');
require(BASE_PATH . 'wp-content/plugins/custom-search/custom-search.php');
require(BASE_PATH . 'wp-content/plugins/import/class/Product.php');
$categories = ['motor', 'gear', 'controller', 'sensor', 'accessories'];
foreach($categories as $category) {
$tableName = 'params_' . $category;
echo $category . PHP_EOL;
$productsParams = $wpdb->get_results(' SELECT * FROM ' . $tableName);
foreach($productsParams as $productParams) {
$productId = $productParams->product_id;
$subCategory = $productParams->program;
Product::replacePrograms($productId, $subCategory);
echo '|';
}
echo PHP_EOL;
}