From 1a2c5787c75ec3e27aab1336fcfed53f3b874d69 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 20 Feb 2026 06:30:25 +0000 Subject: [PATCH] update error --- lib/LicenseService.php | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/LicenseService.php b/lib/LicenseService.php index 3d0f9d1..d32d64a 100644 --- a/lib/LicenseService.php +++ b/lib/LicenseService.php @@ -15,6 +15,7 @@ class LicenseService { */ public static function getTrialRemainingDays() { require_once __DIR__ . '/../db/config.php'; + self::ensureTrialSchema(); $stmt = db()->prepare("SELECT trial_started_at FROM system_license LIMIT 1"); $stmt->execute(); $res = $stmt->fetch(); @@ -30,11 +31,53 @@ class LicenseService { return (int) max(0, 15 - $days_elapsed); } + /** + * Ensures the database schema for the trial period exists. + */ + private static function ensureTrialSchema() { + require_once __DIR__ . '/../db/config.php'; + try { + $db = db(); + // Check if table exists + $tableExists = $db->query("SHOW TABLES LIKE 'system_license'")->fetch(); + + if (!$tableExists) { + $db->exec("CREATE TABLE system_license ( + id INT AUTO_INCREMENT PRIMARY KEY, + license_key VARCHAR(255) DEFAULT '', + activation_token TEXT DEFAULT NULL, + fingerprint VARCHAR(255) DEFAULT NULL, + status ENUM('pending', 'active', 'expired', 'suspended', 'trial') DEFAULT 'pending', + activated_at DATETIME DEFAULT NULL, + last_checked_at DATETIME DEFAULT NULL, + trial_started_at DATETIME DEFAULT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"); + } else { + // Check if trial_started_at column exists + $stmt = $db->query("SHOW COLUMNS FROM system_license LIKE 'trial_started_at'"); + if (!$stmt->fetch()) { + $db->exec("ALTER TABLE system_license ADD COLUMN trial_started_at DATETIME DEFAULT NULL"); + } + + // Ensure 'trial' status exists in ENUM + $stmt = $db->query("SHOW COLUMNS FROM system_license LIKE 'status'"); + $statusCol = $stmt->fetch(); + if ($statusCol && strpos($statusCol['Type'], "'trial'") === false) { + $db->exec("ALTER TABLE system_license MODIFY COLUMN status ENUM('pending', 'active', 'expired', 'suspended', 'trial') DEFAULT 'pending'"); + } + } + } catch (Exception $e) { + // Log or ignore + } + } + /** * Initializes the trial period. */ private static function startTrial() { require_once __DIR__ . '/../db/config.php'; + self::ensureTrialSchema(); $stmt = db()->prepare("SELECT COUNT(*) FROM system_license"); $stmt->execute(); if ($stmt->fetchColumn() == 0) {