Replace the single user (defined in /data/config.php) with a multi user management thing

This commit is contained in:
Bernd Bestel
2018-07-24 19:31:43 +02:00
parent b52ab91606
commit 7f8540ff4e
19 changed files with 695 additions and 23 deletions

View File

@@ -8,21 +8,38 @@ class DatabaseMigrationService extends BaseService
{
$this->DatabaseService->ExecuteDbStatement("CREATE TABLE IF NOT EXISTS migrations (migration INTEGER NOT NULL PRIMARY KEY UNIQUE, execution_time_timestamp DATETIME DEFAULT (datetime('now', 'localtime')))");
$migrationFiles = array();
$sqlMigrationFiles = array();
foreach (new \FilesystemIterator(__DIR__ . '/../migrations') as $file)
{
$migrationFiles[$file->getBasename('.sql')] = $file->getPathname();
if ($file->getExtension() === 'sql')
{
$sqlMigrationFiles[$file->getBasename('.sql')] = $file->getPathname();
}
}
ksort($migrationFiles);
foreach($migrationFiles as $migrationNumber => $migrationFile)
ksort($sqlMigrationFiles);
foreach($sqlMigrationFiles as $migrationNumber => $migrationFile)
{
$migrationNumber = ltrim($migrationNumber, '0');
$this->ExecuteMigrationWhenNeeded($migrationNumber, file_get_contents($migrationFile));
$this->ExecuteSqlMigrationWhenNeeded($migrationNumber, file_get_contents($migrationFile));
}
$phpMigrationFiles = array();
foreach (new \FilesystemIterator(__DIR__ . '/../migrations') as $file)
{
if ($file->getExtension() === 'php')
{
$phpMigrationFiles[$file->getBasename('.php')] = $file->getPathname();
}
}
ksort($phpMigrationFiles);
foreach($phpMigrationFiles as $migrationNumber => $migrationFile)
{
$migrationNumber = ltrim($migrationNumber, '0');
$this->ExecutePhpMigrationWhenNeeded($migrationNumber, $migrationFile);
}
}
private function ExecuteMigrationWhenNeeded(int $migrationId, string $sql)
private function ExecuteSqlMigrationWhenNeeded(int $migrationId, string $sql)
{
$rowCount = $this->DatabaseService->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
if (intval($rowCount) === 0)
@@ -31,4 +48,14 @@ class DatabaseMigrationService extends BaseService
$this->DatabaseService->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
}
}
private function ExecutePhpMigrationWhenNeeded(int $migrationId, string $phpFile)
{
$rowCount = $this->DatabaseService->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
if (intval($rowCount) === 0)
{
include $phpFile;
$this->DatabaseService->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
}
}
}