최초 커밋
This commit is contained in:
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
// header("Content-Type: application/json; charset=utf-8");
|
||||
|
||||
// // DB 연결
|
||||
// $conn = new mysqli('localhost', 'egbim', 'baron3840!!', 'egbim');
|
||||
// if ($conn->connect_error) {
|
||||
// http_response_code(500);
|
||||
// echo json_encode(['message' => 'DB 연결 실패']);
|
||||
// exit;
|
||||
// }
|
||||
// mysqli_set_charset($conn, 'utf8mb4');
|
||||
|
||||
// // === 파라미터 받기 ===
|
||||
// $product_code = $_POST['product_code'] ?? '';
|
||||
// $sw_version = $_POST['sw_version'] ?? '';
|
||||
// $version_type = $_POST['version_type'] ?? 'patch'; // major/minor/patch
|
||||
// $uploader = $_POST['uploader'] ?? '관리자';
|
||||
// $files = isset($_POST['files']) ? json_decode($_POST['files'], true) : [];
|
||||
|
||||
// if (!$product_code || !$sw_version || empty($files)) {
|
||||
// http_response_code(400);
|
||||
// echo json_encode(['message' => '필수값 누락']);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $inserted = [];
|
||||
// foreach ($files as $f) {
|
||||
// $filename = $f['name'] ?? ''; // 규칙 적용된 이름
|
||||
// $original_name = $f['original'] ?? $filename; // 원본 파일명 (없으면 동일)
|
||||
// $filepath = $f['path'] ?? '';
|
||||
// $filetype = $f['type'] ?? '';
|
||||
// $filesize = $f['size'] ?? 0;
|
||||
|
||||
// $sql = "INSERT INTO deploy_files
|
||||
// (product_code, sw_version, version_type,
|
||||
// filename, original_name, filepath, filetype,
|
||||
// filesize, uploader, upload_date, deleted)
|
||||
// VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 0)";
|
||||
|
||||
// $stmt = $conn->prepare($sql);
|
||||
// if (!$stmt) {
|
||||
// http_response_code(500);
|
||||
// echo json_encode(['message' => '쿼리 준비 실패: '.$conn->error]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// // 바인딩
|
||||
// $stmt->bind_param(
|
||||
// "sssssssis",
|
||||
// $product_code,
|
||||
// $sw_version,
|
||||
// $version_type,
|
||||
// $filename,
|
||||
// $original_name,
|
||||
// $filepath,
|
||||
// $filetype,
|
||||
// $filesize,
|
||||
// $uploader
|
||||
// );
|
||||
|
||||
// if ($stmt->execute()) {
|
||||
// $inserted[] = [
|
||||
// 'id' => $stmt->insert_id,
|
||||
// 'filename' => $filename,
|
||||
// 'original' => $original_name,
|
||||
// 'filetype' => $filetype,
|
||||
// 'version' => $sw_version,
|
||||
// 'size' => round($filesize/1024/1024, 2)."MB"
|
||||
// ];
|
||||
// } else {
|
||||
// http_response_code(500);
|
||||
// echo json_encode(['message' => 'DB insert 실패: '.$stmt->error]);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $stmt->close();
|
||||
// }
|
||||
|
||||
|
||||
// /* ✅ 버전 기록: deploy_versions_test 업데이트 */
|
||||
// $check = $conn->prepare("SELECT COUNT(*) FROM deploy_versions_test WHERE product_code=?");
|
||||
// if (!$check) {
|
||||
// error_log("쿼리 준비 실패: ".$conn->error);
|
||||
// } else {
|
||||
// $check->bind_param("s", $product_code);
|
||||
// $check->execute();
|
||||
// $check->bind_result($cnt);
|
||||
// $check->fetch();
|
||||
// $check->close();
|
||||
|
||||
// if ($cnt > 0) {
|
||||
// $upd = $conn->prepare("
|
||||
// UPDATE deploy_versions_test
|
||||
// SET family_version=?, external_version=?, updated_at=NOW()
|
||||
// WHERE product_code=?
|
||||
// ");
|
||||
// if (!$upd) {
|
||||
// error_log("UPDATE 준비 실패: ".$conn->error);
|
||||
// } else {
|
||||
// $upd->bind_param("sss", $sw_version, $sw_version, $product_code);
|
||||
// if (!$upd->execute()) {
|
||||
// error_log("UPDATE 실행 실패: ".$upd->error);
|
||||
// }
|
||||
// $upd->close();
|
||||
// }
|
||||
// } else {
|
||||
// $ins = $conn->prepare("
|
||||
// INSERT INTO deploy_versions_test (product_code, family_version, external_version, updated_at)
|
||||
// VALUES (?, ?, ?, NOW())
|
||||
// ");
|
||||
// if (!$ins) {
|
||||
// error_log("INSERT 준비 실패: ".$conn->error);
|
||||
// } else {
|
||||
// $ins->bind_param("sss", $product_code, $sw_version, $sw_version);
|
||||
// if (!$ins->execute()) {
|
||||
// error_log("INSERT 실행 실패: ".$ins->error);
|
||||
// }
|
||||
// $ins->close();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// echo json_encode([
|
||||
// 'message' => '업로드 DB 기록 완료',
|
||||
// 'group' => [
|
||||
// 'files' => $inserted,
|
||||
// 'upload' => date('Y-m-d H:i:s'),
|
||||
// 'uploader' => $uploader,
|
||||
// 'testdone' => '<button class="bg-green-500 text-white px-2 py-1 rounded">확인</button>',
|
||||
// 'tester' => '',
|
||||
// 'release' => '<button class="bg-blue-500 text-white px-2 py-1 rounded">확인</button>',
|
||||
// 'releaser' => ''
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
// $conn->close();
|
||||
?>
|
||||
<?php
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
|
||||
// DB 연결
|
||||
$conn = new mysqli('localhost', 'egbim', 'baron3840!!', 'egbim');
|
||||
if ($conn->connect_error) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['message' => 'DB 연결 실패']);
|
||||
exit;
|
||||
}
|
||||
mysqli_set_charset($conn, 'utf8mb4');
|
||||
|
||||
// === 파라미터 받기 ===
|
||||
$product_code = $_POST['product_code'] ?? '';
|
||||
$sw_version = $_POST['sw_version'] ?? '';
|
||||
$version_type = $_POST['version_type'] ?? 'patch'; // major/minor/patch
|
||||
$uploader = $_POST['uploader'] ?? '알 수 없음'; // JS에서 세션스토리지 값
|
||||
$files = isset($_POST['files']) ? json_decode($_POST['files'], true) : [];
|
||||
|
||||
if (!$product_code || !$sw_version || empty($files)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['message' => '필수값 누락']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$inserted = [];
|
||||
|
||||
foreach ($files as $f) {
|
||||
$filename = $f['name'] ?? '';
|
||||
$original_name = $f['original'] ?? $filename;
|
||||
$filepath = $f['path'] ?? '';
|
||||
$filetype = $f['type'] ?? '';
|
||||
$filesize = $f['size'] ?? 0;
|
||||
|
||||
$sql = "
|
||||
INSERT INTO deploy_files
|
||||
(product_code, sw_version, version_type,
|
||||
filename, original_name, filepath, filetype,
|
||||
filesize, uploader, upload_date, deleted)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
filename = VALUES(filename),
|
||||
original_name = VALUES(original_name),
|
||||
filepath = VALUES(filepath),
|
||||
filesize = VALUES(filesize),
|
||||
uploader = VALUES(uploader),
|
||||
upload_date = NOW(),
|
||||
deleted = 0
|
||||
";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
if (!$stmt) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['message' => '쿼리 준비 실패: '.$conn->error]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->bind_param(
|
||||
"sssssssis",
|
||||
$product_code,
|
||||
$sw_version,
|
||||
$version_type,
|
||||
$filename,
|
||||
$original_name,
|
||||
$filepath,
|
||||
$filetype,
|
||||
$filesize,
|
||||
$uploader
|
||||
);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$inserted[] = [
|
||||
'filename' => $filename,
|
||||
'original' => $original_name,
|
||||
'filetype' => $filetype,
|
||||
'version' => $sw_version,
|
||||
'size' => round($filesize/1024/1024, 2)."MB"
|
||||
];
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['message' => 'DB insert/update 실패: '.$stmt->error]);
|
||||
exit;
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
/* ✅ 버전 기록: deploy_versions_test 업데이트 */
|
||||
$check = $conn->prepare("SELECT COUNT(*) FROM deploy_versions_test WHERE product_code=?");
|
||||
if ($check) {
|
||||
$check->bind_param("s", $product_code);
|
||||
$check->execute();
|
||||
$check->bind_result($cnt);
|
||||
$check->fetch();
|
||||
$check->close();
|
||||
|
||||
if ($cnt > 0) {
|
||||
// ✅ 기존 레코드 있으면 family_version만 갱신
|
||||
$upd = $conn->prepare("
|
||||
UPDATE deploy_versions_test
|
||||
SET family_version=?, updated_at=NOW()
|
||||
WHERE product_code=?
|
||||
");
|
||||
if ($upd) {
|
||||
$upd->bind_param("ss", $sw_version, $product_code);
|
||||
$upd->execute();
|
||||
$upd->close();
|
||||
}
|
||||
} else {
|
||||
// ✅ 신규 insert 시 external_version은 NULL로 둠
|
||||
$ins = $conn->prepare("
|
||||
INSERT INTO deploy_versions_test (product_code, family_version, updated_at)
|
||||
VALUES (?, ?, NOW())
|
||||
");
|
||||
if ($ins) {
|
||||
$ins->bind_param("ss", $product_code, $sw_version);
|
||||
$ins->execute();
|
||||
$ins->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'message' => '업로드 DB 기록 완료 (insert or update)',
|
||||
'group' => [
|
||||
'files' => $inserted,
|
||||
'upload' => date('Y-m-d H:i:s'),
|
||||
'uploader' => $uploader,
|
||||
'testdone' => '<button class="bg-green-500 text-white px-2 py-1 rounded">확인</button>',
|
||||
'tester' => '',
|
||||
'release' => '<button class="bg-blue-500 text-white px-2 py-1 rounded">확인</button>',
|
||||
'releaser' => ''
|
||||
]
|
||||
]);
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user