update error
This commit is contained in:
parent
84e9690f02
commit
1a2c5787c7
@ -15,6 +15,7 @@ class LicenseService {
|
|||||||
*/
|
*/
|
||||||
public static function getTrialRemainingDays() {
|
public static function getTrialRemainingDays() {
|
||||||
require_once __DIR__ . '/../db/config.php';
|
require_once __DIR__ . '/../db/config.php';
|
||||||
|
self::ensureTrialSchema();
|
||||||
$stmt = db()->prepare("SELECT trial_started_at FROM system_license LIMIT 1");
|
$stmt = db()->prepare("SELECT trial_started_at FROM system_license LIMIT 1");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$res = $stmt->fetch();
|
$res = $stmt->fetch();
|
||||||
@ -30,11 +31,53 @@ class LicenseService {
|
|||||||
return (int) max(0, 15 - $days_elapsed);
|
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.
|
* Initializes the trial period.
|
||||||
*/
|
*/
|
||||||
private static function startTrial() {
|
private static function startTrial() {
|
||||||
require_once __DIR__ . '/../db/config.php';
|
require_once __DIR__ . '/../db/config.php';
|
||||||
|
self::ensureTrialSchema();
|
||||||
$stmt = db()->prepare("SELECT COUNT(*) FROM system_license");
|
$stmt = db()->prepare("SELECT COUNT(*) FROM system_license");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
if ($stmt->fetchColumn() == 0) {
|
if ($stmt->fetchColumn() == 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user