File: /var/www/innodrive/migrations/migrate_at.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/import/class/Product.php');
$products = $wpdb->get_results(' SELECT * FROM products WHERE brand_id = 2');
foreach($products as $product ) {
$groups = json_decode($product->group, true);
foreach($groups as $groupName => $group) {
foreach($group as $name => $dimention) {
if (in_array($name, ['Link to current image', 'a thumbnail image', 'Downloads (links)'])) {
unset($groups[$groupName][$name]);
}
}
}
Product::update([
'group' => json_encode($groups)
], $product->id);
echo $product->title . ': updated' . PHP_EOL;
}
echo PHP_EOL . 'Done';