From aab06e0741af6a4cb75d1aec535102c8ee2700d0 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 21 Sep 2018 11:22:51 +0930 Subject: [PATCH] Live output of migrator notes --- .../src/Database/Console/MigrateCommand.php | 12 ++---- framework/core/src/Database/Migrator.php | 38 +++++++++++-------- .../core/src/Extension/ExtensionManager.php | 4 -- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/framework/core/src/Database/Console/MigrateCommand.php b/framework/core/src/Database/Console/MigrateCommand.php index f5782d13f..6340b3d67 100644 --- a/framework/core/src/Database/Console/MigrateCommand.php +++ b/framework/core/src/Database/Console/MigrateCommand.php @@ -60,14 +60,12 @@ class MigrateCommand extends AbstractCommand }); $migrator = $this->container->make('Flarum\Database\Migrator'); + $migrator->setOutput($this->output); $migrator->run(__DIR__.'/../../../migrations'); - foreach ($migrator->getNotes() as $note) { - $this->info($note); - } - $extensions = $this->container->make('Flarum\Extension\ExtensionManager'); + $extensions->getMigrator()->setOutput($this->output); foreach ($extensions->getExtensions() as $name => $extension) { if (! $extension->isEnabled()) { @@ -76,11 +74,7 @@ class MigrateCommand extends AbstractCommand $this->info('Migrating extension: '.$name); - $notes = $extensions->migrate($extension); - - foreach ($notes as $note) { - $this->info($note); - } + $extensions->migrate($extension); } $this->container->make('Flarum\Settings\SettingsRepositoryInterface')->set('version', $this->container->version()); diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index 8d411887c..98ce7a5e0 100644 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -16,6 +16,7 @@ use Flarum\Extension\Extension; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\Schema\Builder; use Illuminate\Filesystem\Filesystem; +use Symfony\Component\Console\Output\OutputInterface; class Migrator { @@ -41,11 +42,11 @@ class Migrator protected $schemaBuilder; /** - * The notes for the current operation. + * The output interface implementation. * - * @var array + * @var OutputInterface */ - protected $notes = []; + protected $output; /** * Create a new migrator instance. @@ -246,24 +247,29 @@ class Migrator } /** - * Raise a note event for the migrator. + * Set the output implementation that should be used by the console. * - * @param string $message + * @param OutputInterface $output + * @return $this + */ + public function setOutput(OutputInterface $output) + { + $this->output = $output; + + return $this; + } + + /** + * Write a note to the conosle's output. + * + * @param string $message * @return void */ protected function note($message) { - $this->notes[] = $message; - } - - /** - * Get the notes for the last operation. - * - * @return array - */ - public function getNotes() - { - return $this->notes; + if ($this->output) { + $this->output->writeln($message); + } } /** diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 43b2912ca..6ca5aed90 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -236,11 +236,7 @@ class ExtensionManager } else { $this->migrator->reset($migrationDir, $extension); } - - return $this->migrator->getNotes(); } - - return []; } /**