diff --git a/Classes/Command/MigrationsCommandController.php b/Classes/Command/MigrationsCommandController.php index 01af7d2..3da192f 100644 --- a/Classes/Command/MigrationsCommandController.php +++ b/Classes/Command/MigrationsCommandController.php @@ -66,7 +66,7 @@ public function migrateCommand(bool $quiet = false) foreach ($unexecutedMigrations as $version => $migration) { try { - $this->migrationExecutor->execute($migration); + $this->migrationExecutor->execute($migration, 'up', $this->output); if (false === $quiet) { $this->outputLine('Executed Migration "' . $version . '".'); } @@ -86,7 +86,7 @@ public function executeCommand(string $version, string $direction = 'up') { try { $migration = $this->migrationService->getMigrationByVersion($version); - $this->migrationExecutor->execute($migration, $direction); + $this->migrationExecutor->execute($migration, $direction, $this->output); } catch (\Exception $exception) { $this->handleException($exception); } diff --git a/Classes/Domain/Handler/DefaultMigrationHandler.php b/Classes/Domain/Handler/DefaultMigrationHandler.php index 9971ddd..142875b 100644 --- a/Classes/Domain/Handler/DefaultMigrationHandler.php +++ b/Classes/Domain/Handler/DefaultMigrationHandler.php @@ -3,11 +3,18 @@ namespace Netlogix\Migrations\Domain\Handler; +use Neos\Flow\Cli\ConsoleOutput; use Netlogix\Migrations\Domain\Model\DefaultMigration; use Netlogix\Migrations\Domain\Model\Migration; class DefaultMigrationHandler implements MigrationHandler { + + /** + * @var ConsoleOutput + */ + protected $output; + public function canExecute(Migration $migration): bool { return $migration instanceof DefaultMigration; @@ -22,4 +29,19 @@ public function down(Migration $migration): void { $migration->down(); } + + public function setConsoleOutput(?ConsoleOutput $consoleOutput = null): void + { + $this->output = $consoleOutput; + } + + protected function outputLine(string $text, array $arguments = []): void + { + if (!$this->output) { + return; + } + + $this->output->outputLine($text, $arguments); + } + } diff --git a/Classes/Domain/Handler/MigrationHandler.php b/Classes/Domain/Handler/MigrationHandler.php index cffff68..508d23d 100644 --- a/Classes/Domain/Handler/MigrationHandler.php +++ b/Classes/Domain/Handler/MigrationHandler.php @@ -3,8 +3,8 @@ namespace Netlogix\Migrations\Domain\Handler; +use Neos\Flow\Cli\ConsoleOutput; use Netlogix\Migrations\Domain\Model\Migration; -use Netlogix\Migrations\Domain\Model\MigrationInterface; interface MigrationHandler { @@ -13,4 +13,6 @@ public function canExecute(Migration $migration): bool; public function up(Migration $migration): void; public function down(Migration $migration): void; + + public function setConsoleOutput(?ConsoleOutput $consoleOutput = null): void; } diff --git a/Classes/Domain/Service/FileSystemMigrationsResolver.php b/Classes/Domain/Service/FileSystemMigrationsResolver.php index db6de10..ec2365d 100644 --- a/Classes/Domain/Service/FileSystemMigrationsResolver.php +++ b/Classes/Domain/Service/FileSystemMigrationsResolver.php @@ -3,7 +3,6 @@ namespace Netlogix\Migrations\Domain\Service; -use Doctrine\DBAL\Migrations\Finder\GlobFinder; use Neos\Flow\Annotations as Flow; use Neos\Flow\Package\PackageInterface; use Neos\Flow\Package\PackageManager; @@ -36,8 +35,10 @@ public function __construct(PackageManager $packageManager) public function findMigrationFiles(): array { $classNames = []; - /** @var PackageInterface $package */ - foreach ($this->packageManager->getAvailablePackages() as $package) { + /** @var PackageInterface[] $packages */ + $packages = $this->packageManager->getFilteredPackages('available', 'Application'); + + foreach ($packages as $package) { $path = Files::concatenatePaths([ $package->getPackagePath(), 'Migrations', diff --git a/Classes/Domain/Service/GlobFinder.php b/Classes/Domain/Service/GlobFinder.php new file mode 100644 index 0000000..607bccc --- /dev/null +++ b/Classes/Domain/Service/GlobFinder.php @@ -0,0 +1,20 @@ +getRealPath($directory); + + $files = glob(rtrim($dir, '/') . '/**/Version*.php'); + + return $this->loadMigrations($files, $namespace); + } + +} diff --git a/Classes/Domain/Service/MigrationExecutor.php b/Classes/Domain/Service/MigrationExecutor.php index 2395f83..063d07f 100644 --- a/Classes/Domain/Service/MigrationExecutor.php +++ b/Classes/Domain/Service/MigrationExecutor.php @@ -3,6 +3,7 @@ namespace Netlogix\Migrations\Domain\Service; +use Neos\Flow\Cli\ConsoleOutput; use Neos\Flow\ObjectManagement\ObjectManager; use Neos\Flow\Reflection\ReflectionService; use Netlogix\Migrations\Domain\Handler\MigrationHandler; @@ -40,7 +41,7 @@ public function __construct( $this->versionLogger = $versionLogger; } - public function execute(Migration $migration, $direction = 'up') + public function execute(Migration $migration, $direction = 'up', ?ConsoleOutput $consoleOutput = null) { foreach ($this->reflectionService->getAllImplementationClassNamesForInterface(MigrationHandler::class) as $handlerClassName) { @@ -48,6 +49,7 @@ public function execute(Migration $migration, $direction = 'up') $handler = $this->objectManager->get($handlerClassName); if ($handler->canExecute($migration)) { + $handler->setConsoleOutput($consoleOutput); $result = $handler->{$direction}($migration); $this->versionLogger->logMigration($migration, $direction); return $result; diff --git a/Classes/Domain/Service/MigrationService.php b/Classes/Domain/Service/MigrationService.php index 24c1a1c..d0daffb 100644 --- a/Classes/Domain/Service/MigrationService.php +++ b/Classes/Domain/Service/MigrationService.php @@ -6,6 +6,7 @@ use Neos\Flow\Annotations as Flow; use Neos\Flow\ObjectManagement\ObjectManagerInterface; use Netlogix\Migrations\Domain\Model\Migration; +use Netlogix\Migrations\Domain\Model\MigrationStatus; use Netlogix\Migrations\Domain\Repository\MigrationStatusRepository; use Netlogix\Migrations\Error\UnknownMigration; diff --git a/Classes/Domain/Service/VersionResolver.php b/Classes/Domain/Service/VersionResolver.php index d228189..0a5e2ab 100644 --- a/Classes/Domain/Service/VersionResolver.php +++ b/Classes/Domain/Service/VersionResolver.php @@ -3,8 +3,6 @@ namespace Netlogix\Migrations\Domain\Service; -use Netlogix\Migrations\Domain\Model\Migration; - class VersionResolver { public function extractVersion(string $migrationClassName): string diff --git a/Tests/Unit/Domain/Service/FileSystemMigrationsResolverTest.php b/Tests/Unit/Domain/Service/FileSystemMigrationsResolverTest.php index 89bacf4..413bf13 100644 --- a/Tests/Unit/Domain/Service/FileSystemMigrationsResolverTest.php +++ b/Tests/Unit/Domain/Service/FileSystemMigrationsResolverTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Netlogix\Migrations\Tests\Unit\Domain\Service; -use Doctrine\DBAL\Migrations\Finder\GlobFinder; + use Neos\Flow\Package; use Neos\Flow\Package\PackageManager; use Neos\Flow\Tests\UnitTestCase; @@ -32,10 +32,11 @@ protected function setUp() ->method('getPackagePath') ->willReturn('dummy/package/path/'); - $packageManager->method('getAvailablePackages') + $packageManager->method('getFilteredPackages') ->willReturn([$dummyPackage]); + assert($packageManager instanceof PackageManager); - $this->fileSystemMigrationsResolver = new FileSystemMigrationsResolver($packageManager, new GlobFinder()); + $this->fileSystemMigrationsResolver = new FileSystemMigrationsResolver($packageManager); } /** @@ -43,6 +44,7 @@ protected function setUp() */ public function Can_return_empty_array() { + xdebug_break(); $files = $this->fileSystemMigrationsResolver->findMigrationFiles(); $this->assertCount(0, $files); }