Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpgradeCommand.php
Go to the documentation of this file.
1 <?php
7 
16 use Symfony\Component\Console\Input\ArrayInput;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Input\InputOption;
19 use Symfony\Component\Console\Output\OutputInterface;
20 
26 {
30  const INPUT_KEY_KEEP_GENERATED = 'keep-generated';
31 
37  private $installerFactory;
38 
42  private $deploymentConfig;
43 
47  private $appState;
48 
54  public function __construct(
55  InstallerFactory $installerFactory,
56  DeploymentConfig $deploymentConfig = null,
57  AppState $appState = null
58  ) {
59  $this->installerFactory = $installerFactory;
60  $this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
61  $this->appState = $appState ?: ObjectManager::getInstance()->get(AppState::class);
62  parent::__construct();
63  }
64 
68  protected function configure()
69  {
70  $options = [
71  new InputOption(
72  self::INPUT_KEY_KEEP_GENERATED,
73  null,
74  InputOption::VALUE_NONE,
75  'Prevents generated files from being deleted. ' . PHP_EOL .
76  'We discourage using this option except when deploying to production. ' . PHP_EOL .
77  'Consult your system integrator or administrator for more information.'
78  ),
79  new InputOption(
81  null,
82  InputOption::VALUE_OPTIONAL,
83  'Allows to convert old scripts (InstallSchema, UpgradeSchema) to db_schema.xml format',
84  false
85  ),
86  new InputOption(
88  null,
89  InputOption::VALUE_OPTIONAL,
90  'Safe installation of Magento with dumps on destructive operations, like column removal'
91  ),
92  new InputOption(
94  null,
95  InputOption::VALUE_OPTIONAL,
96  'Restore removed data from dumps'
97  ),
98  new InputOption(
100  null,
101  InputOption::VALUE_OPTIONAL,
102  'Magento Installation will be run in dry-run mode',
103  false
104  )
105  ];
106  $this->setName('setup:upgrade')
107  ->setDescription('Upgrades the Magento application, DB data, and schema')
108  ->setDefinition($options);
109  parent::configure();
110  }
111 
115  protected function execute(InputInterface $input, OutputInterface $output)
116  {
117  try {
118  $request = $input->getOptions();
119  $keepGenerated = $input->getOption(self::INPUT_KEY_KEEP_GENERATED);
120  $installer = $this->installerFactory->create(new ConsoleLogger($output));
121  $installer->updateModulesSequence($keepGenerated);
122  $installer->installSchema($request);
123  $installer->installDataFixtures($request);
124 
125  if ($this->deploymentConfig->isAvailable()) {
126  $importConfigCommand = $this->getApplication()->find(ConfigImportCommand::COMMAND_NAME);
127  $arrayInput = new ArrayInput([]);
128  $arrayInput->setInteractive($input->isInteractive());
129  $importConfigCommand->run($arrayInput, $output);
130  }
131 
132  if (!$keepGenerated && $this->appState->getMode() === AppState::MODE_PRODUCTION) {
133  $output->writeln(
134  '<info>Please re-run Magento compile command. Use the command "setup:di:compile"</info>'
135  );
136  }
137  } catch (\Exception $e) {
138  $output->writeln($e->getMessage());
139  return \Magento\Framework\Console\Cli::RETURN_FAILURE;
140  }
141 
142  return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
143  }
144 }
__construct(InstallerFactory $installerFactory, DeploymentConfig $deploymentConfig=null, AppState $appState=null)
execute(InputInterface $input, OutputInterface $output)