Drupal 8  8.0.2
ConfigImporter Class Reference

Public Member Functions

 __construct (StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation)
 
 logError ($message)
 
 getErrors ()
 
 getStorageComparer ()
 
 reset ()
 
 hasUnprocessedConfigurationChanges ()
 
 getProcessedConfiguration ($collection=StorageInterface::DEFAULT_COLLECTION)
 
 getUnprocessedConfiguration ($op, $collection=StorageInterface::DEFAULT_COLLECTION)
 
 getProcessedExtensions ()
 
 getExtensionChangelist ($type, $op=NULL)
 
 import ()
 
 doSyncStep ($sync_step, &$context)
 
 initialize ()
 
 validate ()
 
 alreadyImporting ()
 

Data Fields

const LOCK_NAME = 'config_importer'
 

Protected Member Functions

 getEmptyExtensionsProcessedList ()
 
 setProcessedConfiguration ($collection, $op, $name)
 
 setProcessedExtension ($type, $op, $name)
 
 createExtensionChangelist ()
 
 getUnprocessedExtensions ($type)
 
 processExtensions (array &$context)
 
 processConfigurations (array &$context)
 
 processMissingContent (array &$context)
 
 finish (array &$context)
 
 getNextExtensionOperation ()
 
 getNextConfigurationOperation ()
 
 processConfiguration ($collection, $op, $name)
 
 processExtension ($type, $op, $name)
 
 checkOp ($collection, $op, $name)
 
 importConfig ($collection, $op, $name)
 
 importInvokeOwner ($collection, $op, $name)
 
 importInvokeRename ($collection, $rename_name)
 
 reInjectMe ()
 

Protected Attributes

 $storageComparer
 
 $eventDispatcher
 
 $configManager
 
 $lock
 
 $typedConfigManager
 
 $processedConfiguration
 
 $processedExtensions
 
 $extensionChangelist
 
 $validated
 
 $moduleHandler
 
 $themeHandler
 
 $processedSystemTheme = FALSE
 
 $errors = array()
 
 $totalExtensionsToProcess = 0
 
 $totalConfigurationToProcess = 0
 
 $moduleInstaller
 

Detailed Description

Defines a configuration importer.

A config importer imports the changes into the configuration system. To determine which changes to import a StorageComparer in used.

See Also

The ConfigImporter has a identifier which is used to construct event names. The events fired during an import are:

  • ConfigEvents::IMPORT_VALIDATE: Events listening can throw a to prevent an import from occurring.
    See Also
  • ConfigEvents::IMPORT: Events listening can react to a successful import.
    See Also

Constructor & Destructor Documentation

__construct ( StorageComparerInterface  $storage_comparer,
EventDispatcherInterface  $event_dispatcher,
ConfigManagerInterface  $config_manager,
LockBackendInterface  $lock,
TypedConfigManagerInterface  $typed_config,
ModuleHandlerInterface  $module_handler,
ModuleInstallerInterface  $module_installer,
ThemeHandlerInterface  $theme_handler,
TranslationInterface  $string_translation 
)

Constructs a configuration import object.

Parameters
\Drupal\Core\Config\StorageComparerInterface$storage_comparerA storage comparer object used to determine configuration changes and access the source and target storage objects.
\Symfony\Component\EventDispatcher\EventDispatcherInterface$event_dispatcherThe event dispatcher used to notify subscribers of config import events.
\Drupal\Core\Config\ConfigManagerInterface$config_managerThe configuration manager.
\Drupal\Core\Lock\LockBackendInterface$lockThe lock backend to ensure multiple imports do not occur at the same time.
\Drupal\Core\Config\TypedConfigManagerInterface$typed_configThe typed configuration manager.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler
\Drupal\Core\Extension\ModuleInstallerInterface$module_installerThe module installer.
\Drupal\Core\Extension\ThemeHandlerInterface$theme_handlerThe theme handler
\Drupal\Core\StringTranslation\TranslationInterface$string_translationThe string translation service.

References ConfigImporter\getEmptyExtensionsProcessedList(), Drupal\lock(), and Drupal\moduleHandler().

Here is the call graph for this function:

Member Function Documentation

alreadyImporting ( )

Determines if a import is already running.

Returns
bool TRUE if an import is already running, FALSE if not.

References Drupal\lock().

