/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { $time = microtime(true); $ignoreDataUpdate = $input->getOption('ignore-data'); $headers = array('Setup', 'Module', 'DB', 'Data', 'Status'); if ($ignoreDataUpdate) { unset($headers[array_search('Data', $headers)]); } $errorCounter = 0; $table = array(); foreach ($this->moduleList->getAll() as $moduleName => $moduleInfo) { $moduleVersion = $moduleInfo['setup_version']; $dbVersion = $this->resource->getDbVersion($moduleName); if (!$ignoreDataUpdate) { $dataVersion = $this->resource->getDataVersion($moduleName); } $ok = $dbVersion == $moduleVersion; if ($ok && !$ignoreDataUpdate) { $ok = $dataVersion == $moduleVersion; } if (!$ok) { $errorCounter++; } $row = array('Module' => $moduleName, 'DB' => $dbVersion, 'Data' => $dataVersion); if (!$ignoreDataUpdate) { $row['Data-Version'] = $dataVersion; } $row['Status'] = $ok ? 'OK' : 'Error'; $table[] = $row; } //if there is no output format //highlight the status //and show error'd rows at bottom if (!$input->getOption('format')) { usort($table, function ($a, $b) { return $a['Status'] !== 'OK'; }); array_walk($table, function (&$row) { $status = $row['Status']; $availableStatus = array('OK' => 'info', 'Error' => 'error'); $statusString = sprintf('<%s>%s</%s>', $availableStatus[$status], $status, $availableStatus[$status]); $row['Status'] = $statusString; }); } if ($input->getOption('log-junit')) { $this->logJUnit($table, $input->getOption('log-junit'), microtime($time) - $time); } else { $this->getHelper('table')->setHeaders($headers)->renderByFormat($output, $table, $input->getOption('format')); //if no output format specified - output summary line if (!$input->getOption('format')) { if ($errorCounter > 0) { $this->writeSection($output, sprintf('%s error%s %s found!', $errorCounter, $errorCounter === 1 ? '' : 's', $errorCounter === 1 ? 'was' : 'were'), 'error'); } else { $this->writeSection($output, 'No setup problems were found.', 'info'); } } } }
/** * Get error data for an out-of-date schema or data. * * @param string $moduleName * @return string[] */ private function getDataInfo($moduleName) { $dataVer = $this->moduleResource->getDataVersion($moduleName); $module = $this->moduleList->getOne($moduleName); $configVer = $module['setup_version']; $dataVer = $dataVer ?: 'none'; return [self::KEY_CURRENT => $dataVer, self::KEY_REQUIRED => $configVer, self::KEY_MODULE => $moduleName, self::KEY_TYPE => 'data']; }
/** * Apply data updates to the system after upgrading. * * @return $this */ public function applyDataUpdates() { $dataVer = $this->_resource->getDataVersion($this->_resourceName); $configVer = $this->_moduleConfig['schema_version']; if ($dataVer !== false) { $status = version_compare($configVer, $dataVer); if ($status == self::VERSION_COMPARE_GREATER) { $this->_upgradeData($dataVer, $configVer); } } elseif ($configVer) { $this->_installData($configVer); } return $this; }
/** * @param string $moduleName * @param string $resourceName * @return bool */ public function isDbDataUpToDate($moduleName, $resourceName) { $dataVer = $this->_moduleResource->getDataVersion($resourceName); return $this->isModuleVersionEqual($moduleName, $dataVer); }