脚本备份
This commit is contained in:
parent
a1b2fb2fd0
commit
f67455e37a
5 changed files with 519 additions and 0 deletions
68
migrate-script.php
Normal file
68
migrate-script.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?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 ($yith_brands_before > 0) {
|
||||
echo "🔄 开始迁移 YITH 品牌到原生品牌...\n";
|
||||
|
||||
if ($native_brands_before > 0) {
|
||||
echo "⚠️ 警告:已存在 " . $native_brands_before . " 个原生品牌\n";
|
||||
}
|
||||
|
||||
$wpdb->query('START TRANSACTION');
|
||||
|
||||
try {
|
||||
$result = $wpdb->update(
|
||||
$wpdb->term_taxonomy,
|
||||
array('taxonomy' => 'product_brand'),
|
||||
array('taxonomy' => 'yith_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 "ℹ️ 未检测到 YITH 品牌数据,无需迁移\n";
|
||||
}
|
||||
|
||||
echo "\n=== 迁移完成 ===\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue