脚本备份

This commit is contained in:
feibisi 2025-10-21 14:48:11 +08:00
parent a1b2fb2fd0
commit f67455e37a
5 changed files with 519 additions and 0 deletions

64
rollback-script.php Normal file
View file

@ -0,0 +1,64 @@
<?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";