Files
xianyan/docs/toolsapi/scripts/deploy_user_deletion.py
Developer 283950ea07 chore: 批量代码优化与功能迭代更新
本次提交包含大量代码优化、功能新增与服务端配置更新:
1. 修复分析报告统计数据,调整CMake策略设置
2. 优化APP权限配置、编辑器与聊天界面组件
3. 更新依赖库版本与pubspec配置
4. 新增文件传输服务端、信令服务器相关配置与脚本
5. 完善用户注销功能与数据库迁移脚本
6. 优化多处动画效果、代码风格与日志输出
7. 新增多种调试与部署脚本,修复已知BUG
2026-05-12 06:28:04 +08:00

162 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
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.
#!/usr/bin/env python3
"""
============================================================
闲言工具箱 — 注销功能部署脚本
创建时间: 2026-05-12
作用: 上传注销接口相关PHP文件到服务器并执行SQL迁移
上次更新: v9.2.0 新建
============================================================
"""
import paramiko
import os
import sys
import time
HOST = '123.207.67.197'
PORT = 22
USER = 'root'
PASS = '520Kiss123'
REMOTE_APP_PATH = '/www/wwwroot/tools.wktyl.com/application'
FILES_TO_UPLOAD = [
{
'local': r'e:\project\flutter\f\xianyan\docs\toolsapi\application\api\controller\UserSecurity.php',
'remote': f'{REMOTE_APP_PATH}/api/controller/UserSecurity.php',
'desc': 'UserSecurity.php (新增requestDeletion/deletionStatus/cancelDeletion)',
},
{
'local': r'e:\project\flutter\f\xianyan\docs\toolsapi\application\api\controller\User.php',
'remote': f'{REMOTE_APP_PATH}/api/controller/User.php',
'desc': 'User.php (新增注销方法转发)',
},
{
'local': r'e:\project\flutter\f\xianyan\docs\toolsapi\application\route.php',
'remote': f'{REMOTE_APP_PATH}/route.php',
'desc': 'route.php (新增注销路由)',
},
]
SQL_MIGRATION = r'e:\project\flutter\f\xianyan\docs\toolsapi\application\admin\command\Install\migrate_v9_2.sql'
def main():
print("=" * 60)
print("闲言工具箱 — 注销功能部署")
print("=" * 60)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(HOST, PORT, USER, PASS)
sftp = ssh.open_sftp()
# 1. 上传PHP文件
print("\n--- 上传PHP文件 ---")
for item in FILES_TO_UPLOAD:
local = item['local']
remote = item['remote']
desc = item['desc']
if not os.path.exists(local):
print(f"❌ 本地文件不存在: {local}")
continue
timestamp = time.strftime('%Y%m%d_%H%M%S')
backup = f"{remote}.bak.{timestamp}"
try:
sftp.rename(remote, backup)
print(f" 备份: {remote} -> {backup}")
except:
print(f" 无需备份(文件不存在): {remote}")
sftp.put(local, remote)
sftp.chmod(remote, 0o644)
print(f" ✅ 上传: {desc}")
# 2. 上传SQL迁移文件
print("\n--- 上传SQL迁移文件 ---")
if os.path.exists(SQL_MIGRATION):
remote_sql = f'{REMOTE_APP_PATH}/admin/command/Install/migrate_v9_2.sql'
sftp.put(SQL_MIGRATION, remote_sql)
sftp.chmod(remote_sql, 0o644)
print(f" ✅ 上传: migrate_v9_2.sql")
else:
print(f" ❌ SQL文件不存在: {SQL_MIGRATION}")
# 3. 执行SQL迁移
print("\n--- 执行SQL迁移(创建user_deletion表) ---")
sql_content = open(SQL_MIGRATION, 'r', encoding='utf-8').read()
sql_statements = [s.strip() for s in sql_content.split(';') if s.strip() and not s.strip().startswith('--')]
for sql in sql_statements:
if 'CREATE TABLE' in sql:
check_cmd = "mysql -u tools -ptools tools -e \"SHOW TABLES LIKE 'fa_user_deletion'\" 2>/dev/null"
stdin, stdout, stderr = ssh.exec_command(check_cmd)
result = stdout.read().decode().strip()
if result:
print(" ⚠️ fa_user_deletion表已存在跳过创建")
else:
full_sql = sql + ';'
mysql_cmd = f"mysql -u tools -ptools tools -e \"{full_sql.replace('\"', '\\\"')}\" 2>/dev/null"
stdin, stdout, stderr = ssh.exec_command(mysql_cmd)
err = stderr.read().decode().strip()
if err:
print(f" ❌ SQL执行错误: {err}")
else:
print(" ✅ fa_user_deletion表创建成功")
# 4. 清理PHP缓存
print("\n--- 清理PHP缓存 ---")
stdin, stdout, stderr = ssh.exec_command(f'rm -rf {REMOTE_APP_PATH}/../runtime/cache/* {REMOTE_APP_PATH}/../runtime/temp/*')
print(" ✅ 缓存已清理")
# 5. 验证文件
print("\n--- 验证上传文件 ---")
for item in FILES_TO_UPLOAD:
remote = item['remote']
try:
stat = sftp.stat(remote)
print(f"{item['desc']} ({stat.st_size} bytes)")
except:
print(f" ❌ 文件不存在: {remote}")
sftp.close()
# 6. 快速接口检测
print("\n--- 接口可用性检测 ---")
import requests as req
test_urls = [
('POST', '/api/user_security/requestDeletion', '注销申请接口'),
('GET', '/api/user_security/deletionStatus', '注销状态接口'),
('POST', '/api/user_security/cancelDeletion', '取消注销接口'),
]
for method, path, desc in test_urls:
url = f'https://tools.wktyl.com{path}'
try:
if method == 'GET':
r = req.get(url, timeout=10)
else:
r = req.post(url, timeout=10)
if r.status_code == 404:
print(f"{desc}: 404 未找到")
elif r.status_code == 200:
data = r.json()
if data.get('code') == -1:
print(f"{desc}: 接口存在(需登录)")
else:
print(f"{desc}: 接口正常(code={data.get('code')})")
else:
print(f" ⚠️ {desc}: HTTP {r.status_code}")
except Exception as e:
print(f"{desc}: 请求失败 - {e}")
ssh.close()
print("\n" + "=" * 60)
print("部署完成!")
print("=" * 60)
if __name__ == "__main__":
main()