Fix namespaces of generated migrations

[MAILPOET-5568]
This commit is contained in:
Jan Jakes
2023-08-29 17:38:36 +02:00
committed by Aschepikov
parent e2cf884b98
commit fb63b40475
3 changed files with 8 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);
namespace MailPoet\Migrations;
namespace MailPoet\Migrations\App;
use MailPoet\Migrator\AppMigration;

View File

@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);
namespace MailPoet\Migrations;
namespace MailPoet\Migrations\Db;
use MailPoet\Migrator\DbMigration;

View File

@@ -3,7 +3,8 @@
namespace MailPoet\Migrator;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Migrations\DbMigrationTemplate;
use MailPoet\Migrations\App\AppMigrationTemplate;
use MailPoet\Migrations\Db\DbMigrationTemplate;
use Throwable;
class Runner {
@@ -13,16 +14,12 @@ class Runner {
/** @var Store */
private $store;
/** @var string */
private $namespace;
public function __construct(
ContainerWrapper $container,
Store $store
) {
$this->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));
}
}