objectManagerProvider = $objectManagerProvider; $this->deploymentConfig = $deploymentConfig; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this->setName('setup:db:status') ->setDescription('Checks if DB schema or data requires upgrade'); parent::configure(); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("No information is available: the Magento application is not installed."); return; } /** @var DbVersionInfo $dbVersionInfo */ $dbVersionInfo = $this->objectManagerProvider->get() ->get('Magento\Framework\Module\DbVersionInfo'); $outdated = $dbVersionInfo->getDbVersionErrors(); if (!empty($outdated)) { $output->writeln("The module code base doesn't match the DB schema and data."); $versionParser = new VersionParser(); $codebaseUpdateNeeded = false; foreach ($outdated as $row) { if (!$codebaseUpdateNeeded && $row[DbVersionInfo::KEY_CURRENT] !== 'none') { // check if module code base update is needed $currentVersion = $versionParser->parseConstraints($row[DbVersionInfo::KEY_CURRENT]); $requiredVersion = $versionParser->parseConstraints('>' . $row[DbVersionInfo::KEY_REQUIRED]); if ($requiredVersion->matches($currentVersion)) { $codebaseUpdateNeeded = true; }; } $output->writeln(sprintf( "%20s %10s: %11s -> %-11s", $row[DbVersionInfo::KEY_MODULE], $row[DbVersionInfo::KEY_TYPE], $row[DbVersionInfo::KEY_CURRENT], $row[DbVersionInfo::KEY_REQUIRED] )); } if ($codebaseUpdateNeeded) { $output->writeln( 'Some modules use code versions newer or older than the database. ' . "First update the module code, then run 'setup:upgrade'." ); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } else { $output->writeln("Run 'setup:upgrade' to update your DB schema and data."); } } else { $output->writeln('All modules are up to date.'); } } }