上传文件至 /

This commit is contained in:
feibisi 2025-10-21 14:45:34 +00:00
parent 34e5aa095d
commit a1b2fb2fd0
2 changed files with 295 additions and 0 deletions

80
使用说明.md Normal file
View file

@ -0,0 +1,80 @@
# YITH 品牌迁移脚本工具包

## 📁 文件结构

```
yith/
├── migrate-script.php # 迁移执行脚本
├── verify-data.php # 数据验证脚本
├── rollback-script.php # 回滚脚本
├── test-plugin.php # 状态检查脚本
├── 品牌迁移指南.md # 详细迁移指南
└── 使用说明.md # 本文件
```

## 🚀 使用方法

### 1. 检查当前状态
```bash
php test-plugin.php
```

### 2. 执行迁移
```bash
php migrate-script.php
```

### 3. 验证数据
```bash
php verify-data.php
```

### 4. 回滚(如需要)
```bash
php rollback-script.php
```

## 📊 脚本功能说明

### test-plugin.php
- 显示当前品牌数据统计
- 检查数据库连接状态
- 快速状态检查

### migrate-script.php
- 执行完整的迁移流程
- 显示迁移前后数据对比
- 包含事务安全保护
- 自动清理缓存

### verify-data.php
- 验证迁移后的数据完整性
- 显示品牌列表和统计信息
- 检查产品关联和元数据

### rollback-script.php
- 将原生品牌回滚为 YITH 品牌
- 完全逆向操作
- 包含安全检查

## ⚠️ 注意事项

1. **备份数据**:执行迁移前请备份数据库
2. **测试环境**:建议先在测试环境中验证
3. **插件冲突**:确保 YITH 品牌插件已停用
4. **权限检查**:确保有足够的数据库操作权限

## 🔧 技术细节

- **数据库操作**:使用 WordPress 原生 `$wpdb` 类
- **事务安全**:所有操作都包含在数据库事务中
- **缓存处理**:自动清理 WordPress 和 WooCommerce 缓存
- **错误处理**:完整的错误捕获和回滚机制

## 📞 技术支持

如遇到问题,请检查:
1. WordPress 和 WooCommerce 版本兼容性
2. 数据库权限设置
3. PHP 错误日志
4. 插件冲突情况

215
品牌迁移指南.md Normal file
View file

@ -0,0 +1,215 @@
# YITH WooCommerce Brands Add-On 到 WooCommerce 原生品牌功能迁移指南

## 概述

本指南将帮助您将现有的 YITH WooCommerce Brands Add-On 数据迁移到 WooCommerce 9.4+ 的原生品牌功能。

## 数据结构分析

### YITH WooCommerce Brands Add-On 结构
- **分类法名称**: `yith_product_brand`
- **数据存储**: 使用标准 WordPress 分类法表
- `wp_terms` - 品牌名称和别名
- `wp_term_taxonomy` - 分类法类型和描述
- `wp_term_relationships` - 产品与品牌关联
- `wp_termmeta` - 品牌元数据logo、banner等

### WooCommerce 原生品牌功能结构
- **分类法名称**: `product_brand`
- **数据存储**: 同样使用标准 WordPress 分类法表
- **兼容性**: 与现有 WooCommerce 架构完全集成

## 迁移方案

### 方案一:使用提供的 PHP 迁移脚本

1. **上传脚本**
```bash
# 将 migrate-yith-brands.php 上传到 WordPress 根目录
```

2. **执行迁移**
```bash
# 方法1浏览器访问
http://yoursite.com/migrate-yith-brands.php
# 方法2WP-CLI 执行
wp eval-file migrate-yith-brands.php
```

3. **验证结果**
- 检查 WooCommerce > 产品 > 品牌 页面
- 确认品牌数据正确显示
- 验证产品页面品牌关联

### 方案二:手动 SQL 迁移

```sql
-- 1. 更新分类法名称
UPDATE wp_term_taxonomy
SET taxonomy = 'product_brand'
WHERE taxonomy = 'yith_product_brand';

-- 2. 刷新 WordPress 缓存
-- 需要在 WordPress 后台或通过代码执行
```

