Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function uninstall($type, $name)
 {
     // Remove all dependent configuration entities.
     $dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
     // Reverse the array to that entities are removed in the correct order of
     // dependence. For example, this ensures that field instances are removed
     // before fields.
     foreach (array_reverse($dependent_entities) as $entity) {
         $entity->setUninstalling(TRUE);
         $entity->delete();
     }
     $config_names = $this->configFactory->listAll($name . '.');
     foreach ($config_names as $config_name) {
         $this->configFactory->get($config_name)->delete();
     }
     // Remove any matching configuration from collections.
     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->activeStorage->createCollection($collection);
         $collection_storage->deleteAll($name . '.');
     }
     $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
     if (is_dir($schema_dir)) {
         // Refresh the schema cache if uninstalling an extension that provides
         // configuration schema.
         $this->typedConfigManager->clearCachedDefinitions();
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function uninstall($type, $name)
 {
     $entities = $this->getConfigEntitiesToChangeOnDependencyRemoval($type, [$name], FALSE);
     // Fix all dependent configuration entities.
     /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
     foreach ($entities['update'] as $entity) {
         $entity->save();
     }
     // Remove all dependent configuration entities.
     foreach ($entities['delete'] as $entity) {
         $entity->setUninstalling(TRUE);
         $entity->delete();
     }
     $config_names = $this->configFactory->listAll($name . '.');
     foreach ($config_names as $config_name) {
         $this->configFactory->getEditable($config_name)->delete();
     }
     // Remove any matching configuration from collections.
     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->activeStorage->createCollection($collection);
         $collection_storage->deleteAll($name . '.');
     }
     $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
     if (is_dir($schema_dir)) {
         // Refresh the schema cache if uninstalling an extension that provides
         // configuration schema.
         $this->typedConfigManager->clearCachedDefinitions();
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function getAllCollectionNames($include_default = TRUE)
 {
     $collections = array_unique(array_merge($this->sourceStorage->getAllCollectionNames(), $this->targetStorage->getAllCollectionNames()));
     if ($include_default) {
         array_unshift($collections, StorageInterface::DEFAULT_COLLECTION);
     }
     return $collections;
 }
 /**
  * {@inheritdoc}
  */
 public function uninstall($type, $name)
 {
     // Remove all dependent configuration entities.
     $extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
     // Give config entities a chance to become independent of the entities we
     // are going to delete.
     foreach ($extension_dependent_entities as $entity) {
         $entity_dependencies = $entity->getDependencies();
         if (empty($entity_dependencies)) {
             // No dependent entities nothing to do.
             continue;
         }
         // Work out if any of the entity's dependencies are going to be affected
         // by the uninstall.
         $affected_dependencies = array('entity' => array(), 'module' => array(), 'theme' => array());
         if (isset($entity_dependencies['entity'])) {
             foreach ($extension_dependent_entities as $extension_dependent_entity) {
                 if (in_array($extension_dependent_entity->getConfigDependencyName(), $entity_dependencies['entity'])) {
                     $affected_dependencies['entity'][] = $extension_dependent_entity;
                 }
             }
         }
         // Check if the extension being uninstalled is a dependency of the entity.
         if (isset($entity_dependencies[$type]) && in_array($name, $entity_dependencies[$type])) {
             $affected_dependencies[$type] = array($name);
         }
         // Inform the entity.
         $entity->onDependencyRemoval($affected_dependencies);
     }
     // Recalculate the dependencies, some config entities may have fixed their
     // dependencies on the to-be-removed entities.
     $extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
     // Reverse the array to that entities are removed in the correct order of
     // dependence. For example, this ensures that fields are removed before
     // field storages.
     foreach (array_reverse($extension_dependent_entities) as $extension_dependent_entity) {
         $extension_dependent_entity->setUninstalling(TRUE);
         $extension_dependent_entity->delete();
     }
     $config_names = $this->configFactory->listAll($name . '.');
     foreach ($config_names as $config_name) {
         $this->configFactory->get($config_name)->delete();
     }
     // Remove any matching configuration from collections.
     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->activeStorage->createCollection($collection);
         $collection_storage->deleteAll($name . '.');
     }
     $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
     if (is_dir($schema_dir)) {
         // Refresh the schema cache if uninstalling an extension that provides
         // configuration schema.
         $this->typedConfigManager->clearCachedDefinitions();
     }
 }
 /**
  * Downloads a tarball of the site configuration.
  */
 public function downloadExport()
 {
     file_unmanaged_delete(file_directory_temp() . '/config.tar.gz');
     $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz');
     // Get raw configuration data without overrides.
     foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
         $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
     }
     // Get all override data from the remaining collections.
     foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->targetStorage->createCollection($collection);
         foreach ($collection_storage->listAll() as $name) {
             $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
         }
     }
     $request = new Request(array('file' => 'config.tar.gz'));
     return $this->fileDownloadController->download($request, 'temporary');
 }
 /**
  * {@inheritdoc}
  */
 public function getAllCollectionNames()
 {
     return $this->baseStorage->getAllCollectionNames();
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage)
 {
     // Empty the snapshot of all configuration.
     $snapshot_storage->deleteAll();
     foreach ($snapshot_storage->getAllCollectionNames() as $collection) {
         $snapshot_collection = $snapshot_storage->createCollection($collection);
         $snapshot_collection->deleteAll();
     }
     foreach ($source_storage->listAll() as $name) {
         $snapshot_storage->write($name, $source_storage->read($name));
     }
     // Copy collections as well.
     foreach ($source_storage->getAllCollectionNames() as $collection) {
         $source_collection = $source_storage->createCollection($collection);
         $snapshot_collection = $snapshot_storage->createCollection($collection);
         foreach ($source_collection->listAll() as $name) {
             $snapshot_collection->write($name, $source_collection->read($name));
         }
     }
 }
 /**
  * Tests that the storage supports collections.
  */
 public function testCollection()
 {
     $name = 'config_test.storage';
     $data = array('foo' => 'bar');
     $result = $this->storage->write($name, $data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($data, $this->storage->read($name));
     // Create configuration in a new collection.
     $new_storage = $this->storage->createCollection('collection.sub.new');
     $this->assertFalse($new_storage->exists($name));
     $this->assertEqual(array(), $new_storage->listAll());
     $new_storage->write($name, $data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($data, $new_storage->read($name));
     $this->assertEqual(array($name), $new_storage->listAll());
     $this->assertTrue($new_storage->exists($name));
     $new_data = array('foo' => 'baz');
     $new_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $new_storage->read($name));
     // Create configuration in another collection.
     $another_storage = $this->storage->createCollection('collection.sub.another');
     $this->assertFalse($another_storage->exists($name));
     $this->assertEqual(array(), $another_storage->listAll());
     $another_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $another_storage->read($name));
     $this->assertEqual(array($name), $another_storage->listAll());
     $this->assertTrue($another_storage->exists($name));
     // Create configuration in yet another collection.
     $alt_storage = $this->storage->createCollection('alternate');
     $alt_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $alt_storage->read($name));
     // Switch back to the collection-less mode and check the data still exists
     // add has not been touched.
     $this->assertIdentical($data, $this->storage->read($name));
     // Check that the getAllCollectionNames() method works.
     $this->assertIdentical(array('alternate', 'collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     // Check that the collections are removed when they are empty.
     $alt_storage->delete($name);
     $this->assertIdentical(array('collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     // Create configuration in collection called 'collection'. This ensures that
     // FileStorage's collection storage works regardless of its use of
     // subdirectories.
     $parent_storage = $this->storage->createCollection('collection');
     $this->assertFalse($parent_storage->exists($name));
     $this->assertEqual(array(), $parent_storage->listAll());
     $parent_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $parent_storage->read($name));
     $this->assertEqual(array($name), $parent_storage->listAll());
     $this->assertTrue($parent_storage->exists($name));
     $this->assertIdentical(array('collection', 'collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     $parent_storage->deleteAll();
     $this->assertIdentical(array('collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     // Check that the having an empty collection-less storage does not break
     // anything. Before deleting check that the previous delete did not affect
     // data in another collection.
     $this->assertIdentical($data, $this->storage->read($name));
     $this->storage->delete($name);
     $this->assertIdentical(array('collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
 }