eventDispatcher = $event_dispatcher; $this->connection = $connection; $this->requestLock = $requestLock; $this->persistentLock = $persistentLock; } /** * Transform the storage to be imported from. * * An import transformation is done before the config importer uses the * storage to synchronize the configuration. The transformation is also * done for displaying differences to review imports. * Importing in this context means the active drupal configuration is changed * with the ConfigImporter which may or may not be as part of the config * synchronization. * * @param \Drupal\Core\Config\StorageInterface $storage * The storage to transform for importing from it. * * @return \Drupal\Core\Config\StorageInterface * The transformed storage ready to be imported from. * * @throws \Drupal\Core\Config\StorageTransformerException * Thrown when the lock could not be acquired. */ public function transform(StorageInterface $storage) { // We use a database storage to reduce the memory requirement. $mutable = new DatabaseStorage($this->connection, 'config_import'); if (!$this->persistentLock->lockMayBeAvailable(ConfigImporter::LOCK_NAME)) { // If the config importer is already importing, the transformation will // always be the one the config importer is already using. This makes sure // that even if the storage changes the importer continues importing the // same configuration. return $mutable; } // 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(ConfigEvents::STORAGE_TRANSFORM_IMPORT, new StorageTransformEvent($mutable)); // Return the storage with the altered configuration. return $mutable; } }