ConfigStatusCommand.php 1.71 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Deploy\Console\Command\App;

use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Command for checking if Config propagation is up to date
 */
class ConfigStatusCommand extends Command
{
    /**
     * Code for error when config import is required.
     */
    const EXIT_CODE_CONFIG_IMPORT_REQUIRED = 2;

    /**
     * @var ChangeDetector
     */
    private $changeDetector;

    /**
     * ConfigStatusCommand constructor.
     * @param ChangeDetector $changeDetector
     */
    public function __construct(ChangeDetector $changeDetector)
    {
        $this->changeDetector = $changeDetector;
        parent::__construct();
    }

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->setName('app:config:status')
            ->setDescription('Checks if config propagation requires update');
        parent::configure();
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($this->changeDetector->hasChanges()) {
            $output->writeln(
                '<info>Config files have changed. ' .
                'Run app:config:import or setup:upgrade command to synchronize configuration.</info>'
            );
            return self::EXIT_CODE_CONFIG_IMPORT_REQUIRED;
        }
        $output->writeln('<info>Config files are up to date.</info>');
        return Cli::RETURN_SUCCESS;
    }
}