/**
  * @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');
             }
         }
     }
 }
 /**
  * Check if DB schema is up to date, version info if it is not.
  *
  * @param string $moduleName
  * @return string[] Contains current and needed version strings
  */
 private function getSchemaInfo($moduleName)
 {
     $dbVer = $this->moduleResource->getDbVersion($moduleName);
     // version saved in DB
     $module = $this->moduleList->getOne($moduleName);
     $configVer = $module['setup_version'];
     $dbVer = $dbVer ?: 'none';
     return [self::KEY_CURRENT => $dbVer, self::KEY_REQUIRED => $configVer, self::KEY_MODULE => $moduleName, self::KEY_TYPE => 'schema'];
 }
Beispiel #3
0
 /**
  * Check if DB schema is up to date
  *
  * @param string $moduleName
  * @param string $resourceName
  * @return bool
  */
 public function isDbSchemaUpToDate($moduleName, $resourceName)
 {
     $dbVer = $this->_moduleResource->getDbVersion($resourceName);
     return $this->isModuleVersionEqual($moduleName, $dbVer);
 }
Beispiel #4
0
 /**
  * Apply module resource install, upgrade and data scripts
  *
  * @return $this|true
  */
 public function applyUpdates()
 {
     $dbVer = $this->_resourceResource->getDbVersion($this->_resourceName);
     $configVer = $this->_moduleConfig['schema_version'];
     // Module is installed
     if ($dbVer !== false) {
         $status = version_compare($configVer, $dbVer);
         switch ($status) {
             case self::VERSION_COMPARE_LOWER:
                 $this->_rollbackResourceDb($configVer, $dbVer);
                 break;
             case self::VERSION_COMPARE_GREATER:
                 $this->_upgradeResourceDb($dbVer, $configVer);
                 break;
             default:
                 return true;
                 break;
         }
     } elseif ($configVer) {
         $this->_installResourceDb($configVer);
     }
     return $this;
 }