replaceStorageContents example

      // about objects.       $target_data = [(string) $this->t('File removed')];
    }

    return new Diff($source_data$target_data);
  }

  /** * {@inheritdoc} */
  public function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) {
    self::replaceStorageContents($source_storage$snapshot_storage);
  }

  /** * {@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();
    }


  /** * 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) {
    static::replaceStorageContents($source_storage$target_storage);
  }

}

  public function testWriteOperations($method$arguments$fixture) {
    $this->setRandomFixtureConfig($fixture);

    // Create an independent memory storage as a backup.     $backup = new MemoryStorage();
    static::replaceStorageContents($this->memory, $backup);

    try {
      call_user_func_array([$this->storage, $method]$arguments);
      $this->fail("exception not thrown");
    }
    catch (\BadMethodCallException $exception) {
      $this->assertEquals(ReadOnlyStorage::class D '::' . $method . ' is not allowed on a ReadOnlyStorage', $exception->getMessage());
    }

    // Assert that the memory storage has not been altered.     $this->assertEquals($backup$this->memory);
  }
// Acquire a lock to ensure that the storage is not changed when a     // concurrent request tries to transform the storage. The lock will be     // released at the end of the request.     if (!$this->requestLock->acquire(self::LOCK_NAME)) {
      $this->requestLock->wait(self::LOCK_NAME);
      if (!$this->requestLock->acquire(self::LOCK_NAME)) {
        throw new StorageTransformerException("Cannot acquire config import transformer lock.");
      }
    }

    // Copy the sync configuration to the created mutable storage.     self::replaceStorageContents($storage$mutable);

    // Dispatch the event so that event listeners can alter the configuration.     $this->eventDispatcher->dispatch(new StorageTransformEvent($mutable), ConfigEvents::STORAGE_TRANSFORM_IMPORT);

    // Return the storage with the altered configuration.     return $mutable;
  }

}

  public function getStorage() {
    // Acquire a lock for the request to assert that the storage does not change     // when a concurrent request transforms the storage.     if (!$this->lock->acquire(self::LOCK_NAME)) {
      $this->lock->wait(self::LOCK_NAME);
      if (!$this->lock->acquire(self::LOCK_NAME)) {
        throw new StorageTransformerException("Cannot acquire config export transformer lock.");
      }
    }

    self::replaceStorageContents($this->active, $this->storage);
    $this->eventDispatcher->dispatch(new StorageTransformEvent($this->storage), ConfigEvents::STORAGE_TRANSFORM_EXPORT);

    return new ReadOnlyStorage($this->storage);
  }

}

    if ($target_collections) {
      $collections = $target->getAllCollectionNames();
      $target = $target->createCollection($collections[array_rand($collections)]);
    }

    $source_data = self::toArray($source);
    $source_name = $source->getCollectionName();

    // After copying they are the same, this asserts that items not present     // in the source get removed from the target.     self::replaceStorageContents($source$target);
    $this->assertEquals($source_data, self::toArray($target));
    // Assert that the copy method did indeed not change the source.     $this->assertEquals($source_data, self::toArray($source));

    // Assert that the active collection is the same as the original source.     $this->assertEquals($source_name$source->getCollectionName());
    $this->assertEquals($source_name$target->getCollectionName());
  }

  /** * Provides data for testCheckRequirements(). */
Home | Imprint | This part of the site doesn't use cookies.