/** * @return bool * @throws \Exception */ public function disableDbProfiler() { $env = $this->deploymentConfigReader->load(ConfigFilePool::APP_ENV); unset($env['db']['connection']['default']['profiler']); $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $env], true); return true; }
/** * Removes module from deployment configuration * * @param OutputInterface $output * @param string[] $modules * @return void */ public function removeModulesFromDeploymentConfig(OutputInterface $output, array $modules) { $output->writeln('<info>Removing ' . implode(', ', $modules) . ' from module list in deployment configuration</info>'); $configuredModules = $this->deploymentConfig->getConfigData(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES); $existingModules = $this->loader->load($modules); $newModules = []; foreach (array_keys($existingModules) as $module) { $newModules[$module] = isset($configuredModules[$module]) ? $configuredModules[$module] : 0; } $this->writer->saveConfig([\Magento\Framework\Config\File\ConfigFilePool::APP_CONFIG => [\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES => $newModules]], true); }
public function testSaveConfigOverride() { $configFiles = [ConfigFilePool::APP_CONFIG => 'test_conf.php', 'test_key' => 'test2_conf.php']; $testSetExisting = [ConfigFilePool::APP_CONFIG => ['foo' => 'bar', 'key' => 'value', 'baz' => ['test' => 'value', 'test1' => 'value1']]]; $testSetUpdate = [ConfigFilePool::APP_CONFIG => ['baz' => ['test' => 'value2']]]; $testSetExpected = [ConfigFilePool::APP_CONFIG => ['foo' => 'bar', 'key' => 'value', 'baz' => ['test' => 'value2']]]; $this->deploymentConfig->expects($this->once())->method('resetData'); $this->configFilePool->expects($this->once())->method('getPaths')->willReturn($configFiles); $this->dirWrite->expects($this->any())->method('isExist')->willReturn(true); $this->reader->expects($this->once())->method('load')->willReturn($testSetExisting[ConfigFilePool::APP_CONFIG]); $this->formatter->expects($this->once())->method('format')->with($testSetExpected[ConfigFilePool::APP_CONFIG])->willReturn([]); $this->dirWrite->expects($this->once())->method('writeFile')->with('test_conf.php', []); $this->object->saveConfig($testSetUpdate, true); }
/** * Change encryption key * * @param string|null $key * @return null|string * @throws \Exception */ public function changeEncryptionKey($key = null) { // prepare new key, encryptor and new configuration segment if (!$this->writer->checkIfWritable()) { throw new \Exception(__('Deployment configuration file is not writable.')); } if (null === $key) { $key = md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE)); } $this->encryptor->setNewKey($key); $encryptSegment = new ConfigData(ConfigFilePool::APP_ENV); $encryptSegment->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $this->encryptor->exportKeys()); $configData = [$encryptSegment->getFileKey() => $encryptSegment->getData()]; // update database and config.php $this->beginTransaction(); try { $this->_reEncryptSystemConfigurationValues(); $this->_reEncryptCreditCardNumbers(); $this->writer->saveConfig($configData); $this->commit(); return $key; } catch (\Exception $e) { $this->rollBack(); throw $e; } }
/** * Process input options * * @param array $inputOptions * @return void * @throws \Exception */ public function process($inputOptions) { $this->checkInstallationFilePermissions(); $fileConfigStorage = []; $options = $this->collector->collectOptionsLists(); foreach ($options as $moduleName => $option) { $configData = $option->createConfig($inputOptions, $this->deploymentConfig); foreach ($configData as $config) { if (!$config instanceof ConfigData) { throw new \Exception( 'In module : ' . $moduleName . 'ConfigOption::createConfig should return an array of ConfigData instances' ); } if (isset($fileConfigStorage[$config->getFileKey()])) { $fileConfigStorage[$config->getFileKey()] = array_replace_recursive( $fileConfigStorage[$config->getFileKey()], $config->getData() ); } else { $fileConfigStorage[$config->getFileKey()] = $config->getData(); } } } $this->writer->saveConfig($fileConfigStorage); }
/** * Creates modules deployment configuration segment * * @param \ArrayObject|array $request * @return array * @throws \LogicException */ private function createModulesConfig($request) { $all = array_keys($this->moduleLoader->load()); $currentModules = []; if ($this->deploymentConfig->isAvailable()) { $deploymentConfig = $this->deploymentConfigReader->load(); $currentModules = isset($deploymentConfig['modules']) ? $deploymentConfig['modules'] : []; } $enable = $this->readListOfModules($all, $request, self::ENABLE_MODULES); $disable = $this->readListOfModules($all, $request, self::DISABLE_MODULES); $result = []; foreach ($all as $module) { if (isset($currentModules[$module]) && !$currentModules[$module]) { $result[$module] = 0; } else { $result[$module] = 1; } if (in_array($module, $disable)) { $result[$module] = 0; } if (in_array($module, $enable)) { $result[$module] = 1; } } $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true); return $result; }
/** * @expectedException \Magento\Framework\Exception\FileSystemException * @expectedExceptionMessage Deployment config file env.php is not writable. */ public function testSaveConfigException() { $this->configFilePool->method('getPaths')->willReturn([ConfigFilePool::APP_ENV => 'env.php']); $exception = new FileSystemException(new Phrase('error when writing file config file')); $this->dirWrite->method('writeFile')->willThrowException($exception); $this->object->saveConfig([ConfigFilePool::APP_ENV => ['key' => 'value']]); }
/** * Sets specified modules to enabled or disabled state * * Performs other necessary routines, such as cache cleanup * * @param bool $isEnabled * @param string[] $modules * @return void */ public function setIsEnabled($isEnabled, $modules) { $result = []; foreach ($this->getAllModules($modules) as $name) { $currentStatus = $this->list->has($name); if (in_array($name, $modules)) { $result[$name] = (int) $isEnabled; } else { $result[$name] = (int) $currentStatus; } } $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true); }
/** * Removes module from deployment configuration * * @param string[] $modules * @return void */ private function removeModulesFromDeploymentConfig(array $modules) { $existingModules = $this->deploymentConfig->getConfigData(ConfigOptionsListConstants::KEY_MODULES); $newSort = $this->loader->load($modules); $newModules = []; foreach (array_keys($newSort) as $module) { $newModules[$module] = $existingModules[$module]; } $this->writer->saveConfig( [ConfigFilePool::APP_CONFIG => [ConfigOptionsListConstants::KEY_MODULES => $newModules]], true ); }
/** * Save the current statuses (enabled/disabled) of cache types to the persistent storage * * @return void */ public function persist() { $this->load(); $this->writer->saveConfig([ConfigFilePool::APP_ENV => [self::CACHE_KEY => $this->statuses]]); }
/** * Store mode in env.php * * @param string $mode * @return void */ protected function setStoreMode($mode) { $data = [ConfigFilePool::APP_ENV => [State::PARAM_MODE => $mode]]; $this->writer->saveConfig($data); }
/** * Creates modules deployment configuration segment * * @param \ArrayObject|array $request * @param bool $dryRun * @return array * @throws \LogicException */ private function createModulesConfig($request, $dryRun = false) { $all = array_keys($this->moduleLoader->load()); $deploymentConfig = $this->deploymentConfigReader->load(); $currentModules = isset($deploymentConfig[ConfigOptionsListConstants::KEY_MODULES]) ? $deploymentConfig[ConfigOptionsListConstants::KEY_MODULES] : [] ; $enable = $this->readListOfModules($all, $request, self::ENABLE_MODULES); $disable = $this->readListOfModules($all, $request, self::DISABLE_MODULES); $result = []; foreach ($all as $module) { if ((isset($currentModules[$module]) && !$currentModules[$module])) { $result[$module] = 0; } else { $result[$module] = 1; } if (in_array($module, $disable)) { $result[$module] = 0; } if (in_array($module, $enable)) { $result[$module] = 1; } } if (!$dryRun) { $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true); } return $result; }