Here is the call graph for this function:

checkOp (   $collection,
  $op,
  $name 
)
protected

Checks that the operation is still valid.

During a configuration import secondary writes and deletes are possible. This method checks that the operation is still valid before processing a configuration change.

Parameters
string$collectionThe configuration collection.
string$opThe change operation.
string$nameThe name of the configuration to process.
Returns
bool TRUE is to continue processing, FALSE otherwise.
Exceptions
\Drupal\Core\Config\ConfigImporterException

References ConfigImporter\logError(), ConfigImporter\setProcessedConfiguration(), and t().

Referenced by ConfigImporter\processConfigurations().

Here is the call graph for this function:

Here is the caller graph for this function:

createExtensionChangelist ( )
protected

Populates the extension change list.

References ConfigImporter\getEmptyExtensionsProcessedList().

Referenced by ConfigImporter\validate().

Here is the call graph for this function:

Here is the caller graph for this function:

doSyncStep (   $sync_step,
$context 
)

Calls a config import step.

Parameters
string | callable$sync_stepThe step to do. Either a method on the ConfigImporter class or a callable.
array$contextA batch context array. If the config importer is not running in a batch the only array key that is used is $context['finished']. A process needs to set $context['finished'] = 1 when it is done.
Exceptions
\InvalidArgumentExceptionException thrown if the $sync_step can not be called.

Referenced by ConfigImporter\import(), and ConfigSync\processBatch().

Here is the caller graph for this function:

finish ( array &  $context)
protected

Finishes the batch.

Parameters
array$context,.The batch context.

References Drupal\lock(), ConfigImporter\reset(), and t().

Here is the call graph for this function:

getEmptyExtensionsProcessedList ( )
protected

Gets an empty list of extensions to process.

Returns
array An empty list of extensions to process.

Referenced by ConfigImporter\__construct(), ConfigImporter\createExtensionChangelist(), and ConfigImporter\reset().

Here is the caller graph for this function:

getErrors ( )

Returns error messages created while running the import.

Returns
array List of messages.

Referenced by ConfigSync\processBatch(), and ConfigImporter\validate().

Here is the caller graph for this function:

getExtensionChangelist (   $type,
  $op = NULL 
)

Gets a list changes for extensions.

Parameters
string$typeThe type of extension, either 'theme' or 'module'.
string$opThe change operation to get the unprocessed list for, either install or uninstall.
Returns
array An array of extension names.

Referenced by ConfigImporter\getUnprocessedExtensions(), ConfigImportSubscriber\validateModules(), and ConfigImportSubscriber\validateThemes().

Here is the caller graph for this function:

getNextConfigurationOperation ( )
protected

Gets the next configuration operation to perform.

Returns
array|bool An array containing the next operation and configuration name to perform it on. If there is nothing left to do returns FALSE;

References ConfigImporter\getUnprocessedConfiguration().

Referenced by ConfigImporter\processConfigurations().

Here is the call graph for this function:

Here is the caller graph for this function:

getNextExtensionOperation ( )
protected

Gets the next extension operation to perform.

Returns
array|bool An array containing the next operation and extension name to perform it on. If there is nothing left to do returns FALSE;

References ConfigImporter\getUnprocessedExtensions().

Referenced by ConfigImporter\processExtensions().

Here is the call graph for this function:

Here is the caller graph for this function:

getProcessedConfiguration (   $collection = StorageInterface::DEFAULT_COLLECTION)

Gets list of processed changes.

Parameters
string$collection(optional) The configuration collection to get processed changes for. Defaults to the default collection.
Returns
array An array containing a list of processed changes.
getProcessedExtensions ( )

Gets list of processed extension changes.

Returns
array An array containing a list of processed extension changes.
getStorageComparer ( )

Gets the configuration storage comparer.

Returns
Storage comparer object used to calculate configuration changes.

Referenced by ConfigImporterFieldPurger\initializeSandbox(), ConfigImportSubscriber\validateDependencies(), ConfigImportSubscriber\validateModules(), and ConfigImportSubscriber\validateThemes().

Here is the caller graph for this function:

getUnprocessedConfiguration (   $op,
  $collection = StorageInterface::DEFAULT_COLLECTION 
)

Gets a list of unprocessed changes for a given operation.

