示例#1
0
 /**
  * Copies configuration objects from source storage to target storage.
  *
  * @param \Drupal\Core\Config\StorageInterface $source_storage
  *   The source config storage service.
  * @param \Drupal\Core\Config\StorageInterface $target_storage
  *   The target config storage service.
  */
 protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage)
 {
     $target_storage->deleteAll();
     foreach ($source_storage->listAll() as $name) {
         $target_storage->write($name, $source_storage->read($name));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($path = $form_state->getValue('import_tarball')) {
         $this->configStorage->deleteAll();
         try {
             $archiver = new ArchiveTar($path, 'gz');
             $files = array();
             foreach ($archiver->listContent() as $file) {
                 $files[] = $file['filename'];
             }
             $archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY));
             drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.'));
             $form_state->setRedirect('config.sync');
         } catch (\Exception $e) {
             drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error');
         }
         drupal_unlink($path);
     }
 }
 /**
  * Implements Drupal\Core\Config\StorageInterface::deleteAll().
  */
 public function deleteAll($prefix = '')
 {
     // If the cache was the first to be deleted, another process might start
     // rebuilding the cache before the storage is renamed.
     $names = $this->storage->listAll($prefix);
     if ($this->storage->deleteAll($prefix)) {
         $this->cache->deleteMultiple($this->getCacheKeys($names));
         return TRUE;
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteAll($prefix = '')
 {
     if ($prefix === '') {
         $this->replacementData[$this->collection] = [];
     } else {
         foreach (array_keys($this->replacementData[$this->collection]) as $name) {
             if (strpos($name, $prefix) === 0) {
                 unset($this->replacementData[$this->collection][$name]);
             }
         }
     }
     return $this->storage->deleteAll($prefix);
 }
 /**
  * {@inheritdoc}
  */
 public function deleteAll($prefix = '')
 {
     return $this->baseStorage->deleteAll($prefix);
 }
示例#6
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));
         }
     }
 }
示例#7
0
 /**
  * Tests storage CRUD operations.
  *
  * @todo Coverage: Trigger PDOExceptions / Database exceptions.
  */
 function testCRUD()
 {
     $name = 'config_test.storage';
     // Checking whether a non-existing name exists returns FALSE.
     $this->assertIdentical($this->storage->exists($name), FALSE);
     // Reading a non-existing name returns FALSE.
     $data = $this->storage->read($name);
     $this->assertIdentical($data, FALSE);
     // Writing data returns TRUE and the data has been written.
     $data = array('foo' => 'bar');
     $result = $this->storage->write($name, $data);
     $this->assertIdentical($result, TRUE);
     $raw_data = $this->read($name);
     $this->assertIdentical($raw_data, $data);
     // Checking whether an existing name exists returns TRUE.
     $this->assertIdentical($this->storage->exists($name), TRUE);
     // Writing the identical data again still returns TRUE.
     $result = $this->storage->write($name, $data);
     $this->assertIdentical($result, TRUE);
     // Listing all names returns all.
     $names = $this->storage->listAll();
     $this->assertTrue(in_array('system.performance', $names));
     $this->assertTrue(in_array($name, $names));
     // Listing all names with prefix returns names with that prefix only.
     $names = $this->storage->listAll('config_test.');
     $this->assertFalse(in_array('system.performance', $names));
     $this->assertTrue(in_array($name, $names));
     // Rename the configuration storage object.
     $new_name = 'config_test.storage_rename';
     $this->storage->rename($name, $new_name);
     $raw_data = $this->read($new_name);
     $this->assertIdentical($raw_data, $data);
     // Rename it back so further tests work.
     $this->storage->rename($new_name, $name);
     // Deleting an existing name returns TRUE.
     $result = $this->storage->delete($name);
     $this->assertIdentical($result, TRUE);
     // Deleting a non-existing name returns FALSE.
     $result = $this->storage->delete($name);
     $this->assertIdentical($result, FALSE);
     // Deleting all names with prefix deletes the appropriate data and returns
     // TRUE.
     $files = array('config_test.test.biff', 'config_test.test.bang', 'config_test.test.pow');
     foreach ($files as $name) {
         $this->storage->write($name, $data);
     }
     $result = $this->storage->deleteAll('config_test.');
     $names = $this->storage->listAll('config_test.');
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($names, array());
     // Test renaming an object that does not exist throws an exception.
     try {
         $this->storage->rename('config_test.storage_does_not_exist', 'config_test.storage_does_not_exist_rename');
     } catch (\Exception $e) {
         $class = get_class($e);
         $this->pass($class . ' thrown upon renaming a nonexistent storage bin.');
     }
     // Test renaming to an object that already exists throws an exception.
     try {
         $this->storage->rename('system.cron', 'system.performance');
     } catch (\Exception $e) {
         $class = get_class($e);
         $this->pass($class . ' thrown upon renaming a nonexistent storage bin.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function deleteSnapshot()
 {
     $this->snapshotExtensionStorage->deleteAll();
     $this->snapshotActiveStorage->deleteAll();
 }