class StorageComparer implements StorageComparerInterface (View source)

Defines a config storage comparer.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected StorageInterface $sourceStorage

The source storage used to discover configuration changes.

protected StorageInterface[] $sourceStorages

The source storages keyed by collection.

protected StorageInterface $targetStorage

The target storage used to write configuration changes.

protected StorageInterface[] $targetStorages

The target storages keyed by collection.

protected array $changelist

List of changes to between the source storage and the target storage.

protected array $sourceNames

Sorted list of all the configuration object names in the source storage.

protected array $targetNames

Sorted list of all the configuration object names in the target storage.

protected MemoryBackend $sourceCacheStorage

A memory cache backend to statically cache source configuration data.

protected MemoryBackend $targetCacheStorage

A memory cache backend to statically cache target configuration data.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StorageInterface $source_storage, StorageInterface $target_storage)

Constructs the Configuration storage comparer.

getSourceStorage(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the configuration source storage.

getTargetStorage(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the configuration target storage.

array
getEmptyChangelist()

Gets an empty changelist.

array
getChangelist(string $op = NULL, string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the list of differences to import.

addChangeList(string $collection, string $op, array $changes, array $sort_order = NULL)

Adds changes to the changelist.

createChangelist()

{@inheritdoc}

addChangelistDelete(string $collection)

Creates the delete changelist.

addChangelistCreate(string $collection)

Creates the create changelist.

addChangelistUpdate(string $collection)

Creates the update changelist.

addChangelistRename(string $collection)

Creates the rename changelist.

removeFromChangelist(string $collection, string $op, string $name)

Removes the entry from the given operation changelist for the given name.

moveRenameToUpdate(string $rename, string $collection = StorageInterface::DEFAULT_COLLECTION)

Moves a rename operation to an update.

$this
reset()

Recalculates the differences.

bool
hasChanges()

Checks if there are any operations with changes to process.

bool
validateSiteUuid()

Validates that the system.site::uuid in the source and target match.

getAndSortConfigData($collection)

Gets and sorts configuration data from the source and target storages.

string
createRenameName(string $old_name, string $new_name)

Creates a rename name from the old and new names for the object.

array
extractRenameNames(string $name)

Extracts old and new configuration names from a configuration change name.

array
getAllCollectionNames(bool $include_default = TRUE)

Gets the existing collections from both the target and source storage.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StorageInterface $source_storage, StorageInterface $target_storage)

Constructs the Configuration storage comparer.

Parameters

StorageInterface $source_storage

Storage object used to read configuration.

StorageInterface $target_storage

Storage object used to write configuration.

StorageInterface getSourceStorage(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the configuration source storage.

Parameters

string $collection

(optional) The storage collection to use. Defaults to the default collection.

Return Value

StorageInterface

Storage object used to read configuration.

StorageInterface getTargetStorage(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the configuration target storage.

Parameters

string $collection

(optional) The storage collection to use. Defaults to the default collection.

Return Value

StorageInterface

Storage object used to write configuration.

array getEmptyChangelist()

Gets an empty changelist.

Return Value

array

An empty changelist array.

array getChangelist(string $op = NULL, string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the list of differences to import.

Parameters

string $op

(optional) A change operation. Either delete, create or update. If supplied the returned list will be limited to this operation.

string $collection

(optional) The collection to get the changelist for. Defaults to the default collection.

Return Value

array

An array of config changes that are yet to be imported.

protected addChangeList(string $collection, string $op, array $changes, array $sort_order = NULL)

Adds changes to the changelist.

Parameters

string $collection

The storage collection to add changes for.

string $op

The change operation performed. Either delete, create, rename, or update.

array $changes

Array of changes to add to the changelist.

array $sort_order

Array to sort that can be used to sort the changelist. This array must contain all the items that are in the change list.

createChangelist()

{@inheritdoc}

protected addChangelistDelete(string $collection)

Creates the delete changelist.

The list of deletes is sorted so that dependencies are deleted after configuration entities that depend on them. For example, fields should be deleted after field storages.

Parameters

string $collection

The storage collection to operate on.

protected addChangelistCreate(string $collection)

Creates the create changelist.

The list of creates is sorted so that dependencies are created before configuration entities that depend on them. For example, field storages should be created before fields.

Parameters

string $collection

The storage collection to operate on.

protected addChangelistUpdate(string $collection)

Creates the update changelist.

The list of updates is sorted so that dependencies are created before configuration entities that depend on them. For example, field storages should be updated before fields.

Parameters

string $collection

The storage collection to operate on.

protected addChangelistRename(string $collection)

Creates the rename changelist.

The list of renames is created from the different source and target names with same UUID. These changes will be removed from the create and delete lists.

Parameters

string $collection

The storage collection to operate on.

protected removeFromChangelist(string $collection, string $op, string $name)

Removes the entry from the given operation changelist for the given name.

Parameters

string $collection

The storage collection to operate on.

string $op

The changelist to act on. Either delete, create, rename or update.

string $name

The name of the configuration to remove.

moveRenameToUpdate(string $rename, string $collection = StorageInterface::DEFAULT_COLLECTION)

Moves a rename operation to an update.

Parameters

string $rename

The rename name, as provided by ConfigImporter::createRenameName().

string $collection

(optional) The collection where the configuration is stored. Defaults to the default collection.

$this reset()

Recalculates the differences.

Return Value

$this

An object which implements the StorageComparerInterface.

bool hasChanges()

Checks if there are any operations with changes to process.

Until the changelist has been calculated this will always be FALSE.

Return Value

bool

TRUE if there are changes to process and FALSE if not.

bool validateSiteUuid()

Validates that the system.site::uuid in the source and target match.

Return Value

bool

TRUE if identical, FALSE if not.

protected getAndSortConfigData($collection)

Gets and sorts configuration data from the source and target storages.

Parameters

$collection

protected string createRenameName(string $old_name, string $new_name)

Creates a rename name from the old and new names for the object.

Parameters

string $old_name

The old configuration object name.

string $new_name

The new configuration object name.

Return Value

string

The configuration change name that encodes both the old and the new name.

See also

StorageComparerInterface::extractRenameNames

array extractRenameNames(string $name)

Extracts old and new configuration names from a configuration change name.

Parameters

string $name

The configuration change name, as provided by ConfigImporter::createRenameName().

Return Value

array

An associative array of configuration names. The array keys are 'old_name' and 'new_name' representing the old and new configuration object names during a rename operation.

array getAllCollectionNames(bool $include_default = TRUE)

Gets the existing collections from both the target and source storage.

Parameters

bool $include_default

(optional) Include the default collection. Defaults to TRUE.

Return Value

array

An array of existing collection names.