update error

This commit is contained in:
Flatlogic Bot 2026-02-20 06:30:25 +00:00
parent 84e9690f02
commit 1a2c5787c7

View File

@ -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) {