Exemplo n.º 1
0
 /**
  * Creates configuration in a collection based on the provided list.
  *
  * @param string $collection
  *   The configuration collection.
  * @param array $config_to_install
  *   A list of configuration object names to create.
  */
 protected function createConfiguration($collection, array $config_to_install)
 {
     // Order the configuration to install in the order of dependencies.
     $data = $this->getSourceStorage($collection)->readMultiple($config_to_install);
     $config_entity_support = $this->configManager->supportsConfigurationEntities($collection);
     if ($config_entity_support) {
         $dependency_manager = new ConfigDependencyManager();
         $config_to_install = $dependency_manager->setData($data)->sortAll();
     }
     // Remove configuration that already exists in the active storage.
     $config_to_install = array_diff($config_to_install, $this->getActiveStorage($collection)->listAll());
     foreach ($config_to_install as $name) {
         // Allow config factory overriders to use a custom configuration object if
         // they are responsible for the collection.
         $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
         if ($overrider) {
             $new_config = $overrider->createConfigObject($name, $collection);
         } else {
             $new_config = new Config($name, $this->getActiveStorage($collection), $this->eventDispatcher, $this->typedConfig);
         }
         if ($data[$name] !== FALSE) {
             $new_config->setData($data[$name]);
         }
         if ($config_entity_support && ($entity_type = $this->configManager->getEntityTypeIdByName($name))) {
             // If we are syncing do not create configuration entities. Pluggable
             // configuration entities can have dependencies on modules that are
             // not yet enabled. This approach means that any code that expects
             // default configuration entities to exist will be unstable after the
             // module has been enabled and before the config entity has been
             // imported.
             if ($this->isSyncing) {
                 continue;
             }
             $entity_storage = $this->configManager->getEntityManager()->getStorage($entity_type);
             // It is possible that secondary writes can occur during configuration
             // creation. Updates of such configuration are allowed.
             if ($this->getActiveStorage($collection)->exists($name)) {
                 $id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
                 $entity = $entity_storage->load($id);
                 foreach ($new_config->get() as $property => $value) {
                     $entity->set($property, $value);
                 }
                 $entity->save();
             } else {
                 $entity_storage->create($new_config->get())->save();
             }
         } else {
             $new_config->save();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Finds pre-existing configuration objects for the provided extension.
  *
  * Extensions can not be installed if configuration objects exist in the
  * active storage with the same names. This can happen in a number of ways,
  * commonly:
  * - if a user has created configuration with the same name as that provided
  *   by the extension.
  * - if the extension provides default configuration that does not depend on
  *   it and the extension has been uninstalled and is about to the
  *   reinstalled.
  *
  * @return array
  *   Array of configuration object names that already exist keyed by
  *   collection.
  */
 protected function findPreExistingConfiguration(StorageInterface $storage)
 {
     $existing_configuration = array();
     // Gather information about all the supported collections.
     $collection_info = $this->configManager->getConfigCollectionInfo();
     foreach ($collection_info->getCollectionNames() as $collection) {
         $config_to_create = array_keys($this->getConfigToCreate($storage, $collection));
         $active_storage = $this->getActiveStorages($collection);
         foreach ($config_to_create as $config_name) {
             if ($active_storage->exists($config_name)) {
                 $existing_configuration[$collection][] = $config_name;
             }
         }
     }
     return $existing_configuration;
 }
Exemplo n.º 3
0
 /**
  * Writes a configuration change from the source to the target storage.
  *
  * @param string $collection
  *   The configuration collection.
  * @param string $op
  *   The change operation.
  * @param string $name
  *   The name of the configuration to process.
  */
 protected function importConfig($collection, $op, $name)
 {
     // Allow config factory overriders to use a custom configuration object if
     // they are responsible for the collection.
     $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
     if ($overrider) {
         $config = $overrider->createConfigObject($name, $collection);
     } else {
         $config = new Config($name, $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager);
     }
     if ($op == 'delete') {
         $config->delete();
     } else {
         $data = $this->storageComparer->getSourceStorage($collection)->read($name);
         $config->setData($data ? $data : array());
         $config->save();
     }
     $this->setProcessedConfiguration($collection, $op, $name);
 }