diff --git a/APP Store.zip b/APP Store.zip
deleted file mode 100644
index aec3a8d..0000000
Binary files a/APP Store.zip and /dev/null differ
diff --git a/admin/manage_versions.php b/admin/manage_versions.php
index d8887f4..a4e91a6 100644
--- a/admin/manage_versions.php
+++ b/admin/manage_versions.php
@@ -81,39 +81,80 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_version'])) {
}
}
-// 处理删除版本
-if (isset($_GET['delete_id']) && is_numeric($_GET['delete_id'])) {
- $versionId = $_GET['delete_id'];
+// 处理版本删除请求
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_version'])) {
+ // 设置内容类型为纯文本
+ header('Content-Type: text/plain');
- // 获取版本信息
- $getVersionSql = "SELECT file_path FROM app_versions WHERE id = ? AND app_id = ?";
- $stmt = $conn->prepare($getVersionSql);
- $stmt->bind_param("ii", $versionId, $appId);
- $stmt->execute();
- $result = $stmt->get_result();
+ $versionId = $_POST['version_id'];
+ $appId = $_POST['app_id'];
- if ($result->num_rows === 1) {
- $version = $result->fetch_assoc();
+ // 初始化消息变量
+ $message = '';
+
+ // 开始事务
+ $conn->begin_transaction();
+
+ try {
+ // 1. 获取文件路径
+ $filePath = '';
+ $getFilePathSql = "SELECT file_path FROM app_versions WHERE id = ? AND app_id = ?";
+ $getFileStmt = $conn->prepare($getFilePathSql);
- // 删除文件
- if (file_exists($version['file_path'])) {
- unlink($version['file_path']);
+ if (!$getFileStmt) {
+ throw new Exception("获取文件路径查询准备失败: " . $conn->error);
}
- // 删除数据库记录
+ $getFileStmt->bind_param("ii", $versionId, $appId);
+ $getFileStmt->execute();
+ $fileResult = $getFileStmt->get_result();
+
+ if ($fileResult->num_rows > 0) {
+ $fileRow = $fileResult->fetch_assoc();
+ $filePath = $fileRow['file_path'];
+ }
+
+ // 2. 从数据库删除版本记录
$deleteVersionSql = "DELETE FROM app_versions WHERE id = ? AND app_id = ?";
- $stmt = $conn->prepare($deleteVersionSql);
- $stmt->bind_param("ii", $versionId, $appId);
+ $deleteVersionStmt = $conn->prepare($deleteVersionSql);
- if ($stmt->execute() === TRUE) {
- header('Location: manage_versions.php?app_id=' . $appId . '&success=版本删除成功');
- exit;
- } else {
- $error = '版本删除失败: ' . $conn->error;
+ if (!$deleteVersionStmt) {
+ throw new Exception("版本删除查询准备失败: " . $conn->error);
}
- } else {
- $error = '版本不存在';
+
+ $deleteVersionStmt->bind_param("ii", $versionId, $appId);
+
+ if (!$deleteVersionStmt->execute()) {
+ throw new Exception("版本删除执行失败: " . $conn->error);
+ }
+
+ // 检查是否有记录被删除
+ if ($deleteVersionStmt->affected_rows === 0) {
+ throw new Exception("未找到要删除的版本记录");
+ }
+
+ // 3. 如果数据库删除成功,尝试删除文件(即使文件删除失败也不回滚数据库操作)
+ if (!empty($filePath) && file_exists($filePath)) {
+ if (!unlink($filePath)) {
+ // 文件删除失败不影响数据库操作,继续处理
+ }
+ }
+
+ // 提交事务
+ $conn->commit();
+ $message = '版本删除成功';
+
+ } catch (Exception $e) {
+ // 回滚事务
+ $conn->rollback();
+ $message = '版本删除失败: ' . $e->getMessage();
}
+
+ // 只输出消息,不包含任何HTML
+ echo $message;
+
+ // 确保脚本终止,不执行后续代码
+ exit;
}
// 处理编辑版本
diff --git a/developer/version_control.php b/developer/version_control.php
index ace71dd..9621585 100644
--- a/developer/version_control.php
+++ b/developer/version_control.php
@@ -292,6 +292,8 @@ if (!$verStmt) {
+
+