示例#1
0
 /**
  * @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;
 }
示例#2
0
 /**
  * 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;
     }
 }
 public function testRemoveModulesFromDeploymentConfig()
 {
     $this->output->expects($this->atLeastOnce())->method('writeln');
     $this->deploymentConfig->expects($this->once())->method('getConfigData')->willReturn(['moduleA' => 1, 'moduleB' => 1, 'moduleC' => 1, 'moduleD' => 1]);
     $this->loader->expects($this->once())->method('load')->willReturn(['moduleC' => [], 'moduleD' => []]);
     $this->writer->expects($this->once())->method('saveConfig')->with([ConfigFilePool::APP_CONFIG => [ConfigOptionsListConstants::KEY_MODULES => ['moduleC' => 1, 'moduleD' => 1]]]);
     $this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($this->output, ['moduleA', 'moduleB']);
 }
示例#4
0
 public function testUpdate()
 {
     $segment = $this->createSegment('key', ['nested_key' => 'value']);
     $preExisting = ['foo' => 'bar', 'key' => 'value', 'baz' => 1];
     $this->reader->expects($this->once())->method('load')->willReturn($preExisting);
     $expected = ['foo' => 'bar', 'key' => ['nested_key' => 'value'], 'baz' => 1];
     $this->formatter->expects($this->once())->method('format')->with($expected)->willReturn('formatted');
     $this->dirWrite->expects($this->once())->method('writeFile')->with('test.php', 'formatted');
     $this->object->update($segment);
 }
 /**
  * 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);
 }
示例#6
0
 public function testChangeEncryptionKeyThrowsException()
 {
     $key = 'key';
     $this->writerMock->expects($this->once())->method('checkIfWritable')->willReturn(false);
     try {
         $this->model->changeEncryptionKey($key);
     } catch (\Exception $e) {
         return;
     }
     $this->fail('An excpected exception was not signaled.');
 }
示例#7
0
 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);
 }
示例#8
0
    /**
     * 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);
    }
示例#9
0
 /**
  * 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;
 }
示例#10
0
 /**
  * @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']]);
 }
    private function setUpExecute($input)
    {
        $this->setUpPassValidation();
        $this->remove->expects($this->once())->method('remove')->with(['magento/package-a', 'magento/package-b']);
        $this->dependencyChecker->expects($this->once())
            ->method('checkDependenciesWhenDisableModules')
            ->willReturn(['Magento_A' => [], 'Magento_B' => []]);
        $this->dataSetup->expects($this->exactly(count($input['module'])))->method('deleteTableRow');
        $this->deploymentConfig->expects($this->once())
            ->method('getConfigData')
            ->with(ConfigOptionsListConstants::KEY_MODULES)
            ->willReturn(['Magento_A' => 1, 'Magento_B' => 1, 'Magento_C' => 0, 'Magento_D' => 1]);

        $this->loader->expects($this->once())
            ->method('load')
            ->with($input['module'])
            ->willReturn(['Magento_C' => [], 'Magento_D' => []]);
        $this->writer->expects($this->once())
            ->method('saveConfig')
            ->with(
                [
                    ConfigFilePool::APP_CONFIG =>
                        [ConfigOptionsListConstants::KEY_MODULES => ['Magento_C' => 0, 'Magento_D' => 1]]
                ]
            );
        $this->cache->expects($this->once())->method('clean');
        $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedClasses');

    }
示例#12
0
 /**
  * Installs deployment configuration
  *
  * @param \ArrayObject|array $data
  * @return void
  */
 public function installDeploymentConfig($data)
 {
     $this->checkInstallationFilePermissions();
     $data[InstallConfig::KEY_DATE] = date('r');
     $configs = [$this->createBackendConfig($data), $this->createDbConfig($data), $this->createEncryptConfig($data), $this->createInstallConfig($data), $this->createSessionConfig($data), new ResourceConfig(), $this->createModulesConfig($data)];
     $this->deploymentConfigWriter->create($configs);
 }
示例#13
0
 public function testProcess()
 {
     $testSet1 = [ConfigFilePool::APP_CONFIG => ['segment' => ['someKey' => 'value', 'test' => 'value1']]];
     $testSet2 = [ConfigFilePool::APP_CONFIG => ['segment' => ['test' => 'value2']]];
     $testSetExpected = [ConfigFilePool::APP_CONFIG => ['segment' => ['someKey' => 'value', 'test' => 'value2']]];
     $configData1 = clone $this->configData;
     $configData2 = clone $this->configData;
     $configData1->expects($this->any())->method('getData')->will($this->returnValue($testSet1[ConfigFilePool::APP_CONFIG]));
     $configData1->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG));
     $configData2->expects($this->any())->method('getData')->will($this->returnValue($testSet2[ConfigFilePool::APP_CONFIG]));
     $configData2->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG));
     $configOption = $this->configOptionsList;
     $configOption->expects($this->once())->method('createConfig')->will($this->returnValue([$configData1, $configData2]));
     $configOptionsList = ['Fake_Module' => $configOption];
     $this->collector->expects($this->once())->method('collectOptionsLists')->will($this->returnValue($configOptionsList));
     $this->writer->expects($this->once())->method('saveConfig')->with($testSetExpected);
     $this->configModel->process([]);
 }