### 方案三:使用 WP-CLI推荐

```bash
# 预览迁移(不执行实际操作)
wp eval-file wp-cli-migrate-brands.php --dry-run=true

# 执行迁移
wp eval-file wp-cli-migrate-brands.php

# 迁移并清理旧数据
wp eval-file wp-cli-migrate-brands.php --cleanup=true
```

## 迁移步骤详解

### 1. 备份数据库
```bash
# 使用 mysqldump 备份
mysqldump -u username -p database_name > backup_before_migration.sql

# 或使用 WP-CLI
wp db export backup_before_migration.sql
```

### 2. 检查当前品牌数据
```sql
-- 查看现有品牌数量
SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'yith_product_brand';

-- 查看品牌名称
SELECT t.name, t.slug, tt.description, tt.count
FROM wp_terms t
JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = 'yith_product_brand';
```

### 3. 启用 WooCommerce 原生品牌功能

在 `functions.php` 中添加:
```php
// 启用 WooCommerce 原生品牌功能
add_action('init', function() {
if (class_exists('WooCommerce')) {
// 注册品牌分类法
register_taxonomy('product_brand', 'product', [
'labels' => [
'name' => '品牌',
'singular_name' => '品牌',
'menu_name' => '品牌',
],
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_admin_column' => true,
'hierarchical' => true,
'rewrite' => ['slug' => 'product-brand'],
'show_in_rest' => true,
]);
}
});
```

### 4. 执行迁移

选择上述任一方案执行迁移。

### 5. 更新主题模板

如果主题中有自定义的品牌显示代码,需要更新:

```php
// 旧代码
$brands = get_the_terms($product_id, 'yith_product_brand');

// 新代码
$brands = get_the_terms($product_id, 'product_brand');
```

### 6. 测试验证

- [ ] 品牌页面正常显示
- [ ] 产品页面品牌信息正确
- [ ] 品牌筛选功能正常
- [ ] 品牌 logo 和描述正确显示
- [ ] SEO URL 正常工作

## 注意事项

### 兼容性检查
- 确保 WooCommerce 版本 ≥ 9.4
- 检查主题是否支持原生品牌功能
- 验证相关插件兼容性

### 数据完整性
- 迁移前后品牌数量应一致
- 产品关联关系应保持不变
- 品牌元数据logo、描述等应完整迁移

### 性能优化
```php
// 迁移后清理缓存
wp_cache_flush();
delete_option('_transient_wc_attribute_taxonomies');
```

## 回滚方案

如果迁移出现问题,可以通过以下方式回滚:

```sql
-- 恢复原分类法名称
UPDATE wp_term_taxonomy
SET taxonomy = 'yith_product_brand'
WHERE taxonomy = 'product_brand';
```

或直接恢复数据库备份:
```bash
mysql -u username -p database_name < backup_before_migration.sql
```

## 常见问题

### Q: 迁移后品牌页面显示 404
**A**: 需要刷新固定链接设置
```bash
wp rewrite flush
```

### Q: 品牌 logo 丢失
**A**: 检查 termmeta 表中的元数据是否正确迁移
```sql
SELECT * FROM wp_termmeta WHERE meta_key LIKE '%brand%';
```

### Q: 产品页面不显示品牌
**A**: 检查主题模板是否使用了正确的分类法名称

## 后续维护

### 禁用 YITH 插件
迁移成功后,可以安全禁用 YITH WooCommerce Brands Add-On 插件。

### 清理旧数据
```sql
-- 删除旧的分类法数据(谨慎操作)
DELETE FROM wp_term_taxonomy WHERE taxonomy = 'yith_product_brand';
```

### 更新相关代码
检查并更新所有使用 `yith_product_brand` 的代码为 `product_brand`。

## 技术支持

如果在迁移过程中遇到问题,请:
1. 检查错误日志
2. 验证数据库连接
3. 确认权限设置
4. 联系技术支持团队