Live output of migrator notes

This commit is contained in:
Toby Zerner 2018-09-21 11:22:51 +09:30
parent 2d3f1d9f5c
commit aab06e0741
3 changed files with 25 additions and 29 deletions

View File

@ -60,14 +60,12 @@ class MigrateCommand extends AbstractCommand
}); });
$migrator = $this->container->make('Flarum\Database\Migrator'); $migrator = $this->container->make('Flarum\Database\Migrator');
$migrator->setOutput($this->output);
$migrator->run(__DIR__.'/../../../migrations'); $migrator->run(__DIR__.'/../../../migrations');
foreach ($migrator->getNotes() as $note) {
$this->info($note);
}
$extensions = $this->container->make('Flarum\Extension\ExtensionManager'); $extensions = $this->container->make('Flarum\Extension\ExtensionManager');
$extensions->getMigrator()->setOutput($this->output);
foreach ($extensions->getExtensions() as $name => $extension) { foreach ($extensions->getExtensions() as $name => $extension) {
if (! $extension->isEnabled()) { if (! $extension->isEnabled()) {
@ -76,11 +74,7 @@ class MigrateCommand extends AbstractCommand
$this->info('Migrating extension: '.$name); $this->info('Migrating extension: '.$name);
$notes = $extensions->migrate($extension); $extensions->migrate($extension);
foreach ($notes as $note) {
$this->info($note);
}
} }
$this->container->make('Flarum\Settings\SettingsRepositoryInterface')->set('version', $this->container->version()); $this->container->make('Flarum\Settings\SettingsRepositoryInterface')->set('version', $this->container->version());

View File

@ -16,6 +16,7 @@ use Flarum\Extension\Extension;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Schema\Builder; use Illuminate\Database\Schema\Builder;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Output\OutputInterface;
class Migrator class Migrator
{ {
@ -41,11 +42,11 @@ class Migrator
protected $schemaBuilder; 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. * 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 * @return void
*/ */
protected function note($message) protected function note($message)
{ {
$this->notes[] = $message; if ($this->output) {
} $this->output->writeln($message);
}
/**
* Get the notes for the last operation.
*
* @return array
*/
public function getNotes()
{
return $this->notes;
} }
/** /**

View File

@ -236,11 +236,7 @@ class ExtensionManager
} else { } else {
$this->migrator->reset($migrationDir, $extension); $this->migrator->reset($migrationDir, $extension);
} }
return $this->migrator->getNotes();
} }
return [];
} }
/** /**