diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index 0f1120687..7435a74d1 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -31,11 +31,15 @@ class UpdateManager use \October\Rain\Support\Traits\Singleton; /** - * The notes for the current operation. - * @var array + * @var array The notes for the current operation. */ protected $notes = []; + /** + * @var \Illuminate\Console\OutputStyle + */ + protected $notesOutput; + /** * @var string Application base path. */ @@ -365,9 +369,11 @@ class UpdateManager $this->migrator->run(base_path() . '/modules/'.strtolower($module).'/database/migrations'); $this->note($module); + foreach ($this->migrator->getNotes() as $note) { $this->note(' - '.$note); } + return $this; } @@ -466,13 +472,17 @@ class UpdateManager return; } - $this->versionManager->resetNotes(); + $this->note($name); + + $this->versionManager->resetNotes()->setNotesOutput($this->notesOutput); + if ($this->versionManager->updatePlugin($plugin) !== false) { - $this->note($name); + foreach ($this->versionManager->getNotes() as $note) { - $this->note(' - '.$note); + $this->note($note); } } + return $this; } @@ -689,11 +699,17 @@ class UpdateManager /** * Raise a note event for the migrator. * @param string $message - * @return void + * @return self */ protected function note($message) { - $this->notes[] = $message; + if ($this->notesOutput !== null) { + $this->notesOutput->writeln($message); + } + else { + $this->notes[] = $message; + } + return $this; } @@ -708,11 +724,26 @@ class UpdateManager /** * Resets the notes store. - * @return array + * @return self */ public function resetNotes() { + $this->notesOutput = null; + $this->notes = []; + + return $this; + } + + /** + * Sets an output stream for writing notes. + * @param Illuminate\Console\Command $output + * @return self + */ + public function setNotesOutput($output) + { + $this->notesOutput = $output; + return $this; } diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index 05576e27e..be19b3a2f 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -36,6 +36,11 @@ class VersionManager */ protected $notes = []; + /** + * @var \Illuminate\Console\OutputStyle + */ + protected $notesOutput; + /** * Cache of plugin versions as files. */ @@ -85,7 +90,7 @@ class VersionManager // No updates needed if ($currentVersion == $databaseVersion) { - $this->note('Nothing to update.'); + $this->note('- Nothing to update.'); return; } @@ -150,7 +155,7 @@ class VersionManager $this->setDatabaseVersion($code, $version); - $this->note(sprintf('v%s: %s', $version, $comment)); + $this->note(sprintf('- v%s: %s', $version, $comment)); } /** @@ -471,7 +476,13 @@ class VersionManager */ protected function note($message) { - $this->notes[] = $message; + if ($this->notesOutput !== null) { + $this->notesOutput->writeln($message); + } + else { + $this->notes[] = $message; + } + return $this; } @@ -486,11 +497,26 @@ class VersionManager /** * Resets the notes store. - * @return array + * @return self */ public function resetNotes() { + $this->notesOutput = null; + $this->notes = []; + + return $this; + } + + /** + * Sets an output stream for writing notes. + * @param Illuminate\Console\Command $output + * @return self + */ + public function setNotesOutput($output) + { + $this->notesOutput = $output; + return $this; } } diff --git a/modules/system/console/OctoberDown.php b/modules/system/console/OctoberDown.php index acb7595cd..fbaf42997 100644 --- a/modules/system/console/OctoberDown.php +++ b/modules/system/console/OctoberDown.php @@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputArgument; */ class OctoberDown extends Command { - use \Illuminate\Console\ConfirmableTrait; /** @@ -45,11 +44,10 @@ class OctoberDown extends Command return; } - $manager = UpdateManager::instance()->resetNotes()->uninstall(); - - foreach ($manager->getNotes() as $note) { - $this->output->writeln($note); - } + UpdateManager::instance() + ->setNotesOutput($this->output) + ->uninstall() + ; } /** diff --git a/modules/system/console/OctoberInstall.php b/modules/system/console/OctoberInstall.php index 31badc7fa..4554a3f60 100644 --- a/modules/system/console/OctoberInstall.php +++ b/modules/system/console/OctoberInstall.php @@ -291,7 +291,11 @@ class OctoberInstall extends Command try { Db::purge(); - UpdateManager::instance()->resetNotes()->update(); + + UpdateManager::instance() + ->setNotesOutput($this->output) + ->update() + ; } catch (Exception $ex) { $this->error($ex->getMessage()); diff --git a/modules/system/console/OctoberUp.php b/modules/system/console/OctoberUp.php index b5a02e17a..bce7b1506 100644 --- a/modules/system/console/OctoberUp.php +++ b/modules/system/console/OctoberUp.php @@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputArgument; */ class OctoberUp extends Command { - /** * The console command name. */ @@ -39,13 +38,12 @@ class OctoberUp extends Command */ public function fire() { - $manager = UpdateManager::instance()->resetNotes()->update(); - $this->output->writeln('Migrating application and plugins...'); - foreach ($manager->getNotes() as $note) { - $this->output->writeln($note); - } + UpdateManager::instance() + ->setNotesOutput($this->output) + ->update() + ; } /** diff --git a/modules/system/console/OctoberUpdate.php b/modules/system/console/OctoberUpdate.php index 7a40e7214..b5186c5e7 100644 --- a/modules/system/console/OctoberUpdate.php +++ b/modules/system/console/OctoberUpdate.php @@ -44,7 +44,7 @@ class OctoberUpdate extends Command public function fire() { $this->output->writeln('Updating October...'); - $manager = UpdateManager::instance()->resetNotes(); + $manager = UpdateManager::instance()->setNotesOutput($this->output); $forceUpdate = $this->option('force'); /* @@ -66,7 +66,7 @@ class OctoberUpdate extends Command * Perform update */ $updateList = $manager->requestUpdateList($forceUpdate); - $updates = (int)array_get($updateList, 'update', 0); + $updates = (int) array_get($updateList, 'update', 0); if ($updates == 0) { $this->output->writeln('No new updates found'); diff --git a/modules/system/console/PluginInstall.php b/modules/system/console/PluginInstall.php index 546c1cab9..49e62f40d 100644 --- a/modules/system/console/PluginInstall.php +++ b/modules/system/console/PluginInstall.php @@ -45,7 +45,7 @@ class PluginInstall extends Command public function fire() { $pluginName = $this->argument('name'); - $manager = UpdateManager::instance()->resetNotes(); + $manager = UpdateManager::instance()->setNotesOutput($this->output); $pluginDetails = $manager->requestPluginDetails($pluginName); @@ -64,10 +64,6 @@ class PluginInstall extends Command $this->output->writeln(sprintf('Migrating plugin...', $code)); PluginManager::instance()->loadPlugins(); $manager->updatePlugin($code); - - foreach ($manager->getNotes() as $note) { - $this->output->writeln($note); - } } /** diff --git a/modules/system/console/PluginRefresh.php b/modules/system/console/PluginRefresh.php index 7358e1729..5888da71a 100644 --- a/modules/system/console/PluginRefresh.php +++ b/modules/system/console/PluginRefresh.php @@ -45,26 +45,27 @@ class PluginRefresh extends Command */ public function fire() { + /* + * Lookup plugin + */ $pluginName = $this->argument('name'); $pluginName = PluginManager::instance()->normalizeIdentifier($pluginName); if (!PluginManager::instance()->exists($pluginName)) { throw new \InvalidArgumentException(sprintf('Plugin "%s" not found.', $pluginName)); } - $manager = UpdateManager::instance()->resetNotes(); + $manager = UpdateManager::instance()->setNotesOutput($this->output); + /* + * Rollback plugin + */ $manager->rollbackPlugin($pluginName); - foreach ($manager->getNotes() as $note) { - $this->output->writeln($note); - } - $manager->resetNotes(); + /* + * Update plugin + */ $this->output->writeln('Reinstalling plugin...'); $manager->updatePlugin($pluginName); - - foreach ($manager->getNotes() as $note) { - $this->output->writeln($note); - } } /** diff --git a/modules/system/console/PluginRemove.php b/modules/system/console/PluginRemove.php index df2d743c4..e256f3938 100644 --- a/modules/system/console/PluginRemove.php +++ b/modules/system/console/PluginRemove.php @@ -63,13 +63,9 @@ class PluginRemove extends Command /* * Rollback plugin */ - $manager = UpdateManager::instance()->resetNotes(); + $manager = UpdateManager::instance()->setNotesOutput($this->output); $manager->rollbackPlugin($pluginName); - foreach ($manager->getNotes() as $note) { - $this->output->writeln($note); - } - /* * Delete from file system */