class MigrationState (View source)

Determines the migrate state for all modules enabled on the source.

Retrieves migrate info from *.migrate_drupal.yml files.

Knowing which modules will be upgraded and those that will not is needed by anyone upgrading a legacy Drupal version. This service provides that information by analyzing the existing migrations and data in migrate_drupal.yml files. Modules that are enabled or disabled in the source are included in the analysis modules that are uninstalled are ignored.

Deciding the upgrade state of a source module is a complicated task. A destination module is not limited in any way to the source modules or the current major version destination modules it is providing migrations for. We see this in core where the Drupal 6 Menu module is upgraded by having migrations in three Drupal 8 modules; menu_link_content, menu_ui and system. If migrations for any of those three modules are not complete or if any of them are not installed on the destination site then the Drupal 6 Menu module cannot be listed as upgraded. If any one of the conditions are not met then it should be listed as will not be upgraded.

Another challenge is to ensure that legacy source modules that do not need an upgrade path are handled correctly. These will not have migrations but should be listed as will be upgraded, which even though there are not migrations under the hood, it lets a site admin know that upgrading with this module enabled is safe.

There is not enough information in the existing system to determine the correct state of the upgrade path for these, and other scenarios.

The solution is for every destination module that is the successor to a module built for a legacy Drupal version to declare the state of the upgrade path(s) for the module. A module's upgrade path from a previous version may consist of one or more migrations sets. Each migration set definition consists of a source module supporting a legacy Drupal version, and one or more current destination modules. This allows a module to indicate that a provided migration set requires additional modules to be enabled in the destination.

A migration set can be marked 'finished', which indicates that all migrations that are going to be provided by this destination module for this migration set have been written and are complete. A migration set may also be marked 'not_finished' which indicates that the module either has not provided any migrations for the set, or needs to provide additional migrations to complete the set. Note that other modules may still provide additional finished or not_finished migrations for the same migration set.

Modules inform the upgrade process of the migration sets by adding them to their .migrate_drupal.yml file.

The .migrate_drupal.yml file uses the following structure:

(optional) List of the source_module/destination_module(s) for the

migration sets that this module provides and are complete.

finished:

One or more Drupal legacy version number mappings (i.e. 6 and/or 7).

6:

A mapping of legacy module machine names to either an array of modules

# or a single destination module machine name to define this migration
# set.
<source_module_1>: <destination_module_1>
<source_module_2>:
  - <destination_module_1>
  - <destination_module_2>

7:

: : - - # (optional) List of the migration sets that this module provides, or will be # providing, that are incomplete or do not yet exist. not_finished: 6: : : - - Examples:

Traits

Provides a trait for the messenger service.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Constants

FINISHED

Source module upgrade state when all its migrations are complete.

NOT_FINISHED

Source module upgrade state when all its migrations are not complete.

Properties

protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected ModuleHandler $moduleHandler

The field plugin manager service.

protected MigrateFieldPluginManagerInterface $fieldPluginManager

The field plugin manager service.

protected array $unmigratedSourceModules

Source modules that will not be migrated determined using legacy method.

protected array $migratedSourceModules

Source modules that will be migrated determined using legacy method, keyed by version.

protected array $stateBySource

An array of migration states declared for each source migration.

protected array $declaredBySource

An array of destinations declared for each source migration.

protected array $discoveredBySource

An array of migration source and destinations derived from migrations.

protected array $destinations

An array of migration source and destinations.

protected array $enabledModules

Array of enabled modules.

Methods

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(MigrateFieldPluginManagerInterface $fieldPluginManager, ModuleHandlerInterface $moduleHandler, MessengerInterface $messenger, TranslationInterface $stringTranslation)

Construct a new MigrationState object.

array
getUpgradeStates(string $version, array $source_system_data, array $migrations)

Gets the upgrade states for all enabled source modules.

array
getMigrationStates()

Gets migration state information from *.migrate_drupal.yml.

array
buildUpgradeState(string $version, array $source_system_data, array $migrations)

Determines migration state for each source module enabled on the source.

buildDiscoveredDestinationsBySource(string $version, array $migrations, array $source_system_data)

Builds migration source and destination module information.

buildDeclaredStateBySource(string $version)

Gets migration data from *.migrate_drupal.yml sorted by source module.

string
getSourceState(string $version, string $source_module)

Tests if a destination exists for the given source module.

array
getDestinationsForSource(string $version, string $source_module)

Get net destinations for source module.

Details

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(MigrateFieldPluginManagerInterface $fieldPluginManager, ModuleHandlerInterface $moduleHandler, MessengerInterface $messenger, TranslationInterface $stringTranslation)

Construct a new MigrationState object.

Parameters

MigrateFieldPluginManagerInterface $fieldPluginManager

Field plugin manager.

ModuleHandlerInterface $moduleHandler

Module handler.

MessengerInterface $messenger

Messenger sevice.

TranslationInterface $stringTranslation

String translation service.

array getUpgradeStates(string $version, array $source_system_data, array $migrations)

Gets the upgrade states for all enabled source modules.

Parameters

string $version

The legacy drupal version.

array $source_system_data

The data from the source site system table.

array $migrations

An array of migrations.

Return Value

array

An associative array of data with keys of state, source modules and a value which is a comma separated list of destination modules.

protected array getMigrationStates()

Gets migration state information from *.migrate_drupal.yml.

Return Value

array

An association array keyed by module of the finished and not_finished migrations for each module.

protected array buildUpgradeState(string $version, array $source_system_data, array $migrations)

Determines migration state for each source module enabled on the source.

If there are no migrations for a module and no declared state the state is set to NOT_FINISHED. When a module does not need any migrations, such as Overlay, a state of finished is declared in system.migrate_drupal.yml.

If there are migrations for a module the following happens. If the destination module is 'core' the state is set to FINISHED. If there are any occurrences of 'not_finished' in the *.migrate_drupal.yml information for this source module then the state is set to NOT_FINISHED. And finally, if there is an occurrence of 'finished' the state is set to FINISHED.

Parameters

string $version

The legacy drupal version.

array $source_system_data

The data from the source site system table.

array $migrations

An array of migrations.

Return Value

array

An associative array of data with keys of state, source modules and a value which is a comma separated list of destination modules. Example.

protected buildDiscoveredDestinationsBySource(string $version, array $migrations, array $source_system_data)

Builds migration source and destination module information.

Parameters

string $version

The legacy Drupal version.

array $migrations

The discovered migrations.

array $source_system_data

The data from the source site system table.

protected buildDeclaredStateBySource(string $version)

Gets migration data from *.migrate_drupal.yml sorted by source module.

Parameters

string $version

The legacy Drupal version.

protected string getSourceState(string $version, string $source_module)

Tests if a destination exists for the given source module.

Parameters

string $version

Source version of Drupal.

string $source_module

Source module.

Return Value

string

Migration state, either 'finished' or 'not_finished'.

protected array getDestinationsForSource(string $version, string $source_module)

Get net destinations for source module.

Parameters

string $version

Source version.

string $source_module

Source module.

Return Value

array

Destination modules either declared by {modulename}.migrate_drupal.yml files or discovered from migration plugins.