Fix namespaces of generated migrations
[MAILPOET-5568]
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php declare(strict_types = 1);
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
namespace MailPoet\Migrations;
|
namespace MailPoet\Migrations\App;
|
||||||
|
|
||||||
use MailPoet\Migrator\AppMigration;
|
use MailPoet\Migrator\AppMigration;
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php declare(strict_types = 1);
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
namespace MailPoet\Migrations;
|
namespace MailPoet\Migrations\Db;
|
||||||
|
|
||||||
use MailPoet\Migrator\DbMigration;
|
use MailPoet\Migrator\DbMigration;
|
||||||
|
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
namespace MailPoet\Migrator;
|
namespace MailPoet\Migrator;
|
||||||
|
|
||||||
use MailPoet\DI\ContainerWrapper;
|
use MailPoet\DI\ContainerWrapper;
|
||||||
use MailPoet\Migrations\DbMigrationTemplate;
|
use MailPoet\Migrations\App\AppMigrationTemplate;
|
||||||
|
use MailPoet\Migrations\Db\DbMigrationTemplate;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Runner {
|
class Runner {
|
||||||
@@ -13,16 +14,12 @@ class Runner {
|
|||||||
/** @var Store */
|
/** @var Store */
|
||||||
private $store;
|
private $store;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $namespace;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ContainerWrapper $container,
|
ContainerWrapper $container,
|
||||||
Store $store
|
Store $store
|
||||||
) {
|
) {
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->store = $store;
|
$this->store = $store;
|
||||||
$this->namespace = $this->getMigrationsNamespace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runMigration(string $name, string $level): void {
|
public function runMigration(string $name, string $level): void {
|
||||||
@@ -41,7 +38,8 @@ class Runner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getClassName(string $name, string $level): string {
|
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)) {
|
if (!class_exists($className)) {
|
||||||
throw MigratorException::migrationClassNotFound($className);
|
throw MigratorException::migrationClassNotFound($className);
|
||||||
}
|
}
|
||||||
@@ -53,8 +51,8 @@ class Runner {
|
|||||||
return $className;
|
return $className;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMigrationsNamespace(): string {
|
private function getNamespace(string $className): string {
|
||||||
$parts = explode('\\', DbMigrationTemplate::class);
|
$parts = explode('\\', $className);
|
||||||
return implode('\\', array_slice($parts, 0, -1));
|
return implode('\\', array_slice($parts, 0, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user