From fb63b404756ee1848e5e5bf19fce1691f4579c67 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Tue, 29 Aug 2023 17:38:36 +0200 Subject: [PATCH] Fix namespaces of generated migrations [MAILPOET-5568] --- mailpoet/lib/Migrator/AppMigrationTemplate.php | 2 +- mailpoet/lib/Migrator/DbMigrationTemplate.php | 2 +- mailpoet/lib/Migrator/Runner.php | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mailpoet/lib/Migrator/AppMigrationTemplate.php b/mailpoet/lib/Migrator/AppMigrationTemplate.php index 819618cde5..5b9c2a4449 100644 --- a/mailpoet/lib/Migrator/AppMigrationTemplate.php +++ b/mailpoet/lib/Migrator/AppMigrationTemplate.php @@ -1,6 +1,6 @@ container = $container; $this->store = $store; - $this->namespace = $this->getMigrationsNamespace(); } public function runMigration(string $name, string $level): void { @@ -41,7 +38,8 @@ class Runner { } private function getClassName(string $name, string $level): string { - $className = $this->namespace . '\\' . ucfirst($level) . '\\' . $name; + $templateClass = $level === Repository::MIGRATIONS_LEVEL_DB ? DbMigrationTemplate::class : AppMigrationTemplate::class; + $className = $this->getNamespace($templateClass) . '\\' . $name; if (!class_exists($className)) { throw MigratorException::migrationClassNotFound($className); } @@ -53,8 +51,8 @@ class Runner { return $className; } - private function getMigrationsNamespace(): string { - $parts = explode('\\', DbMigrationTemplate::class); + private function getNamespace(string $className): string { + $parts = explode('\\', $className); return implode('\\', array_slice($parts, 0, -1)); } }