create database fix

This commit is contained in:
Roman 2023-01-09 17:10:47 +01:00
parent 5ac363d360
commit 11f1f2e678

@ -4,6 +4,7 @@ namespace Core\Configuration;
use Core\Driver\SQL\SQL; use Core\Driver\SQL\SQL;
use Core\Objects\DatabaseEntity\Controller\DatabaseEntity; use Core\Objects\DatabaseEntity\Controller\DatabaseEntity;
use Core\Objects\DatabaseEntity\Controller\DatabaseEntityHandler;
use Core\Objects\DatabaseEntity\Group; use Core\Objects\DatabaseEntity\Group;
use Core\Objects\DatabaseEntity\Language; use Core\Objects\DatabaseEntity\Language;
use Core\Objects\DatabaseEntity\Route; use Core\Objects\DatabaseEntity\Route;
@ -18,17 +19,6 @@ class CreateDatabase extends DatabaseScript {
self::loadEntities($queries, $sql); self::loadEntities($queries, $sql);
$queries[] = Language::getHandler($sql)->getInsertQuery([
new Language(Language::AMERICAN_ENGLISH, "en_US", 'American English'),
new Language(Language::GERMAN_STANDARD, "de_DE", 'Deutsch Standard'),
]);
$queries[] = Group::getHandler($sql)->getInsertQuery([
new Group(Group::ADMIN, Group::GROUPS[Group::ADMIN], "#dc3545"),
new Group(Group::MODERATOR, Group::GROUPS[Group::MODERATOR], "#28a745"),
new Group(Group::SUPPORT, Group::GROUPS[Group::SUPPORT], "#007bff"),
]);
$queries[] = $sql->createTable("Visitor") $queries[] = $sql->createTable("Visitor")
->addInt("day") ->addInt("day")
->addInt("count", false, 1) ->addInt("count", false, 1)
@ -122,7 +112,6 @@ class CreateDatabase extends DatabaseScript {
$persistables = []; $persistables = [];
$baseDirs = ["Core", "Site"]; $baseDirs = ["Core", "Site"];
foreach ($baseDirs as $baseDir) { foreach ($baseDirs as $baseDir) {
$entityDirectory = "./$baseDir/Objects/DatabaseEntity/"; $entityDirectory = "./$baseDir/Objects/DatabaseEntity/";
if (file_exists($entityDirectory) && is_dir($entityDirectory)) { if (file_exists($entityDirectory) && is_dir($entityDirectory)) {
$scan_arr = scandir($entityDirectory); $scan_arr = scandir($entityDirectory);
@ -133,9 +122,9 @@ class CreateDatabase extends DatabaseScript {
$className = substr($file, 0, strlen($file) - strlen($suffix)); $className = substr($file, 0, strlen($file) - strlen($suffix));
$className = "\\$baseDir\\Objects\\DatabaseEntity\\$className"; $className = "\\$baseDir\\Objects\\DatabaseEntity\\$className";
$reflectionClass = new \ReflectionClass($className); $reflectionClass = new \ReflectionClass($className);
if ($reflectionClass->getParentClass()?->getName() === DatabaseEntity::class) { if ($reflectionClass->isSubclassOf(DatabaseEntity::class)) {
$method = "$className::getHandler"; $method = "$className::getHandler";
$handler = call_user_func($method, $sql); $handler = call_user_func($method, $sql, null, true);
$persistables[$handler->getTableName()] = $handler; $persistables[$handler->getTableName()] = $handler;
foreach ($handler->getNMRelations() as $nmTableName => $nmRelation) { foreach ($handler->getNMRelations() as $nmTableName => $nmRelation) {
@ -145,6 +134,7 @@ class CreateDatabase extends DatabaseScript {
} }
} }
} }
}
$tableCount = count($persistables); $tableCount = count($persistables);
$createdTables = []; $createdTables = [];
@ -171,5 +161,4 @@ class CreateDatabase extends DatabaseScript {
} }
} }
} }
}
} }