yith-brand-migrator/rollback-script.php
2025-10-21 14:48:11 +08:00

64 lines
No EOL
2.3 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
define('WP_USE_THEMES', false);
require_once('/Users/feibisi-studio/Local Sites/mall/app/public/wp-load.php');
echo "=== YITH 品牌回滚脚本 ===\n\n";
global $wpdb;
echo "📊 回滚前数据统计:\n";
$yith_brands_before = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->terms} t
INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = 'yith_product_brand'");
$native_brands_before = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->terms} t
INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = 'product_brand'");
echo " YITH 品牌数量: " . ($yith_brands_before ?: 0) . "\n";
echo " 原生品牌数量: " . ($native_brands_before ?: 0) . "\n\n";
if ($native_brands_before > 0) {
echo "🔄 开始回滚原生品牌到 YITH 品牌...\n";
$wpdb->query('START TRANSACTION');
try {
$result = $wpdb->update(
$wpdb->term_taxonomy,
array('taxonomy' => 'yith_product_brand'),
array('taxonomy' => 'product_brand')
);
if ($result !== false) {
echo "✅ 成功回滚 " . $result . " 个品牌\n";
$wpdb->query('COMMIT');
wp_cache_flush();
if (function_exists('wc_delete_product_transients')) {
wc_delete_product_transients();
}
echo "✅ 缓存已清理\n";
$yith_brands_after = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'yith_product_brand'");
$native_brands_after = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'product_brand'");
echo "\n📊 回滚后数据统计:\n";
echo " YITH 品牌数量: " . ($yith_brands_after ?: 0) . "\n";
echo " 原生品牌数量: " . ($native_brands_after ?: 0) . "\n";
} else {
$wpdb->query('ROLLBACK');
echo "❌ 回滚失败\n";
}
} catch (Exception $e) {
$wpdb->query('ROLLBACK');
echo "❌ 回滚出错: " . $e->getMessage() . "\n";
}
} else {
echo " 未检测到原生品牌数据,无需回滚\n";
}
echo "\n=== 回滚完成 ===\n";