Parameters
string$opThe change operation to get the unprocessed list for, either delete, create, rename, or update.
string$collection(optional) The configuration collection to get unprocessed changes for. Defaults to the default collection.
Returns
array An array of configuration names.

Referenced by ConfigImporter\getNextConfigurationOperation(), ConfigImporter\hasUnprocessedConfigurationChanges(), ConfigImporterFieldPurger\initializeSandbox(), ConfigImporterFieldPurger\process(), ConfigImporter\processConfigurations(), and ConfigImporter\validate().

Here is the caller graph for this function:

getUnprocessedExtensions (   $type)
protected

Gets a list of unprocessed changes for extensions.

Parameters
string$typeThe type of extension, either 'theme' or 'module'.
Returns
array An array of extension names.

References ConfigImporter\getExtensionChangelist().

Referenced by ConfigImporter\getNextExtensionOperation(), and ConfigImporter\initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

hasUnprocessedConfigurationChanges ( )

Checks if there are any unprocessed configuration changes.

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

References ConfigImporter\getUnprocessedConfiguration().

Referenced by ConfigImporter\import().

Here is the call graph for this function:

Here is the caller graph for this function:

import ( )

Imports the changelist to the target storage.

Returns
The ConfigImporter instance.
Exceptions
\Drupal\Core\Config\ConfigException

References ConfigImporter\doSyncStep(), ConfigImporter\hasUnprocessedConfigurationChanges(), and ConfigImporter\initialize().

Here is the call graph for this function:

importConfig (   $collection,
  $op,
  $name 
)
protected

Writes a configuration change from the source to the target storage.

Parameters
string$collectionThe configuration collection.
string$opThe change operation.
string$nameThe name of the configuration to process.

References ConfigImporter\setProcessedConfiguration().

Referenced by ConfigImporter\processConfiguration(), and ConfigImporter\processExtension().

Here is the call graph for this function:

Here is the caller graph for this function:

importInvokeOwner (   $collection,
  $op,
  $name 
)
protected

Invokes import* methods on configuration entity storage.

Allow modules to take over configuration change operations for higher-level configuration data.

Todo:
Add support for other extension types; e.g., themes etc.
Parameters
string$collectionThe configuration collection.
string$opThe change operation to get the unprocessed list for, either delete, create, rename, or update.
string$nameThe name of the configuration to process.
Returns
bool TRUE if the configuration was imported as a configuration entity. FALSE otherwise.
Exceptions
\Drupal\Core\Entity\EntityStorageExceptionThrown if the data is owned by an entity type, but the entity storage does not support imports.

References ConfigImporter\importInvokeRename(), Config\initWithData(), Config\setData(), and ConfigImporter\setProcessedConfiguration().

Referenced by ConfigImporter\processConfiguration().

Here is the call graph for this function:

Here is the caller graph for this function:

importInvokeRename (   $collection,
  $rename_name 
)
protected

Imports a configuration entity rename.

Parameters
string$collectionThe configuration collection.
string$rename_nameThe rename configuration name, as provided by ::createRenameName().
Returns
bool TRUE if the configuration was imported as a configuration entity. FALSE otherwise.
Exceptions
\Drupal\Core\Entity\EntityStorageExceptionThrown if the data is owned by an entity type, but the entity storage does not support imports.
See Also
::createRenameName()

References Config\initWithData(), Config\setData(), and ConfigImporter\setProcessedConfiguration().

Referenced by ConfigImporter\importInvokeOwner().

Here is the call graph for this function:

Here is the caller graph for this function:

initialize ( )

Initializes the config importer in preparation for processing a batch.

Returns
array An array of method names and callables that are invoked to complete the import. If there are modules or themes to process then an extra step is added.
Exceptions
\Drupal\Core\Config\ConfigImporterExceptionIf the configuration is already importing.

References ConfigImporter\getUnprocessedExtensions(), Drupal\lock(), Drupal\moduleHandler(), and ConfigImporter\validate().

Referenced by ConfigImporter\import().

Here is the call graph for this function:

Here is the caller graph for this function:

logError (   $message)

Logs an error message.

Parameters
string$messageThe message to log.

Referenced by ConfigImporter\checkOp(), ConfigImporter\processConfiguration(), ConfigImporter\validate(), ConfigImportSubscriber\validateDependencies(), ConfigImportSubscriber\validateModules(), and ConfigImportSubscriber\validateThemes().

