new installation fix

This commit is contained in:
Flatlogic Bot 2026-05-09 13:50:18 +00:00
parent 7c9d532070
commit 8896b8d05a
2 changed files with 45 additions and 32 deletions

View File

@ -303,17 +303,9 @@ INSERT INTO `role_permissions` VALUES
UNLOCK TABLES;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES
(1,1,'admin','$2y$10$uLxB5VJa9nZ3nGhukx7jOeBotQ/PtumL3ndbzTZ.TjrAr9yJH/hIq','admin@example.com',NULL,'uploads/profile_1_1771401598.png','default','active','2026-02-18 05:30:12'),
(2,1,'admin2','$2y$10$A299UOd8VZWXyuKcbcLwWewIg.7V2ti3oomGaKH9qhMm4vdG6a/xi',NULL,NULL,NULL,'default','active','2026-02-18 06:44:10'),
(5,1,'moosa','$2y$10$Ho5NrFTAb6HUH4VvCd4NZuCsKGMl4v1pvWiesEuC29fDDu6Pkg7AS','aalabry@gmail.com',NULL,NULL,'default','active','2026-02-18 09:30:38');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
-- Users are created during installation step 3.
-- Keep seed data user-free so fresh installs do not ship demo admin accounts
-- and stay compatible with the latest users table structure.
--
-- Dumping data for table `payment_methods`

View File

@ -138,28 +138,49 @@ class DatabaseInstaller {
private static function executeSqlFile(string $filePath): void {
require_once __DIR__ . '/../db/config.php';
$host = DB_HOST;
$name = DB_NAME;
$user = DB_USER;
$pass = DB_PASS;
$passwordSegment = $pass !== '' ? ' -p' . escapeshellarg($pass) : '';
$command = sprintf(
'mysql -h %s -u %s%s %s < %s',
escapeshellarg($host),
escapeshellarg($user),
$passwordSegment,
escapeshellarg($name),
escapeshellarg($filePath)
);
$output = [];
$returnVar = 0;
exec($command . ' 2>&1', $output, $returnVar);
if ($returnVar !== 0) {
throw new Exception('Failed to execute SQL file: ' . implode("\n", $output));
$pdo = db();
$sql = file_get_contents($filePath);
if ($sql === false) {
throw new RuntimeException('Unable to read SQL file: ' . basename($filePath));
}
$statements = self::splitSqlStatements($sql);
foreach ($statements as $index => $statement) {
if (self::shouldSkipSqlFileStatement($statement, $filePath)) {
continue;
}
try {
$pdo->exec($statement);
} catch (PDOException $exception) {
if (self::isIgnorableMigrationError($pdo, $exception, $statement)) {
continue;
}
throw new RuntimeException(
'Failed to execute SQL file ' . basename($filePath) . ' at statement ' . ($index + 1) . ': ' . $exception->getMessage(),
0,
$exception
);
}
}
}
private static function shouldSkipSqlFileStatement(string $statement, string $filePath): bool {
$normalized = strtoupper(trim($statement));
if ($normalized === '') {
return true;
}
if (str_starts_with($normalized, 'LOCK TABLES ') || str_starts_with($normalized, 'UNLOCK TABLES')) {
return true;
}
if (basename($filePath) === 'seed.sql' && preg_match('/^INSERT\s+INTO\s+`?users`?/i', $statement) === 1) {
return true;
}
return false;
}
private static function ensureMigrationsTable(PDO $pdo): void {