ConfigStatusCommand.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Console\Command\App;
  7. use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
  8. use Magento\Framework\Console\Cli;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. /**
  13. * Command for checking if Config propagation is up to date
  14. */
  15. class ConfigStatusCommand extends Command
  16. {
  17. /**
  18. * Code for error when config import is required.
  19. */
  20. const EXIT_CODE_CONFIG_IMPORT_REQUIRED = 2;
  21. /**
  22. * @var ChangeDetector
  23. */
  24. private $changeDetector;
  25. /**
  26. * ConfigStatusCommand constructor.
  27. * @param ChangeDetector $changeDetector
  28. */
  29. public function __construct(ChangeDetector $changeDetector)
  30. {
  31. $this->changeDetector = $changeDetector;
  32. parent::__construct();
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected function configure()
  38. {
  39. $this->setName('app:config:status')
  40. ->setDescription('Checks if config propagation requires update');
  41. parent::configure();
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. protected function execute(InputInterface $input, OutputInterface $output)
  47. {
  48. if ($this->changeDetector->hasChanges()) {
  49. $output->writeln(
  50. '<info>Config files have changed. ' .
  51. 'Run app:config:import or setup:upgrade command to synchronize configuration.</info>'
  52. );
  53. return self::EXIT_CODE_CONFIG_IMPORT_REQUIRED;
  54. }
  55. $output->writeln('<info>Config files are up to date.</info>');
  56. return Cli::RETURN_SUCCESS;
  57. }
  58. }