Here is the caller graph for this function:

processConfiguration (   $collection,
  $op,
  $name 
)
protected

Processes a configuration change.

Parameters
string$collectionThe configuration collection to process changes for.
string$opThe change operation.
string$nameThe name of the configuration to process.
Exceptions
\ExceptionThrown when the import process fails, only thrown when no importer log is set, otherwise the exception message is logged and the configuration is skipped.

References StorageInterface\DEFAULT_COLLECTION, ConfigImporter\importConfig(), ConfigImporter\importInvokeOwner(), ConfigImporter\logError(), ConfigImporter\setProcessedConfiguration(), and t().

Referenced by ConfigImporter\processConfigurations().

Here is the call graph for this function:

Here is the caller graph for this function:

processConfigurations ( array &  $context)
protected

Processes configuration as a batch operation.

Parameters
array$context,.The batch context.

References ConfigImporter\checkOp(), StorageInterface\DEFAULT_COLLECTION, ConfigImporter\getNextConfigurationOperation(), ConfigImporter\getUnprocessedConfiguration(), ConfigImporter\processConfiguration(), and t().

Here is the call graph for this function:

processExtension (   $type,
  $op,
  $name 
)
protected

Processes an extension change.

Parameters
string$typeThe type of extension, either 'module' or 'theme'.
string$opThe change operation.
string$nameThe name of the extension to process.

References StorageInterface\DEFAULT_COLLECTION, ConfigImporter\importConfig(), Drupal\moduleHandler(), ConfigImporter\reInjectMe(), Drupal\service(), and ConfigImporter\setProcessedExtension().

Referenced by ConfigImporter\processExtensions().

Here is the call graph for this function:

Here is the caller graph for this function:

processExtensions ( array &  $context)
protected

Processes extensions as a batch operation.

Parameters
array$context,.The batch context.

References ConfigImporter\getNextExtensionOperation(), ConfigImporter\processExtension(), and t().

Here is the call graph for this function:

processMissingContent ( array &  $context)
protected

Handles processing of missing content.

Parameters
array$contextStandard batch context.

References ConfigEvents\IMPORT_MISSING_CONTENT, and t().

Here is the call graph for this function:

reInjectMe ( )
protected

Gets all the service dependencies from .

Since the ConfigImporter handles module installation the kernel and the container can be rebuilt and altered during processing. It is necessary to keep the services used by the importer in sync.

References Drupal\service().

Referenced by ConfigImporter\processExtension().

Here is the call graph for this function:

Here is the caller graph for this function:

reset ( )

Resets the storage comparer and processed list.

Returns
The ConfigImporter instance.

References ConfigImporter\getEmptyExtensionsProcessedList().

Referenced by ConfigImporter\finish().

Here is the call graph for this function:

Here is the caller graph for this function:

setProcessedConfiguration (   $collection,
  $op,
  $name 
)
protected

Sets a change as processed.

Parameters
string$collectionThe configuration collection to set a change as processed for.
string$opThe change operation performed, either delete, create, rename, or update.
string$nameThe name of the configuration processed.

Referenced by ConfigImporter\checkOp(), ConfigImporter\importConfig(), ConfigImporter\importInvokeOwner(), ConfigImporter\importInvokeRename(), and ConfigImporter\processConfiguration().

Here is the caller graph for this function:

setProcessedExtension (   $type,
  $op,
  $name 
)
protected

Sets an extension change as processed.

Parameters
string$typeThe type of extension, either 'theme' or 'module'.
string$opThe change operation performed, either install or uninstall.
string$nameThe name of the extension processed.

Referenced by ConfigImporter\processExtension().

Here is the caller graph for this function:

validate ( )

Dispatches validate event for a ConfigImporter object.

Events should throw a to prevent an import from occurring.

Exceptions
\Drupal\Core\Config\ConfigImporterExceptionException thrown if the validate event logged any errors.

References ConfigImporter\createExtensionChangelist(), ConfigImporter\getErrors(), ConfigImporter\getUnprocessedConfiguration(), ConfigImporter\logError(), and t().

Referenced by ConfigImporter\initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

Field Documentation

const LOCK_NAME = 'config_importer'

The name used to identify the lock.


The documentation for this class was generated from the following file: