|
|
@@ -0,0 +1,72 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
+
|
|
|
+// Variables de conexión
|
|
|
+$host = 'localhost';
|
|
|
+$dbname = 'samqa';
|
|
|
+$username = 'root';
|
|
|
+$password = 'root';
|
|
|
+$log_file = __DIR__ . '/../storage/logs/timeout_validator.log';
|
|
|
+
|
|
|
+// Función de log
|
|
|
+function writeLog($message)
|
|
|
+{
|
|
|
+ global $log_file;
|
|
|
+ $timestamp = date('Y-m-d H:i:s');
|
|
|
+ file_put_contents($log_file, "[$timestamp] $message" . PHP_EOL, FILE_APPEND | LOCK_EX);
|
|
|
+}
|
|
|
+
|
|
|
+// Conexión a BD
|
|
|
+try {
|
|
|
+ $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
|
|
|
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
+ writeLog("Conexión a BD establecida correctamente");
|
|
|
+} catch (PDOException $e) {
|
|
|
+ writeLog("ERROR: Conexión a BD falló - " . $e->getMessage());
|
|
|
+ die("Error de conexión: " . $e->getMessage());
|
|
|
+}
|
|
|
+
|
|
|
+// Validar timeouts vencidos
|
|
|
+$stmt = $pdo->prepare("
|
|
|
+ SELECT s.SOVA_IDSV, s.SOVA_INEX, s.SOVA_FEEN, s.SOVA_IDET
|
|
|
+ FROM S002V01TSOVA s
|
|
|
+ WHERE s.SOVA_ESTA = 'Pendiente'
|
|
|
+");
|
|
|
+$stmt->execute();
|
|
|
+$pendingSOVAs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
+writeLog("Validando timeouts de " . count($pendingSOVAs) . " SOVAs pendientes");
|
|
|
+
|
|
|
+foreach ($pendingSOVAs as $row) {
|
|
|
+ $sovaData = json_decode($row['SOVA_INEX'], true)[0];
|
|
|
+ $timeout = $sovaData['timeout'];
|
|
|
+
|
|
|
+ // Parsear timeout (ej: "30min", "2hr", "45seg", "6 min")
|
|
|
+ preg_match('/(\d+)\s*(seg|min|hr)/', $timeout, $matches);
|
|
|
+ if (count($matches) !== 3) continue;
|
|
|
+
|
|
|
+ $valor = (int)$matches[1];
|
|
|
+ $unidad = $matches[2];
|
|
|
+
|
|
|
+ // Convertir a DateInterval
|
|
|
+ $intervalSpec = match ($unidad) {
|
|
|
+ 'seg' => "PT{$valor}S",
|
|
|
+ 'min' => "PT{$valor}M",
|
|
|
+ 'hr' => "PT{$valor}H"
|
|
|
+ };
|
|
|
+
|
|
|
+ $fechaEnvio = new DateTime($row['SOVA_FEEN']);
|
|
|
+ $fechaLimite = clone $fechaEnvio;
|
|
|
+ $fechaLimite->add(new DateInterval($intervalSpec));
|
|
|
+ $ahora = new DateTime();
|
|
|
+ //writeLog($fechaLimite);
|
|
|
+
|
|
|
+ if ($ahora >= $fechaLimite) {
|
|
|
+ $updateStmt = $pdo->prepare("UPDATE S002V01TSOVA SET SOVA_ESTA = 'Validada por timeout' WHERE SOVA_IDSV = ?");
|
|
|
+ $updateStmt->execute([$row['SOVA_IDSV']]);
|
|
|
+ writeLog("SOVA autovalidada por timeout: ID {$row['SOVA_IDSV']} - Timeout: {$timeout}");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+writeLog("Validación de timeouts completada");
|
|
|
+echo "Validación de timeouts completada\n";
|