Fix namespaces of generated migrations
[MAILPOET-5568]
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Migrations;
|
||||
namespace MailPoet\Migrations\App;
|
||||
|
||||
use MailPoet\Migrator\AppMigration;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Migrations;
|
||||
namespace MailPoet\Migrations\Db;
|
||||
|
||||
use MailPoet\Migrator\DbMigration;
|
||||
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user