';
echo '';
echo '
';
echo 'EasyStream Settings Initialization
';
}
try {
// Read SQL file
$sqlFile = __DIR__ . '/__install/add_admin_settings.sql';
if (!file_exists($sqlFile)) {
throw new Exception("SQL file not found: $sqlFile");
}
$sql = file_get_contents($sqlFile);
if ($sql === false) {
throw new Exception("Failed to read SQL file");
}
output('Reading SQL migration file...', 'info');
// Split SQL into individual statements
$statements = array_filter(
array_map('trim', explode(';', $sql)),
function($stmt) {
return !empty($stmt) &&
!preg_match('/^--/', $stmt) &&
!preg_match('/^\/\*/', $stmt);
}
);
output('Found ' . count($statements) . ' SQL statements', 'info');
// Execute each statement
$successCount = 0;
$errorCount = 0;
foreach ($statements as $statement) {
$statement = trim($statement);
if (empty($statement)) {
continue;
}
// Skip comments
if (preg_match('/^(--|\/\*)/', $statement)) {
continue;
}
try {
$pdo->exec($statement);
$successCount++;
} catch (PDOException $e) {
// Ignore duplicate key errors (settings already exist)
if ($e->getCode() !== '23000') {
output('Error executing statement: ' . $e->getMessage(), 'error');
$errorCount++;
} else {
$successCount++;
}
}
}
output("\nSettings initialization completed!", 'success');
output("Successful statements: $successCount", 'success');
if ($errorCount > 0) {
output("Errors encountered: $errorCount", 'error');
}
// Get total settings count
$stmt = $pdo->query("SELECT COUNT(*) FROM db_settings");
$totalSettings = $stmt->fetchColumn();
output("\nTotal settings in database: $totalSettings", 'info');
// Show sample settings
output("\nSample settings:", 'info');
$stmt = $pdo->query("SELECT cfg_name, cfg_data, cfg_info FROM db_settings LIMIT 10");
$settings = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($settings as $setting) {
output(" - {$setting['cfg_name']}: {$setting['cfg_data']} ({$setting['cfg_info']})", 'info');
}
output("\nYou can now access the settings panel at: /admin_settings.php", 'success');
output("\nInitialization completed successfully!", 'success');
if (!$isCLI) {
echo '
Go to Settings Panel';
echo '
Back to Dashboard';
}
} catch (Exception $e) {
output('FATAL ERROR: ' . $e->getMessage(), 'error');
output('Trace: ' . $e->getTraceAsString(), 'error');
exit(1);
}
if (!$isCLI) {
echo '