encoder = $encoder; $this->config = $config; $this->decoder = $decoder; $this->moduleReader = $moduleReader; $this->file = $file; $this->scopeConfig = $scopeConfig; } /** * Move config from srcPath to dstPath * @param ModuleDataSetupInterface $setup * @param string $srcPath * @param string $dstPath */ private function moveConfig(ModuleDataSetupInterface $setup, $srcPath, $dstPath) { $value = $this->scopeConfig->getValue($srcPath); if (is_array($value)) { foreach (array_keys($value) as $k) { $this->moveConfig($setup, $srcPath . '/' . $k, $dstPath . '/' . $k); } } else { $connection = $setup->getConnection(); $configData = $setup->getTable('core_config_data'); $connection->update($configData, ['path' => $dstPath], 'path='.$connection->quote($srcPath)); } } private function upgradeTo010200(ModuleDataSetupInterface $setup) { $this->moveConfig( $setup, 'msp_securitysuite/twofactorauth/allow_trusted_devices', 'msp_securitysuite_twofactorauth/google/allow_trusted_devices' ); $this->moveConfig( $setup, 'msp_securitysuite/twofactorauth', 'msp_securitysuite_twofactorauth/general' ); // Generate random duo security key $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < 64; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } $this->config->saveConfig(DuoSecurity::XML_PATH_APPLICATION_KEY, $randomString, 'default', 0); } private function upgradeTo020000(ModuleDataSetupInterface $setup) { $this->moveConfig( $setup, 'msp_securitysuite_twofactorauth/general/force_provider', 'msp_securitysuite_twofactorauth/general/force_provider_0' ); } private function upgradeTo020001(ModuleDataSetupInterface $setup) { $connection = $setup->getConnection(); $tableName = $setup->getTable('msp_tfa_country_codes'); $countryCodesJsonFile = $this->moduleReader->getModuleDir(false, 'MSP_TwoFactorAuth') . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'country_codes.json'; $countryCodesJson = $this->file->read($countryCodesJsonFile); $countryCodes = $this->decoder->decode(trim($countryCodesJson)); // @codingStandardsIgnoreStart foreach ($countryCodes as $countryCode) { $connection->insert($tableName, $countryCode); } // @codingStandardsIgnoreEnd } /** * Upgrades data for a module * * @param ModuleDataSetupInterface $setup * @param ModuleContextInterface $context * @return void */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); if (version_compare($context->getVersion(), '1.2.0') < 0) { $this->upgradeTo010200($setup); } if (version_compare($context->getVersion(), '2.0.0') < 0) { $this->upgradeTo020000($setup); } if (version_compare($context->getVersion(), '2.0.1') < 0) { $this->upgradeTo020001($setup); } $setup->endSetup(); } }