MigrationState
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
The
(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:
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 | $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
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Construct a new MigrationState object.
Gets the upgrade states for all enabled source modules.
Gets migration state information from *.migrate_drupal.yml.
Determines migration state for each source module enabled on the source.
Builds migration source and destination module information.
Gets migration data from *.migrate_drupal.yml sorted by source module.
Tests if a destination exists for the given source module.
Get net destinations for source module.
Details
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets 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
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
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.
protected array
getMigrationStates()
Gets migration state information from *.migrate_drupal.yml.
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.
protected
buildDiscoveredDestinationsBySource(string $version, array $migrations, array $source_system_data)
Builds migration source and destination module information.
protected
buildDeclaredStateBySource(string $version)
Gets migration data from *.migrate_drupal.yml sorted by source module.
protected string
getSourceState(string $version, string $source_module)
Tests if a destination exists for the given source module.
protected array
getDestinationsForSource(string $version, string $source_module)
Get net destinations for source module.