fix: 确保日志目录存在以避免写入日志失败

在多个文件中添加了检查并创建日志目录的逻辑,防止因目录不存在而导致日志写入失败
This commit is contained in:
2025-12-12 02:50:40 +08:00
parent 5438b944b8
commit 89a22c7b11
4 changed files with 55 additions and 0 deletions
+20
View File
@@ -32,6 +32,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$phone = $vip_customer['phone']; $phone = $vip_customer['phone'];
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'index.php:28', 'message' => 'VIP customer data', 'data' => ['vip_id' => $vip_id, 'has_car_model' => isset($vip_customer['car_model']), 'has_car_number' => isset($vip_customer['car_number'])], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'A']); $log_data = json_encode(['location' => 'index.php:28', 'message' => 'VIP customer data', 'data' => ['vip_id' => $vip_id, 'has_car_model' => isset($vip_customer['car_model']), 'has_car_number' => isset($vip_customer['car_number'])], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'A']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
// VIP客户信息优先,但允许通过POST覆盖(如果用户想修改) // VIP客户信息优先,但允许通过POST覆盖(如果用户想修改)
@@ -116,6 +121,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 两个时间段重叠的条件:现有预约的开始时间 < 新预约的结束时间 AND 现有预约的结束时间 > 新预约的开始时间 // 两个时间段重叠的条件:现有预约的开始时间 < 新预约的结束时间 AND 现有预约的结束时间 > 新预约的开始时间
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'index.php:98', 'message' => 'Checking time conflict', 'data' => ['start_time' => $start_time, 'end_time' => $end_time, 'duration' => $duration], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'F']); $log_data = json_encode(['location' => 'index.php:98', 'message' => 'Checking time conflict', 'data' => ['start_time' => $start_time, 'end_time' => $end_time, 'duration' => $duration], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'F']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
$stmt = $pdo->prepare("SELECT COUNT(*) FROM bookings $stmt = $pdo->prepare("SELECT COUNT(*) FROM bookings
@@ -126,6 +136,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$conflict_count = $stmt->fetchColumn(); $conflict_count = $stmt->fetchColumn();
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'index.php:107', 'message' => 'Time conflict check result', 'data' => ['conflict_count' => $conflict_count], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'F']); $log_data = json_encode(['location' => 'index.php:107', 'message' => 'Time conflict check result', 'data' => ['conflict_count' => $conflict_count], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'F']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
@@ -216,6 +231,11 @@ foreach ($all_bookings as $booking) {
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'index.php:196', 'message' => 'Checking cross-day booking', 'data' => ['booking_date' => $booking_date, 'start_time' => $booking_start_time, 'end_time' => $booking_end_time, 'start_ts' => $start_timestamp, 'end_ts' => $end_timestamp], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'G']); $log_data = json_encode(['location' => 'index.php:196', 'message' => 'Checking cross-day booking', 'data' => ['booking_date' => $booking_date, 'start_time' => $booking_start_time, 'end_time' => $booking_end_time, 'start_ts' => $start_timestamp, 'end_ts' => $end_timestamp], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'G']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
+20
View File
@@ -3,6 +3,11 @@
require_once 'db_connect.php'; require_once 'db_connect.php';
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'process_booking.php:3', 'message' => 'Database connection check', 'data' => ['has_pdo' => isset($pdo), 'using_db_connect' => true], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'D']); $log_data = json_encode(['location' => 'process_booking.php:3', 'message' => 'Database connection check', 'data' => ['has_pdo' => isset($pdo), 'using_db_connect' => true], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'D']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
@@ -108,6 +113,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'process_booking.php:70', 'message' => 'Time conversion', 'data' => ['booking_date' => $booking_date, 'time_slot' => $time_slot, 'start_time' => $start_time, 'end_time' => $end_time, 'duration' => $duration], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'E']); $log_data = json_encode(['location' => 'process_booking.php:70', 'message' => 'Time conversion', 'data' => ['booking_date' => $booking_date, 'time_slot' => $time_slot, 'start_time' => $start_time, 'end_time' => $end_time, 'duration' => $duration], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'E']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
@@ -136,6 +146,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 两个时间段重叠的条件:现有预约的开始时间 < 新预约的结束时间 AND 现有预约的结束时间 > 新预约的开始时间 // 两个时间段重叠的条件:现有预约的开始时间 < 新预约的结束时间 AND 现有预约的结束时间 > 新预约的开始时间
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'process_booking.php:100', 'message' => 'Checking time conflict', 'data' => ['start_time' => $start_time, 'end_time' => $end_time], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'H']); $log_data = json_encode(['location' => 'process_booking.php:100', 'message' => 'Checking time conflict', 'data' => ['start_time' => $start_time, 'end_time' => $end_time], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'H']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
$stmt = $pdo->prepare("SELECT COUNT(*) FROM bookings $stmt = $pdo->prepare("SELECT COUNT(*) FROM bookings
@@ -146,6 +161,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$conflict_count = $stmt->fetchColumn(); $conflict_count = $stmt->fetchColumn();
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'process_booking.php:110', 'message' => 'Time conflict check result', 'data' => ['conflict_count' => $conflict_count], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'H']); $log_data = json_encode(['location' => 'process_booking.php:110', 'message' => 'Time conflict check result', 'data' => ['conflict_count' => $conflict_count], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'H']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
+10
View File
@@ -64,12 +64,22 @@ try {
// 计算新的持续时间(分钟) // 计算新的持续时间(分钟)
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'update_booking.php:65', 'message' => 'Calculating duration', 'data' => ['start_time' => $new_start_time, 'end_time' => $new_end_time], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'C']); $log_data = json_encode(['location' => 'update_booking.php:65', 'message' => 'Calculating duration', 'data' => ['start_time' => $new_start_time, 'end_time' => $new_end_time], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'C']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
$interval = $start_dt->diff($end_dt); $interval = $start_dt->diff($end_dt);
$duration = ($interval->days * 24 * 60) + ($interval->h * 60) + $interval->i; $duration = ($interval->days * 24 * 60) + ($interval->h * 60) + $interval->i;
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'update_booking.php:67', 'message' => 'Duration calculated', 'data' => ['duration' => $duration, 'days' => $interval->days, 'hours' => $interval->h, 'minutes' => $interval->i], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'C']); $log_data = json_encode(['location' => 'update_booking.php:67', 'message' => 'Duration calculated', 'data' => ['duration' => $duration, 'days' => $interval->days, 'hours' => $interval->h, 'minutes' => $interval->i], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'C']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
+5
View File
@@ -416,6 +416,11 @@ try {
// 查询所有可用的洗车套餐 // 查询所有可用的洗车套餐
// #region agent log // #region agent log
$log_data = json_encode(['location' => 'vip.php:417', 'message' => 'Loading packages', 'data' => ['using_pdo' => isset($pdo), 'using_conn' => isset($conn)], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'B']); $log_data = json_encode(['location' => 'vip.php:417', 'message' => 'Loading packages', 'data' => ['using_pdo' => isset($pdo), 'using_conn' => isset($conn)], 'timestamp' => time() * 1000, 'sessionId' => 'debug-session', 'runId' => 'run1', 'hypothesisId' => 'B']);
// 确保日志目录存在
$log_dir = '.cursor';
if (!file_exists($log_dir)) {
mkdir($log_dir, 0777, true);
}
file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND); file_put_contents('.cursor/debug.log', $log_data . "\n", FILE_APPEND);
// #endregion // #endregion
try { try {