/** * Run module modification files. Return version of last applied upgrade (false if no upgrades applied) * @param string $actionType * @param string $fromVersion * @param string $toVersion * @return false|string * @throws \Exception */ protected function applySchemaUpdates($actionType, $fromVersion, $toVersion) { $files = $this->getAvailableDbFiles($actionType, $fromVersion, $toVersion); if (empty($files) || !$this->getConnection()) { return false; } $version = false; foreach ($files as $file) { $fileName = $file['fileName']; $fileType = pathinfo($fileName, PATHINFO_EXTENSION); try { switch ($fileType) { case 'php': $result = $this->includeFile($fileName); break; default: $result = false; break; } if ($result) { $this->resource->setDbVersion($this->resourceName, $file['toVersion']); //@todo log } else { //@todo log "Failed resource setup: {$fileName}"; } } catch (\Exception $e) { throw new \Exception(sprintf('Error in file: "%s" - %s', $fileName, $e->getMessage()), 0, $e); } $version = $file['toVersion']; } return $version; }
/** * Generates list of ModuleContext * * @param \Magento\Framework\Module\Resource $resource * @param string $type * @return ModuleContext[] * @throws \Magento\Setup\Exception */ private function generateListOfModuleContext($resource, $type) { $moduleContextList = []; foreach ($this->moduleList->getNames() as $moduleName) { if ($type === 'schema-version') { $dbVer = $resource->getDbVersion($moduleName); } elseif ($type === 'data-version') { $dbVer = $resource->getDataVersion($moduleName); } else { throw new \Magento\Setup\Exception("Unsupported version type {$type} is requested"); } if ($dbVer !== false) { $moduleContextList[$moduleName] = new ModuleContext($dbVer); } else { $moduleContextList[$moduleName] = new ModuleContext(''); } } return $moduleContextList; }
/** * Invoke remove data routine in each specified module * * @param string[] $modules * @param OutputInterface $output * @param bool $dbBackupOption * @return void */ private function removeData(array $modules, OutputInterface $output, $dbBackupOption) { if (!$dbBackupOption) { $output->writeln('<error>You are removing data without a database backup.</error>'); } else { $output->writeln('<info>Removing data</info>'); } $uninstalls = $this->collector->collectUninstall(); $setupModel = $this->objectManager->get('Magento\Setup\Module\Setup'); foreach ($modules as $module) { if (isset($uninstalls[$module])) { $output->writeln("<info>Removing data of $module</info>"); $uninstalls[$module]->uninstall( $setupModel, new ModuleContext($this->moduleResource->getDbVersion($module) ?: '') ); } else { $output->writeln("<info>No data to clear in $module</info>"); } } }