Commit 752b99ff authored by webchick's avatar webchick

Issue #2443615 by benjy: Add an interface to MigrateExecutable

parent 518eff9b
......@@ -16,7 +16,7 @@
/**
* Defines a migrate executable class.
*/
class MigrateExecutable {
class MigrateExecutable implements MigrateExecutableInterface {
use StringTranslationTrait;
/**
......@@ -222,7 +222,7 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa
* @return \Drupal\migrate\Source
* The source.
*/
public function getSource() {
protected function getSource() {
if (!isset($this->source)) {
$this->source = new Source($this->migration, $this);
}
......@@ -230,7 +230,7 @@ public function getSource() {
}
/**
* Performs an import operation - migrate items from source to destination.
* {@inheritdoc}
*/
public function import() {
// Knock off migration if the requirements haven't been met.
......@@ -347,22 +347,7 @@ public function import() {
}
/**
* Processes a row.
*
* @param \Drupal\migrate\Row $row
* The $row to be processed.
* @param array $process
* (optional) A process pipeline configuration. If not set, the top level
* process configuration in the migration entity is used.
* @param 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\Iterator::transformKey for an
* example.
*
* @throws \Drupal\migrate\MigrateException
* {@inheritdoc}
*/
public function processRow(Row $row, array $process = NULL, $value = NULL) {
foreach ($this->migration->getProcessPlugins($process) as $destination => $plugins) {
......@@ -444,10 +429,7 @@ protected function timeOptionExceeded() {
}
/**
* Returns the time limit.
*
* @return null|int
* The time limit, NULL if no limit or if the units were not in seconds.
* {@inheritdoc}
*/
public function getTimeLimit() {
$limit = $this->limit;
......@@ -460,31 +442,21 @@ public function getTimeLimit() {
}
/**
* Passes messages through to the map class.
*
* @param string $message
* The message to record.
* @param int $level
* (optional) Message severity (defaults to MESSAGE_ERROR).
* {@inheritdoc}
*/
public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR) {
$this->migration->getIdMap()->saveMessage($this->sourceIdValues, $message, $level);
}
/**
* Queues messages to be later saved through the map class.
*
* @param string $message
* The message to record.
* @param int $level
* (optional) Message severity (defaults to MESSAGE_ERROR).
* {@inheritdoc}
*/
public function queueMessage($message, $level = MigrationInterface::MESSAGE_ERROR) {
$this->queuedMessages[] = array('message' => $message, 'level' => $level);
}
/**
* Saves any messages we've queued up to the message table.
* {@inheritdoc}
*/
public function saveQueuedMessages() {
foreach ($this->queuedMessages as $queued_message) {
......@@ -641,7 +613,7 @@ protected function getTimeElapsed() {
* (optional) Whether to save the message in the migration's mapping table.
* Set to FALSE in contexts where this doesn't make sense.
*/
public function handleException(\Exception $exception, $save = TRUE) {
protected function handleException(\Exception $exception, $save = TRUE) {
$result = Error::decodeException($exception);
$message = $result['!message'] . ' (' . $result['%file'] . ':' . $result['%line'] . ')';
if ($save) {
......
<?php
/**
* @file
* Contains \Drupal\migrate\MigrateExecutableInterface
*/
namespace Drupal\migrate;
use Drupal\migrate\Entity\MigrationInterface;
interface MigrateExecutableInterface {
/**
* Performs an import operation - migrate items from source to destination.
*/
public function import();
/**
* Processes a row.
*
* @param \Drupal\migrate\Row $row
* The $row to be processed.
* @param array $process
* (optional) A process pipeline configuration. If not set, the top level
* process configuration in the migration entity is used.
* @param 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\Iterator::transformKey for an
* example.
*
* @throws \Drupal\migrate\MigrateException
*/
public function processRow(Row $row, array $process = NULL, $value = NULL);
/**
* Returns the time limit.
*
* @return null|int
* The time limit, NULL if no limit or if the units were not in seconds.
*/
public function getTimeLimit();
/**
* Passes messages through to the map class.
*
* @param string $message
* The message to record.
* @param int $level
* (optional) Message severity (defaults to MESSAGE_ERROR).
*/
public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR);
/**
* Queues messages to be later saved through the map class.
*
* @param string $message
* The message to record.
* @param int $level
* (optional) Message severity (defaults to MESSAGE_ERROR).
*/
public function queueMessage($message, $level = MigrationInterface::MESSAGE_ERROR);
/**
* Saves any messages we've queued up to the message table.
*/
public function saveQueuedMessages();
}
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
......@@ -28,7 +28,7 @@ interface MigrateProcessInterface extends PluginInspectionInterface {
*
* @param mixed $value
* The value to be transformed.
* @param \Drupal\migrate\MigrateExecutable $migrate_executable
* @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
* The migration in which this process is being executed.
* @param \Drupal\migrate\Row $row
* The row from the source to process. Normally, just transforming the
......@@ -41,7 +41,7 @@ interface MigrateProcessInterface extends PluginInspectionInterface {
* @return string|array
* The newly transformed value.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property);
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property);
/**
* Indicates whether the returned value requires multiple handling.
......
......@@ -7,7 +7,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -29,7 +29,7 @@ class Callback extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_callable($this->configuration['callable'])) {
$value = call_user_func($this->configuration['callable'], $value);
}
......
......@@ -9,7 +9,7 @@
use Drupal\Component\Utility\String;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -28,7 +28,7 @@ class Concat extends ProcessPluginBase {
*
* Concatenates the strings in the current value.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value)) {
$delimiter = isset($this->configuration['delimiter']) ? $this->configuration['delimiter'] : '';
return implode($delimiter, $value);
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateException;
use Drupal\Component\Utility\Unicode;
......@@ -26,7 +26,7 @@ abstract class DedupeBase extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$i = 1;
$postfix = isset($this->configuration['postfix']) ? $this->configuration['postfix'] : '';
$start = isset($this->configuration['start']) ? $this->configuration['start'] : 0;
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
......@@ -24,7 +24,7 @@ class DefaultValue extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!empty($this->configuration['strict'])) {
return isset($value) ? $value : $this->configuration['default_value'];
}
......
......@@ -10,7 +10,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
......@@ -27,7 +27,7 @@ class Extract extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($value)) {
throw new MigrateException('Input should be an array.');
}
......
......@@ -6,7 +6,7 @@
*/
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -31,7 +31,7 @@ class Flatten extends ProcessPluginBase {
*
* For example, array(array(1, 2, array(3, 4))) becomes array(1, 2, 3, 4).
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($value)), FALSE);
}
}
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
......@@ -28,7 +28,7 @@ class Get extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$source = $this->configuration['source'];
$properties = is_string($source) ? array($source) : $source;
$return = array();
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
......@@ -26,7 +26,7 @@ class Iterator extends ProcessPluginBase {
/**
* Runs a process pipeline on each destination property per list item.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$return = array();
foreach ($value as $key => $new_value) {
$new_row = new Row($new_value, array());
......@@ -45,7 +45,7 @@ public function transform($value, MigrateExecutable $migrate_executable, Row $ro
*
* @param string|int $key
* The current key.
* @param \Drupal\migrate\MigrateExecutable $migrate_executable
* @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
* The migrate executable helper class.
* @param \Drupal\migrate\Row $row
* The current row after processing.
......@@ -53,7 +53,7 @@ public function transform($value, MigrateExecutable $migrate_executable, Row $ro
* @return mixed
* The transformed key.
*/
protected function transformKey($key, MigrateExecutable $migrate_executable, Row $row) {
protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) {
$process = array('key' => $this->configuration['key']);
$migrate_executable->processRow($row, $process, $key);
return $row->getDestinationProperty('key');
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
......@@ -33,7 +33,7 @@ class MachineName extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$new_value = $this->getTransliteration()->transliterate($value, LanguageInterface::LANGCODE_DEFAULT, '_');
$new_value = strtolower($new_value);
$new_value = preg_replace('/[^a-z0-9_]+/', '_', $new_value);
......
......@@ -17,7 +17,7 @@
use Drupal\migrate\Plugin\MigratePluginManager;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -67,7 +67,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$migration_ids = $this->configuration['migration'];
if (!is_array($migration_ids)) {
$migration_ids = array($migration_ids);
......
......@@ -10,7 +10,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -52,7 +52,7 @@ public static function create(ContainerInterface $container, array $configuratio
*
* Set the destination route information based on the source link_path.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($link_path, $options) = $value;
$extracted = $this->pathValidator->getUrlIfValidWithoutAccessCheck($link_path);
$route = array();
......
......@@ -7,7 +7,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -26,7 +26,7 @@ class SkipProcessOnEmpty extends ProcessPluginBase {
*
* Skip the rest of the processing on 0.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!$value) {
throw new MigrateSkipProcessException();
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
......@@ -25,7 +25,7 @@ class SkipRowIfNotSet extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!isset($value[$this->configuration['index']])) {
throw new MigrateSkipRowException();
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
......@@ -24,7 +24,7 @@ class SkipRowOnEmpty extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!$value) {
throw new MigrateSkipRowException();
}
......
......@@ -10,7 +10,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
......@@ -28,7 +28,7 @@ class StaticMap extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$new_value = $value;
if (is_array($value)) {
if (!$value) {
......
......@@ -199,10 +199,10 @@ public function count($refresh = FALSE) {
*
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration entity.
* @param \Drupal\migrate\MigrateExecutable $migrate_executable
* @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
* The migration executable.
*/
public function __construct(MigrationInterface $migration, MigrateExecutable $migrate_executable) {
public function __construct(MigrationInterface $migration, MigrateExecutableInterface $migrate_executable) {
$this->migration = $migration;
$this->migrateExecutable = $migrate_executable;
$configuration = $migration->get('source');
......
......@@ -10,7 +10,7 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigratePluginManager;
use Drupal\migrate\ProcessPluginBase;
......@@ -64,7 +64,7 @@ public static function create(ContainerInterface $container, array $configuratio
*
* Set the block plugin id.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value)) {
list($module, $delta) = $value;
switch ($module) {
......
......@@ -7,7 +7,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\Component\Utility\NestedArray;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -23,7 +23,7 @@ class BlockRegion extends ProcessPluginBase {
* Set the destination block region, based on the source region and theme as
* well as the current destination default theme.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($region, $source_theme, $destination_theme) = $value;
// Theme is the same on both source and destination, we will assume they
......
......@@ -7,7 +7,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
......@@ -23,7 +23,7 @@ class BlockSettings extends ProcessPluginBase {
*
* Set the block configuration.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($plugin, $delta, $old_settings) = $value;
$settings = array();
switch ($plugin) {
......
......@@ -7,7 +7,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\Core\Config\Config;
......@@ -76,7 +76,7 @@ public static function create(ContainerInterface $container, array $configuratio
*
* Set the block theme, based on the current default theme.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($theme, $d6_default_theme, $d6_admin_theme) = $value;
// If the source theme exists on the destination, we're good.
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\migrate\Entity\MigrationInterface;
......@@ -55,7 +55,7 @@ public static function create(ContainerInterface $container, array $configuratio
*
* Set the block visibility settings.
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($pages, $roles, $old_visibility) = $value;
$visibility = array();
......
......@@ -8,7 +8,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\process\Route;
......@@ -22,7 +22,7 @@ class CckFile extends Route implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($fid, $list, $data) = $value;
// If $fid is still an array at this point, that's because we have a file