Sql
class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryPluginInterface, HighestIdInterface (View source)
Defines the sql based ID map implementation.
It creates one map and one message table per migration entity to store the relevant information.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Provides dependency injection friendly methods for serialization.
Provides a trait for the messenger service.
Constants
| DERIVATIVE_SEPARATOR |
A string which is used to separate base plugin IDs from the derivative ID. |
| SOURCE_IDS_HASH |
Column name of hashed source id values. |
Properties
| protected string | $pluginId | The plugin_id. |
from PluginBase |
| protected array | $pluginDefinition | The plugin implementation definition. |
from PluginBase |
| protected array | $configuration | Configuration information passed into the plugin. |
from PluginBase |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| 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 MessengerInterface | $messenger | The messenger. |
from MessengerTrait |
| protected EventDispatcherInterface | $eventDispatcher | An event dispatcher instance to use for map events. |
|
| protected string | $mapTableName | The migration map table name. |
|
| protected string | $messageTableName | The message table name. |
|
| protected MigrateMessageInterface | $message | The migrate message service. |
|
| protected Connection | $database | The database connection for the map/message tables on the destination. |
|
| protected SelectInterface | $query | The select query. |
|
| protected MigrationInterface | $migration | The migration being done. |
|
| protected array | $sourceIdFields | The source ID fields. |
|
| protected array | $destinationIdFields | The destination ID fields. |
|
| protected bool | $initialized | Whether the plugin is already initialized. |
|
| protected StatementInterface | $result | The result. |
|
| protected array | $sourceIds | The source identifiers. |
|
| protected array | $destinationIds | The destination identifiers. |
|
| protected array|false|null | $currentRow | The current row. |
|
| protected array | $currentKey | The current key. |
Methods
Constructs an SQL object.
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.
Creates an instance of the plugin.
Retrieves the hash of the source identifier values.
The source ID fields.
The destination ID fields.
The name of the database map table.
The name of the database message table.
Get the fully qualified map table name.
Gets the database connection.
Initialize the plugin.
Create the map and message tables if they don't already exist.
Creates schema from an ID definition.
Retrieves a row from the map table based on source identifier values.
Retrieves a row by the destination identifiers.
Retrieves an array of map rows marked as needing update.
Looks up the source identifier.
Looks up the destination identifiers corresponding to a source key.
Saves a mapping from the source identifiers to the destination identifiers.
Saves a message related to a source record in the migration message table.
Retrieves a traversable object of messages related to source records.
Prepares to run a full update.
Returns the number of processed items in the map.
Returns the number of imported items in the map.
Returns a count of items which are marked as needing update.
Returns the number of items that failed to import.
Returns the number of messages saved.
Counts records in a table.
Deletes the map and message entries for a given source record.
Deletes the map and message table entries for a given destination row.
Sets a specified record to be updated, if it exists.
Clears all messages from the map.
Removes any persistent storage used by this map.
Implementation of \Iterator::rewind().
Implementation of \Iterator::current().
Implementation of \Iterator::key().
Looks up the destination identifier currently being iterated.
Looks up the source identifier(s) currently being iterated.
Implementation of \Iterator::next().
Implementation of \Iterator::valid().
Returns the migration plugin manager.
Returns the highest ID tracked by the implementing plugin.
Details
__construct(array $configuration, string $plugin_id, mixed $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher)
Constructs an SQL object.
Sets up the tables and builds the maps,
string
getPluginId()
Gets the plugin_id of the plugin instance.
string
getBaseId()
Gets the base_plugin_id of the plugin instance.
string|null
getDerivativeId()
Gets the derivative_id of the plugin instance.
array
getPluginDefinition()
Gets the definition of the plugin implementation.
bool
isConfigurable()
Determines if the plugin is configurable.
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.
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
static ContainerFactoryPluginInterface
create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition, MigrationInterface $migration = NULL)
Creates an instance of the plugin.
string
getSourceIdsHash(array $source_id_values)
| internal |
Retrieves the hash of the source identifier values.
protected array
sourceIdFields()
The source ID fields.
protected array
destinationIdFields()
The destination ID fields.
string
mapTableName()
The name of the database map table.
string
messageTableName()
The name of the database message table.
getQualifiedMapTableName()
Get the fully qualified map table name.
Connection
getDatabase()
Gets the database connection.
protected
init()
Initialize the plugin.
setMessage(MigrateMessageInterface $message)
Sets the migrate message service.
protected
ensureTables()
Create the map and message tables if they don't already exist.
protected array
getFieldSchema(array $id_definition)
Creates schema from an ID definition.
array
getRowBySource(array $source_id_values)
Retrieves a row from the map table based on source identifier values.
array
getRowByDestination(array $destination_id_values)
Retrieves a row by the destination identifiers.
array
getRowsNeedingUpdate(int $count)
Retrieves an array of map rows marked as needing update.
array
lookupSourceId(array $destination_id_values)
Looks up the source identifier.
Given a (possibly multi-field) destination identifier value, return the (possibly multi-field) source identifier value mapped to it.
array
lookupDestinationIds(array $source_id_values)
Looks up the destination identifiers corresponding to a source key.
This can look up a subset of source keys if only some are provided, and will return all destination keys that match.
saveIdMapping(Row $row, array $destination_id_values, $source_row_status = MigrateIdMapInterface::STATUS_IMPORTED, int $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE)
Saves a mapping from the source identifiers to the destination identifiers.
Called upon import of one row, we record a mapping from the source ID to the destination ID. Also may be called, setting the third parameter to NEEDS_UPDATE, to signal an existing record should be re-migrated.
saveMessage(array $source_id_values, string $message, int $level = MigrationInterface::MESSAGE_ERROR)
Saves a message related to a source record in the migration message table.
Traversable
getMessages(array $source_id_values = [], int $level = NULL)
Retrieves a traversable object of messages related to source records.
prepareUpdate()
Prepares to run a full update.
Prepares this migration to run as an update - that is, in addition to un-migrated content (source records not in the map table) being imported, previously-migrated content will also be updated in place by marking all previously-imported content as ready to be re-imported.
int
processedCount()
Returns the number of processed items in the map.
int
importedCount()
Returns the number of imported items in the map.
int
updateCount()
Returns a count of items which are marked as needing update.
int
errorCount()
Returns the number of items that failed to import.
int
messageCount()
Returns the number of messages saved.
protected int
countHelper(int|array $status = NULL, string $table = NULL)
Counts records in a table.
delete(array $source_id_values, bool $messages_only = FALSE)
Deletes the map and message entries for a given source record.
deleteDestination(array $destination_id_values)
Deletes the map and message table entries for a given destination row.
setUpdate(array $source_id_values)
Sets a specified record to be updated, if it exists.
clearMessages()
Clears all messages from the map.
destroy()
Removes any persistent storage used by this map.
For example, remove the map and message tables.
rewind()
Implementation of \Iterator::rewind().
This is called before beginning a foreach loop.
current()
Implementation of \Iterator::current().
This is called when entering a loop iteration, returning the current row.
key()
Implementation of \Iterator::key().
This is called when entering a loop iteration, returning the key of the current row. It must be a scalar - we will serialize to fulfill the requirement, but using getCurrentKey() is preferable.
array
currentDestination()
Looks up the destination identifier currently being iterated.
array
currentSource()
Looks up the source identifier(s) currently being iterated.
next()
Implementation of \Iterator::next().
This is called at the bottom of the loop implicitly, as well as explicitly from rewind().
valid()
Implementation of \Iterator::valid().
This is called at the top of the loop, returning TRUE to process the loop and FALSE to terminate it.
protected MigrationPluginManagerInterface
getMigrationPluginManager()
Returns the migration plugin manager.
int
getHighestId()
Returns the highest ID tracked by the implementing plugin.