public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config->get('config_files.config');
     $config->set('directory', $form_state->getValue('directory'));
     $config->save();
     $active_dir = $config->get('directory');
     foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
         $yml = Yaml::dump($this->configManager->getConfigFactory()->get($name)->getRawData());
         $file_name = $name . '.yml';
         file_put_contents($active_dir . '/' . $file_name, $yml, FILE_EXISTS_REPLACE);
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $directory = $input->getOption('directory');
     $tar = $input->getOption('tar');
     $removeUuid = $input->getOption('remove-uuid');
     if (!$directory) {
         $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     }
     if ($tar) {
         if (!is_dir($directory)) {
             mkdir($directory, 0777, true);
         }
         $dateTime = new \DateTime();
         $archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s'));
         $archiveTar = new ArchiveTar($archiveFile, 'gz');
     }
     try {
         // Get raw configuration data without overrides.
         foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
             $configData = $this->configManager->getConfigFactory()->get($name)->getRawData();
             $configName = sprintf('%s.yml', $name);
             // The _core is site-specific, so don't export it.
             unset($configData['_core']);
             if ($removeUuid) {
                 unset($configData['uuid']);
             }
             $ymlData = Yaml::encode($configData);
             if ($tar) {
                 $archiveTar->addString($configName, $ymlData);
                 continue;
             }
             $configFileName = sprintf('%s/%s', $directory, $configName);
             $fileSystem = new Filesystem();
             try {
                 $fileSystem->mkdir($directory);
             } catch (IOExceptionInterface $e) {
                 $io->error(sprintf($this->trans('commands.config.export.messages.error'), $e->getPath()));
             }
             file_put_contents($configFileName, $ymlData);
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
     }
     $io->info(sprintf($this->trans('commands.config.export.messages.directory'), $directory));
 }
 /**
  * @covers ::createChangelist
  */
 public function testCreateChangelistUpdate()
 {
     $target_data = $source_data = $this->getConfigData();
     $source_data['system.site']['title'] = 'Drupal New!';
     $source_data['field.instance.node.article.body']['new_config_key'] = 'new data';
     $source_data['field.storage.node.body']['new_config_key'] = 'new data';
     $this->sourceStorage->expects($this->once())->method('listAll')->will($this->returnValue(array_keys($source_data)));
     $this->targetStorage->expects($this->once())->method('listAll')->will($this->returnValue(array_keys($target_data)));
     $this->sourceStorage->expects($this->once())->method('readMultiple')->will($this->returnValue($source_data));
     $this->targetStorage->expects($this->once())->method('readMultiple')->will($this->returnValue($target_data));
     $this->sourceStorage->expects($this->once())->method('getAllCollectionNames')->will($this->returnValue(array()));
     $this->targetStorage->expects($this->once())->method('getAllCollectionNames')->will($this->returnValue(array()));
     $this->configManager->expects($this->any())->method('supportsConfigurationEntities')->will($this->returnValue(TRUE));
     $this->storageComparer->createChangelist();
     $expected = array('field.storage.node.body', 'system.site', 'field.instance.node.article.body');
     $this->assertEquals($expected, $this->storageComparer->getChangelist('update'));
     $this->assertEmpty($this->storageComparer->getChangelist('create'));
     $this->assertEmpty($this->storageComparer->getChangelist('delete'));
 }
示例#4
0
 protected function getStorageDependentConfigs(StorageInterface $storage)
 {
     static $dependents = [];
     $storage_id = spl_object_hash($storage);
     if (!isset($dependents[$storage_id])) {
         // We cannot use the service config.manager because it depends on the
         // active storage.
         $manager = new ConfigManager(\Drupal::service('entity.manager'), new ConfigFactory($storage, \Drupal::service('event_dispatcher'), new TypedConfigManager($storage, new ExtensionInstallStorage($storage, 'config/schema'), \Drupal::service('cache.discovery'), \Drupal::service('module_handler'))), \Drupal::service('config.typed'), \Drupal::service('string_translation'), $storage, \Drupal::service('event_dispatcher'));
         // Get configs from other modules which depend on the given modules.
         $external_dependents = array_keys($manager->findConfigEntityDependents('module', $this->adjustments));
         // Get configs from the given modules (which obviously depend on them but
         // are not listed by findConfigEntityDependents().
         $adjustments = $this->adjustments;
         $internal_dependents = array_filter($storage->listAll(), function ($config_name) use($adjustments) {
             foreach ($this->adjustments as $module_name) {
                 if (strpos($config_name, $module_name . '.') === 0) {
                     return TRUE;
                 }
             }
             return FALSE;
         });
         $dependents[$storage_id] = array_unique(array_merge($internal_dependents, $external_dependents));
     }
     return $dependents[$storage_id];
 }