Upgrade.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Knuckles\Scribe\Commands;
  3. use Illuminate\Console\Command;
  4. use Shalvah\Upgrader\Upgrader;
  5. class Upgrade extends Command
  6. {
  7. protected $signature = "scribe:upgrade {--dry-run}";
  8. protected $description = '';
  9. public function newLine($count = 1)
  10. {
  11. // TODO Remove when Laravel 6 is no longer supported
  12. $this->getOutput()->write(str_repeat("\n", $count));
  13. }
  14. public function handle(): void
  15. {
  16. $oldConfig = config('scribe');
  17. $upgrader = Upgrader::ofConfigFile('config/scribe.php', __DIR__ . '/../../config/scribe.php')
  18. ->dontTouch('routes', 'laravel.middleware', 'postman.overrides', 'openapi.overrides')
  19. ->move('interactive', 'try_it_out.enabled');
  20. $changes = $upgrader->dryRun();
  21. if (empty($changes)) {
  22. $this->info("No changes needed! Looks like you're all set.");
  23. return;
  24. }
  25. $this->info('The following changes will be made to your config file:');
  26. $this->newLine();
  27. foreach ($changes as $change) {
  28. $this->info($change["description"]);
  29. }
  30. if ($this->option('dry-run')) {
  31. return;
  32. }
  33. $upgrader->upgrade();
  34. if (!empty($oldConfig["continue_without_database_transactions"])) {
  35. $this->warn(
  36. '`continue_without_database_transactions` was deprecated in 2.4.0. Your new config file now uses `database_connections_to_transact`.'
  37. );
  38. }
  39. $this->newLine();
  40. $this->info("✔ Upgraded your config file. Your old config is backed up at config/scribe.php.bak.");
  41. $this->info("Don't forget to check out the changelog or release announcement for new features!");
  42. }
  43. }