class MigrateExecutable implements MigrateExecutableInterface (View source)

Defines a migrate executable class.

Traits

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

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected MigrationInterface $migration

The configuration of the migration to do.

protected int $sourceRowStatus

Status of one row.

protected float $memoryThreshold

The ratio of the memory limit at which an operation will be interrupted.

protected int $memoryLimit

The PHP memory_limit expressed in bytes.

protected array $sourceIdValues

The configuration values of the source.

protected array $counts

An array of counts. Initially used for cache hit/miss tracking.

protected MigrateSourceInterface $source

The source.

protected EventDispatcherInterface $eventDispatcher

The event dispatcher.

MigrateMessageInterface $message

Migration message service.

Methods

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(MigrationInterface $migration, MigrateMessageInterface $message = NULL, EventDispatcherInterface $event_dispatcher = NULL)

Constructs a MigrateExecutable and verifies and sets the memory limit.

getSource()

Returns the source.

EventDispatcherInterface
getEventDispatcher()

Gets the event dispatcher.

import()

Performs an import operation - migrate items from source to destination.

rollback()

Performs a rollback operation - remove previously-imported items.

getIdMap()

Get the ID map from the current migration.

processRow(Row $row, array $process = NULL, mixed $value = NULL)

Processes a row.

array
currentSourceIds()

Fetches the key array for the current source record.

saveMessage(string $message, int $level = MigrationInterface::MESSAGE_ERROR)

Passes messages through to the map class.

handleException(Exception $exception, bool $save = TRUE)

Takes an Exception object and both saves and displays it.

checkStatus()

Checks for exceptional conditions, and display feedback.

bool
memoryExceeded()

Tests whether we've exceeded the desired memory threshold.

int
getMemoryUsage()

Returns the memory usage so far.

int
attemptMemoryReclaim()

Tries to reclaim memory.

string
formatSize(int $size)

Generates a string representation for the given byte count.

Details

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(MigrationInterface $migration, MigrateMessageInterface $message = NULL, EventDispatcherInterface $event_dispatcher = NULL)

Constructs a MigrateExecutable and verifies and sets the memory limit.

Parameters

MigrationInterface $migration

The migration to run.

MigrateMessageInterface $message

(optional) The migrate message service.

EventDispatcherInterface $event_dispatcher

(optional) The event dispatcher.

protected MigrateSourceInterface getSource()

Returns the source.

Makes sure source is initialized based on migration settings.

Return Value

MigrateSourceInterface

The source.

protected EventDispatcherInterface getEventDispatcher()

Gets the event dispatcher.

Return Value

EventDispatcherInterface

import()

Performs an import operation - migrate items from source to destination.

rollback()

Performs a rollback operation - remove previously-imported items.

protected MigrateIdMapInterface getIdMap()

Get the ID map from the current migration.

Return Value

MigrateIdMapInterface

The ID map.

processRow(Row $row, array $process = NULL, mixed $value = NULL)

Processes a row.

Parameters

Row $row

The $row to be processed.

array $process

(optional) A process pipeline configuration. If not set, the top level process configuration in the migration entity is used.

mixed $value

(optional) Initial value of the pipeline for the first destination. Usually setting this is not necessary as $process typically starts with a 'get'. This is useful only when the $process contains a single destination and needs to access a value outside of the source. See \Drupal\migrate\Plugin\migrate\process\SubProcess::transformKey for an example.

Exceptions

MigrateException

protected array currentSourceIds()

Fetches the key array for the current source record.

Return Value

array

The current source IDs.

saveMessage(string $message, int $level = MigrationInterface::MESSAGE_ERROR)

Passes messages through to the map class.

Parameters

string $message

The message to record.

int $level

(optional) Message severity (defaults to MESSAGE_ERROR).

protected handleException(Exception $exception, bool $save = TRUE)

Takes an Exception object and both saves and displays it.

Pulls in additional information on the location triggering the exception.

Parameters

Exception $exception

Object representing the exception.

bool $save

(optional) Whether to save the message in the migration's mapping table. Set to FALSE in contexts where this doesn't make sense.

protected checkStatus()

Checks for exceptional conditions, and display feedback.

protected bool memoryExceeded()

Tests whether we've exceeded the desired memory threshold.

If so, output a message.

Return Value

bool

TRUE if the threshold is exceeded, otherwise FALSE.

protected int getMemoryUsage()

Returns the memory usage so far.

Return Value

int

The memory usage.

protected int attemptMemoryReclaim()

Tries to reclaim memory.

Return Value

int

The memory usage after reclaim.

protected string formatSize(int $size)

Generates a string representation for the given byte count.

Parameters

int $size

A size in bytes.

Return Value

string

A translated string representation of the size.