Commit 47febbf6 authored by alexpott's avatar alexpott

Issue #2694009 by heddn: MigrationInterface doesn't include get()

parent e9fc0f1a
......@@ -91,7 +91,7 @@ public function prepareRow(Row $row) {
// the source_base_path in order to make them all relative.
// @todo https://www.drupal.org/node/2577871 Don't depend on destination
// configuration and figure out if this is even needed at all?
$path = str_replace($this->migration->get('destination')['source_base_path'], NULL, $path);
$path = str_replace($this->migration->getDestinationConfiguration()['source_base_path'], NULL, $path);
$row->setSourceProperty('filepath', $path);
return parent::prepareRow($row);
}
......
......@@ -24,7 +24,7 @@ protected function setUpMigratedFiles() {
/** @var \Drupal\migrate\Plugin\migration $migration */
$migration = $migration_plugin_manager->createInstance('d6_file');
$source = $migration->get('source');
$source = $migration->getSourceConfiguration();
$source['site_path'] = 'core/modules/simpletest';
$migration->set('source', $source);
$this->executeMigration($migration);
......
......@@ -261,7 +261,7 @@ public function import() {
$this->handleException($e);
}
}
if ($high_water_property = $this->migration->get('highWaterProperty')) {
if ($high_water_property = $this->migration->getHighWaterProperty()) {
$this->migration->saveHighWater($row->getSourceProperty($high_water_property['name']));
}
......
......@@ -131,7 +131,9 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn
protected $destinationIds = [];
/**
* Information on the high water mark.
* Information on the property used as the high watermark.
*
* Array of 'name' & (optional) db 'alias' properties used for high watermark.
*
* @var array
*/
......@@ -331,6 +333,9 @@ public function label() {
*
* @return mixed
* The value for that property, or NULL if the property does not exist.
*
* @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use
* more specific getters instead.
*/
public function get($property) {
return isset($this->$property) ? $this->$property : NULL;
......@@ -677,4 +682,39 @@ public function getPluginDefinition() {
}
return $definition;
}
/**
* {@inheritdoc}
*/
public function getDestinationConfiguration() {
return $this->destination;
}
/**
* {@inheritdoc}
*/
public function getSourceConfiguration() {
return $this->source;
}
/**
* {@inheritdoc}
*/
public function getHighWaterProperty() {
return $this->highWaterProperty;
}
/**
* {@inheritdoc}
*/
public function getTrackLastImported() {
$this->trackLastImported;
}
/**
* {@inheritdoc}
*/
public function getDestinationIds() {
$this->destinationIds;
}
}
......@@ -332,4 +332,51 @@ public function setTrackLastImported($track_last_imported);
*/
public function getMigrationDependencies();
/**
* Get the destination configuration, with at least a 'plugin' key.
*
* @return array
* The destination configuration.
*/
public function getDestinationConfiguration();
/**
* Get the source configuration, with at least a 'plugin' key.
*
* @return array
* The source configuration.
*/
public function getSourceConfiguration();
/**
* Get information on the property used as the high watermark.
*
* Array of 'name' & (optional) db 'alias' properties used for high watermark.
*
* @see Drupal\migrate\Plugin\migrate\source\SqlBase::initializeIterator()
*
* @return array
* The property used as the high watermark.
*/
public function getHighWaterProperty();
/**
* If true, track time of last import.
*
* @return bool
* Flag to determine desire of tracking time of last import.
*/
public function getTrackLastImported();
/**
* The destination identifiers.
*
* An array of destination identifiers: the keys are the name of the
* properties, the values are dependent on the ID map plugin.
*
* @return array
* Destination identifiers.
*/
public function getDestinationIds();
}
......@@ -570,7 +570,7 @@ public function saveIdMapping(Row $row, array $destination_id_values, $source_ro
$this->message->display(t('Could not save to map table due to missing destination id values'), 'error');
return;
}
if ($this->migration->get('trackLastImported')) {
if ($this->migration->getTrackLastImported()) {
$fields['last_imported'] = time();
}
$keys = [static::SOURCE_IDS_HASH => $this->getSourceIDsHash($source_id_values)];
......
......@@ -121,7 +121,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
}
$destination_plugin = $migration->getDestinationPlugin(TRUE);
// Only keep the process necessary to produce the destination ID.
$process = $migration->get('process');
$process = $migration->getProcess();
// We already have the source ID values but need to key them for the Row
// constructor.
......@@ -131,7 +131,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$values[$source_id] = $source_id_values[$migration->id()][$index];
}
$stub_row = new Row($values + $migration->get('source'), $source_ids, TRUE);
$stub_row = new Row($values + $migration->getSourceConfiguration(), $source_ids, TRUE);
// Do a normal migration with the stub row.
$migrate_executable->processRow($stub_row, $process);
......
......@@ -153,7 +153,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this->idMap = $this->migration->getIdMap();
// Pull out the current highwater mark if we have a highwater property.
if ($this->highWaterProperty = $this->migration->get('highWaterProperty')) {
if ($this->highWaterProperty = $this->migration->getHighWaterProperty()) {
$this->originalHighWater = $this->migration->getHighWater();
}
......@@ -300,7 +300,7 @@ public function next() {
$row_data = $this->getIterator()->current() + $this->configuration;
$this->getIterator()->next();
$row = new Row($row_data, $this->migration->getSourcePlugin()->getIds(), $this->migration->get('destinationIds'));
$row = new Row($row_data, $this->migration->getSourcePlugin()->getIds(), $this->migration->getDestinationIds());
// Populate the source key for this row.
$this->currentSourceIds = $row->getSourceIdValues();
......
......@@ -166,7 +166,7 @@ protected function prepareQuery() {
*/
protected function initializeIterator() {
$this->prepareQuery();
$high_water_property = $this->migration->get('highWaterProperty');
$high_water_property = $this->migration->getHighWaterProperty();
// Get the key values, for potential use in joining to the map table.
$keys = array();
......@@ -208,7 +208,7 @@ protected function initializeIterator() {
$map_key = 'sourceid' . $count;
$this->query->addField($alias, $map_key, "migrate_map_$map_key");
}
if ($n = count($this->migration->get('destinationIds'))) {
if ($n = count($this->migration->getDestinationIds())) {
for ($count = 1; $count <= $n; $count++) {
$map_key = 'destid' . $count++;
$this->query->addField($alias, $map_key, "migrate_map_$map_key");
......
......@@ -83,9 +83,9 @@ protected function getMigration() {
$configuration = &$this->migrationConfiguration;
$migration->method('get')
->willReturnCallback(function ($argument) use (&$configuration) {
return isset($configuration[$argument]) ? $configuration[$argument] : '';
$migration->method('getHighWaterProperty')
->willReturnCallback(function () use ($configuration) {
return isset($configuration['highWaterProperty']) ? $configuration['highWaterProperty'] : '';
});
$migration->method('set')
......
......@@ -76,8 +76,8 @@ public function testTransformWithStubbing() {
$migration_plugin->id()->willReturn('actual_migration');
$destination_migration->id()->willReturn('destination_migration');
$destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
$destination_migration->get('process')->willReturn([]);
$destination_migration->get('source')->willReturn([]);
$destination_migration->getProcess()->willReturn([]);
$destination_migration->getSourceConfiguration()->willReturn([]);
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
$source_plugin->getIds()->willReturn(['nid']);
......
......@@ -75,7 +75,7 @@ public function calculateDependencies() {
$this->dependencies = parent::calculateDependencies();
// Add a dependency on the module that provides the field type using the
// source plugin configuration.
$source_configuration = $this->migration->get('source');
$source_configuration = $this->migration->getSourceConfiguration();
if (isset($source_configuration['constants']['type'])) {
$field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']);
$this->addDependency('module', $field_type['provider']);
......
......@@ -112,7 +112,7 @@ public static function run($initial_ids, $operation, $config, &$context) {
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
// @TODO, remove this in https://www.drupal.org/node/2681869.
$destination = $migration->get('destination');
$destination = $migration->getDestinationConfiguration();
if ($destination['plugin'] === 'entity:file') {
// Make sure we have a single trailing slash.
$source_base_path = rtrim($config['source_base_path'], '/') . '/';
......
......@@ -27,7 +27,7 @@ protected function setUp() {
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->getMigration('d6_user_picture_file');
$source = $migration->get('source');
$source = $migration->getSourceConfiguration();
$source['site_path'] = 'core/modules/simpletest';
$migration->set('source', $source);
$this->executeMigration($migration);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment