File: /var/www/innodrive/migrations/migrate_status.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');
$products = $wpdb->get_results(' SELECT * FROM products');
foreach($products as $product ) {
$status = $wpdb->get_var('SELECT value FROM params WHERE product_id = ' . $product->id . ' AND name = "LebenszyklusStatus"');
switch ($status) {
case 'Coming soon':
case 'Imported':
case 'inactive':
$newStatus = Product::STATUS_HIDDEN;
break;
case 'NEW':
case 'Active':
$newStatus = Product::STATUS_SHOW;
break;
case 'NRND':
case 'Discontinued;Discontinuation':
case 'Discontinued':
case 'Discontinuation':
case 'Obsolete':
$newStatus = Product::STATUS_SEARCH_ONLY;
break;
default:
$newStatus = Product::STATUS_UNKNOWN;
}
Product::update([
'status' => $newStatus
], $product->id);
echo $product->title . ': ' . $status . ' -> ' . $newStatus . PHP_EOL;
}
echo PHP_EOL . 'Done';