示例#14
0
 /**
  * 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);
 }
示例#15
0
 /**
  * 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
     );
 }
示例#16
0
 /**
  * Prepare mocks for update modules tests and returns the installer to use
  *
  * @return Installer
  */
 private function prepareForUpdateModulesTests()
 {
     $allModules = ['Foo_One' => [], 'Bar_Two' => [], 'New_Module' => []];
     $cacheManager = $this->getMock('Magento\\Framework\\App\\Cache\\Manager', [], [], '', false);
     $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
     $cacheManager->expects($this->once())->method('clean');
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\App\\Cache\\Manager', $cacheManager]]));
     $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
     $expectedModules = [ConfigFilePool::APP_CONFIG => ['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'New_Module' => 1]]];
     $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
     $newObject = $this->createObject(false, false);
     $this->configReader->expects($this->once())->method('load')->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]);
     $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules);
     return $newObject;
 }
示例#17
0
    public function testUpdateModulesSequence()
    {
        $allModules = [
            'Foo_One' => [],
            'Bar_Two' => [],
            'New_Module' => [],
        ];
        $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedClasses')->will(
            $this->returnValue(
                [
                    "The directory '/generation' doesn't exist - skipping cleanup",
                ]
            )
        );

        $cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false);
        $cache->expects($this->once())->method('clean');
        $this->objectManager->expects($this->once())
            ->method('create')
            ->will($this->returnValueMap([
                ['Magento\Framework\App\Cache', [], $cache],
            ]));

        $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);

        $expectedModules = [
            ConfigFilePool::APP_CONFIG => [
                'modules' => [
                    'Bar_Two' => 0,
                    'Foo_One' => 1,
                    'New_Module' => 1
                ]
            ]
        ];

        $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);

        $newObject = $this->createObject(false, false);
        $this->configReader->expects($this->once())->method('load')
            ->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] ]);
        $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules);
        $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully');
        $this->logger->expects($this->at(1))->method('log')->with('File system cleanup:');
        $this->logger->expects($this->at(2))->method('log')
            ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup');
        $this->logger->expects($this->at(3))->method('log')->with('Updating modules:');
        $newObject->updateModulesSequence();
    }
示例#18
0
 /**
  * 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] = $isEnabled;
         } else {
             $result[$name] = $currentStatus;
         }
     }
     $segment = $this->deploymentConfigFactory->create($result);
     $this->writer->update($segment);
     $this->cleanup->clearCaches();
     $this->cleanup->clearCodeGeneratedFiles();
 }
示例#19
0
 public function testUpdateModulesSequence()
 {
     $varDir = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $varDir->expects($this->exactly(2))->method('getAbsolutePath')->willReturn('/var');
     $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->willReturn($varDir);
     $allModules = ['Foo_One' => [], 'Bar_Two' => [], 'New_Module' => []];
     $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
     $expectedModules = ['Bar_Two' => 0, 'Foo_One' => 1, 'New_Module' => 1];
     $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
     $this->deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules)->willReturn($this->deploymentConfig);
     $newObject = $this->createObject(false, false);
     $this->configReader->expects($this->once())->method('load')->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]);
     $this->configWriter->expects($this->once())->method('update')->with($this->deploymentConfig);
     $this->logger->expects($this->at(0))->method('log')->with('File system cleanup:');
     $this->logger->expects($this->at(1))->method('log')->with('The directory \'/var\' doesn\'t exist - skipping cleanup');
     $this->logger->expects($this->at(3))->method('log')->with('Updating modules:');
     $newObject->updateModulesSequence();
 }
示例#20
0
 /**
  * Save the current statuses (enabled/disabled) of cache types to the persistent storage
  *
  * @return void
  */
 public function persist()
 {
     $this->load();
     $segment = new ConfigSegment($this->statuses);
     $this->writer->update($segment);
 }
示例#21
0
 /**
  * Updates modules in deployment configuration
  *
  * @return void
  */
 public function updateModulesSequence()
 {
     $this->assertDeploymentConfigExists();
     $this->log->log('File system cleanup:');
     $this->deleteDirContents(DirectoryList::GENERATION);
     $this->deleteDirContents(DirectoryList::CACHE);
     $this->log->log('Updating modules:');
     $allModules = array_keys($this->moduleLoader->load());
     $deploymentConfig = $this->deploymentConfigReader->load();
     $currentModules = isset($deploymentConfig['modules']) ? $deploymentConfig['modules'] : [];
     $result = [];
     foreach ($allModules as $module) {
         if (isset($currentModules[$module]) && !$currentModules[$module]) {
             $result[$module] = 0;
         } else {
             $result[$module] = 1;
         }
     }
     $segment = $this->deploymentConfigFactory->create($result);
     $this->deploymentConfigWriter->update($segment);
 }
示例#22
0
 /**
  * Removes deployment configuration
  *
  * @return void
  */
 private function deleteDeploymentConfig()
 {
     $configDir = $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG);
     $configFiles = $this->deploymentConfigReader->getFiles();
     foreach ($configFiles as $configFile) {
         $absolutePath = $configDir->getAbsolutePath($configFile);
         if (!$configDir->isFile($configFile)) {
             $this->log->log("The file '{$absolutePath}' doesn't exist - skipping cleanup");
             continue;
         }
         try {
             $this->log->log($absolutePath);
             $configDir->delete($configFile);
         } catch (FileSystemException $e) {
             $this->log->log($e->getMessage());
         }
     }
 }
 /**
  * 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;
 }
示例#24
0
 /**
  * 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]]);
 }
示例#25
0
 /**
  * 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);
 }