Skip to content

Commit 8d2d734

Browse files
committed
Fix issue with Symfony/Console throwing error when empty array is passed to writeln
1 parent ea10929 commit 8d2d734

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

app/sprinkles/core/src/Bakery/MigrateCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use UserFrosting\Sprinkle\Core\Bakery\Helper\ConfirmableTrait;
17+
use UserFrosting\Sprinkle\Core\Database\Migrator\Migrator;
1718
use UserFrosting\System\Bakery\BaseCommand;
1819

1920
/**
@@ -79,13 +80,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
7980
try {
8081
$migrated = $migrator->run(['pretend' => $pretend, 'step' => $step]);
8182
} catch (\Exception $e) {
82-
$this->io->writeln($migrator->getNotes());
83+
$this->displayNotes($migrator);
8384
$this->io->error($e->getMessage());
8485
exit(1);
8586
}
8687

8788
// Get notes and display them
88-
$this->io->writeln($migrator->getNotes());
89+
$this->displayNotes($migrator);
8990

9091
// If all went well, there's no fatal errors and we have migrated
9192
// something, show some success
@@ -128,4 +129,15 @@ protected function setupMigrator(InputInterface $input)
128129

129130
return $migrator;
130131
}
132+
133+
/**
134+
* Display migrator notes
135+
* @param Migrator $migrator
136+
*/
137+
protected function displayNotes(Migrator $migrator)
138+
{
139+
if (!empty($notes = $migrator->getNotes())) {
140+
$this->io->writeln($notes);
141+
}
142+
}
131143
}

app/sprinkles/core/src/Bakery/MigrateRefreshCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171
try {
7272
$rolledback = $migrator->rollback(['pretend' => false, 'steps' => $steps]);
7373
} catch (\Exception $e) {
74-
$this->io->writeln($migrator->getNotes());
74+
$this->displayNotes($migrator);
7575
$this->io->error($e->getMessage());
7676
exit(1);
7777
}
7878

7979
// Get notes and display them
80-
$this->io->writeln($migrator->getNotes());
80+
$this->displayNotes($migrator);
8181

8282
// Stop if nothing was rolledback
8383
if (empty($rolledback)) {
@@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8888

8989
// Run back up again
9090
$migrated = $migrator->run(['pretend' => false, 'step' => false]);
91-
$this->io->writeln($migrator->getNotes());
91+
$this->displayNotes($migrator);
9292

9393
// If all went well, there's no fatal errors and we have migrated
9494
// something, show some success

app/sprinkles/core/src/Bakery/MigrateResetCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ protected function performReset(InputInterface $input)
8787
try {
8888
$resetted = $migrator->reset($pretend);
8989
} catch (\Exception $e) {
90-
$this->io->writeln($migrator->getNotes());
90+
$this->displayNotes($migrator);
9191
$this->io->error($e->getMessage());
9292
exit(1);
9393
}
9494

9595
// Get notes and display them
96-
$this->io->writeln($migrator->getNotes());
96+
$this->displayNotes($migrator);
9797

9898
// Delete the repository
9999
if (!$pretend && $migrator->repositoryExists()) {

app/sprinkles/core/src/Bakery/MigrateRollbackCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
$migrated = $migrator->rollback(['pretend' => $pretend, 'steps' => $steps]);
8181
}
8282
} catch (\Exception $e) {
83-
$this->io->writeln($migrator->getNotes());
83+
$this->displayNotes($migrator);
8484
$this->io->error($e->getMessage());
8585
exit(1);
8686
}
8787

8888
// Get notes and display them
89-
$this->io->writeln($migrator->getNotes());
89+
$this->displayNotes($migrator);
9090

9191
// If all went well, there's no fatal errors and we have migrated
9292
// something, show some success

0 commit comments

Comments
 (0)