Commit 52bfbe0a authored by catch's avatar catch
Browse files

Issue #3111344 by Gábor Hojtsy, andypost, quietone: Remove deprecated code from migrate module

parent d33f3753
......@@ -85,26 +85,6 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
*/
public function getMessages(array $source_id_values = [], $level = NULL);
/**
* Retrieves an iterator over messages relate to source records.
*
* @param array $source_id_values
* (optional) The source identifier keyed values of the record, e.g.
* ['nid' => 5]. If empty (the default), all messages are retrieved.
* @param int $level
* (optional) Message severity. If NULL (the default), retrieve messages of
* all severities.
*
* @return \Iterator
* Retrieves an iterator over the message rows.
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
* Use \Drupal\migrate\Plugin\MigrateIdMapInterface::getMessages() instead.
*
* @see https://www.drupal.org/node/3060969
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL);
/**
* Prepares to run a full update.
*
......@@ -226,25 +206,6 @@ public function getRowsNeedingUpdate($count);
*/
public function lookupSourceId(array $destination_id_values);
/**
* Looks up the destination identifier corresponding to a source key.
*
* Given a (possibly multi-field) source identifier value, return the
* (possibly multi-field) destination identifier value it is mapped to.
*
* @param array $source_id_values
* The source identifier keyed values of the record, e.g. ['nid' => 5].
*
* @return array
* The destination identifier values of the record, or empty on failure.
*
* @deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Use
* lookupDestinationIds() instead.
*
* @see https://www.drupal.org/node/2725809
*/
public function lookupDestinationId(array $source_id_values);
/**
* Looks up the destination identifiers corresponding to a source key.
*
......
......@@ -63,20 +63,13 @@ public function __construct(ModuleHandlerInterface $module_handler, CacheBackend
* Gets the plugin discovery.
*
* This method overrides DefaultPluginManager::getDiscovery() in order to
* search for migration configurations in the MODULENAME/migrations and
* MODULENAME/migration_templates directories. Throws a deprecation notice if
* the MODULENAME/migration_templates directory exists.
* search for migration configurations in the MODULENAME/migrations
* directory.
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$directories = array_map(function ($directory) {
// Check for use of the @deprecated /migration_templates directory.
// @todo Remove use of /migration_templates in Drupal 9.0.0.
if (is_dir($directory . '/migration_templates')) {
@trigger_error('Use of the /migration_templates directory to store migration configuration files is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0. See https://www.drupal.org/node/2920988.', E_USER_DEPRECATED);
}
// But still accept configurations found in /migration_templates.
return [$directory . '/migration_templates', $directory . '/migrations'];
return [$directory . '/migrations'];
}, $this->moduleHandler->getModuleDirectories());
$yaml_discovery = new YamlDirectoryDiscovery($directories, 'migrate');
......
<?php
namespace Drupal\migrate\Plugin\migrate\process;
@trigger_error('The ' . __NAMESPACE__ . ' \DedupeEntityBase is deprecated in
Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . ' \MakeUniqueEntityFieldBase', E_USER_DEPRECATED);
/**
* This abstract base contains the dedupe logic.
*
* These plugins avoid duplication at the destination. For example, when
* creating filter format names, the current value is checked against the
* existing filter format names and if it exists, a numeric postfix is added
* and incremented until a unique value is created.
*
* @link https://www.drupal.org/node/2345929 Online handbook documentation for dedupebase process plugin @endlink
*
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use
* \Drupal\migrate\Plugin\migrate\process\MakeUniqueBase instead.
*
* @see https://www.drupal.org/node/2873762
*/
abstract class DedupeBase extends MakeUniqueBase {
}
<?php
namespace Drupal\migrate\Plugin\migrate\process;
@trigger_error('The ' . __NAMESPACE__ . ' \DedupeEntity is deprecated in
Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . ' \MakeUniqueEntityField', E_USER_DEPRECATED);
/**
* Ensures value is not duplicated against an entity field.
*
* If the 'migrated' configuration value is true, an entity will only be
* considered a duplicate if it was migrated by the current migration.
*
* @link https://www.drupal.org/node/2135325 Online handbook documentation for dedupe_entity process plugin @endlink
*
* @MigrateProcessPlugin(
* id = "dedupe_entity"
* )
*
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use
* \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField instead.
*
* @see https://www.drupal.org/node/2873762
*/
class DedupeEntity extends MakeUniqueEntityField {}
<?php
namespace Drupal\migrate\Plugin\migrate\process;
@trigger_error('The ' . __NAMESPACE__ . '\Iterator is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\SubProcess', E_USER_DEPRECATED);
/**
* Iterates and processes an associative array.
*
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use
* \Drupal\migrate\Plugin\migrate\process\SubProcess instead.
*
* @see https://www.drupal.org/node/2880427
*
* @MigrateProcessPlugin(
* id = "iterator",
* handle_multiples = TRUE
* )
*/
class Iterator extends SubProcess {}
......@@ -11,7 +11,6 @@
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -30,18 +29,6 @@ class MenuLinkParent extends ProcessPluginBase implements ContainerFactoryPlugin
*/
protected $menuLinkManager;
/**
* The Migration process plugin.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @deprecated in drupal:8.8.x and is removed from drupal:9.0.0. Use
* the migrate.lookup service instead.
*
* @see https://www.drupal.org/node/3047268
*/
protected $migrationPlugin;
/**
* The currently running migration.
*
......@@ -80,19 +67,9 @@ class MenuLinkParent extends ProcessPluginBase implements ContainerFactoryPlugin
* The currently running migration.
*/
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, $plugin_definition, $migrate_lookup, MenuLinkManagerInterface $menu_link_manager, EntityStorageInterface $menu_link_storage, MigrationInterface $migration = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateLookupInterface $migrate_lookup, MenuLinkManagerInterface $menu_link_manager, EntityStorageInterface $menu_link_storage, MigrationInterface $migration) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if ($migrate_lookup instanceof MigrateProcessInterface) {
@trigger_error('Passing a migration process plugin as the fourth argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$this->migrationPlugin = $migrate_lookup;
$migrate_lookup = \Drupal::service('migrate.lookup');
}
elseif (!$migrate_lookup instanceof MigrateLookupInterface) {
throw new \InvalidArgumentException("The fourth argument to " . __METHOD__ . " must be an instance of MigrateLookupInterface.");
}
elseif (!$migration instanceof MigrationInterface) {
throw new \InvalidArgumentException("The seventh argument to " . __METHOD__ . " must be an instance of MigrationInterface.");
}
$this->migration = $migration;
$this->migrateLookup = $migrate_lookup;
$this->menuLinkManager = $menu_link_manager;
......@@ -126,26 +103,9 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
// Top level item.
return '';
}
// This BC layer is included because if the plugin constructor was called
// in the legacy way with a migration_lookup process plugin, it may have
// been preconfigured with a different migration to look up against. While
// this is unlikely, for maximum BC we will continue to use the plugin to do
// the lookup if it is provided, and support for this will be removed in
// Drupal 9.
if ($this->migrationPlugin) {
try {
$already_migrated_id = $this
->migrationPlugin
->transform($parent_id, $migrate_executable, $row, $destination_property);
}
catch (MigrateSkipRowException $e) {
}
}
else {
$lookup_result = $this->migrateLookup->lookup($this->migration->id(), [$parent_id]);
if ($lookup_result) {
$already_migrated_id = $lookup_result[0]['id'];
}
$lookup_result = $this->migrateLookup->lookup($this->migration->id(), [$parent_id]);
if ($lookup_result) {
$already_migrated_id = $lookup_result[0]['id'];
}
if (!empty($already_migrated_id) && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
......
<?php
namespace Drupal\migrate\Plugin\migrate\process;
@trigger_error('The ' . __NAMESPACE__ . '\Migration is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MigrationLookup', E_USER_DEPRECATED);
/**
* Calculates the value of a property based on a previous migration.
*
* @link https://www.drupal.org/node/2149801 Online handbook documentation for migration process plugin @endlink
*
* @MigrateProcessPlugin(
* id = "migration"
* )
*
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0.
* Use \Drupal\migrate\Plugin\migrate\process\MigrationLookup instead.
*/
class Migration extends MigrationLookup {}
......@@ -146,18 +146,9 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
* The migrate stub service.
*/
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, $migrate_lookup, $migrate_stub = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateLookupInterface $migrate_lookup, MigrateStubInterface $migrate_stub) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if (!$migrate_lookup instanceof MigrateLookupInterface) {
@trigger_error('Not passing the migrate lookup service as the fifth parameter to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \\Drupal\\migrate\\MigrateLookupInterface. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$migrate_lookup = \Drupal::service('migrate.lookup');
}
if (!$migrate_stub instanceof MigrateStubInterface) {
@trigger_error('Not passing the migrate stub service as the sixth parameter to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \\Drupal\\migrate\\MigrateStubInterface. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$migrate_stub = \Drupal::service('migrate.stub');
}
$this->migration = $migration;
$this->migrateLookup = $migrate_lookup;
$this->migrateStub = $migrate_stub;
}
......
name: 'Migration directory test'
type: module
package: Testing
version: VERSION
dependencies:
- drupal:migrate
id: migration_templates_test
label: Migration templates test
source:
plugin: embedded_data
process:
id: id
destination:
plugin: null
<?php
namespace Drupal\Tests\migrate\Kernel;
/**
* @deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use
* \Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase::migrateFields()
* instead.
*/
use Drupal\comment\Entity\CommentType;
use Drupal\node\Entity\NodeType;
/**
* Provides methods for testing node and comment combinations.
*/
trait NodeCommentCombinationTrait {
/**
* Creates a node type with a corresponding comment type.
*
* @param string $node_type
* The node type ID.
* @param string $comment_type
* (optional) The comment type ID, if not provided defaults to
* comment_node_{type}.
*/
protected function createNodeCommentCombination($node_type, $comment_type = NULL) {
@trigger_error('NodeCommentCombinationTrait::createNodeCommentCombination() is deprecated in Drupal 8.7.x, will be removed before Drupal 9.0.0. Use \Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase::migrateFields() instead.', E_USER_DEPRECATED);
if (!$comment_type) {
$comment_type = "comment_node_$node_type";
}
NodeType::create([
'type' => $node_type,
'label' => $this->randomString(),
])->save();
CommentType::create([
'id' => $comment_type,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
])->save();
}
}
<?php
namespace Drupal\Tests\migrate\Kernel\Plugin;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
/**
* Tests that migrations exist in the migration_templates directory.
*
* @group migrate
* @group legacy
*/
class MigrationDirectoryTest extends MigrateDrupalTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migration_directory_test'];
/**
* Tests that migrations in the migration_templates directory are created.
*
* @expectedDeprecation Use of the /migration_templates directory to store migration configuration files is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0. See https://www.drupal.org/node/2920988.
*/
public function testMigrationDirectory() {
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
$plugin_manager = $this->container->get('plugin.manager.migration');
// Tests that a migration in directory 'migration_templates' is discovered.
$this->assertTrue($plugin_manager->hasDefinition('migration_templates_test'));
}
}
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\migrate\Plugin\migrate\process\DedupeEntity;
/**
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\DedupeEntity
* @group migrate
* @group legacy
*/
class DedupeEntityTest extends MigrateProcessTestCase {
/**
* The mock entity query.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $entityQuery;
/**
* The mocked entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* The migration configuration, initialized to set the ID to test.
*
* @var array
*/
protected $migrationConfiguration = [
'id' => 'test',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->entityQuery = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryInterface')
->disableOriginalConstructor()
->getMock();
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$storage = $this->createMock(EntityStorageInterface::class);
$storage->expects($this->any())
->method('getQuery')
->willReturn($this->entityQuery);
$this->entityTypeManager->expects($this->any())
->method('getStorage')
->with('test_entity_type')
->willReturn($storage);
parent::setUp();
}
/**
* Tests entity based deduplication based on providerTestDedupe() values.
*
* @dataProvider providerTestDedupe
*/
public function testDedupe($count, $postfix = '', $start = NULL, $length = NULL) {
$configuration = [
'entity_type' => 'test_entity_type',
'field' => 'test_field',
];
if ($postfix) {
$configuration['postfix'] = $postfix;
}
$configuration['start'] = isset($start) ? $start : NULL;
$configuration['length'] = isset($length) ? $length : NULL;
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
$this->entityQueryExpects($count);
$value = $this->randomMachineName(32);
$actual = $plugin->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
$expected = mb_substr($value, $start, $length);
$expected .= $count ? $postfix . $count : '';
$this->assertSame($expected, $actual);
}
/**
* Tests that invalid start position throws an exception.
*/
public function testDedupeEntityInvalidStart() {
$configuration = [
'entity_type' => 'test_entity_type',
'field' => 'test_field',
'start' => 'foobar',
];
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
$this->expectException('Drupal\migrate\MigrateException');
$this->expectExceptionMessage('The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.');
$plugin->transform('test_start', $this->migrateExecutable, $this->row, 'testproperty');
}
/**
* Tests that invalid length option throws an exception.
*/
public function testDedupeEntityInvalidLength() {
$configuration = [
'entity_type' => 'test_entity_type',
'field' => 'test_field',
'length' => 'foobar',
];
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
$this->expectException('Drupal\migrate\MigrateException');
$this->expectExceptionMessage('The character length configuration key should be an integer. Omit this key to capture the entire string.');
$plugin->transform('test_length', $this->migrateExecutable, $this->row, 'testproperty');
}
/**
* Data provider for testDedupe().
*/
public function providerTestDedupe() {
return [
// Tests no duplication.
[0],
// Tests no duplication and start position.
[0, NULL, 10],
// Tests no duplication, start position, and length.
[0, NULL, 5, 10],
// Tests no duplication and length.
[0, NULL, NULL, 10],
// Tests duplication.
[3],
// Tests duplication and start position.
[3, NULL, 10],
// Tests duplication, start position, and length.
[3, NULL, 5, 10],
// Tests duplication and length.
[3, NULL, NULL, 10],
// Tests no duplication and postfix.
[0, '_'],
// Tests no duplication, postfix, and start position.
[0, '_', 5],
// Tests no duplication, postfix, start position, and length.
[0, '_', 5, 10],
// Tests no duplication, postfix, and length.
[0, '_', NULL, 10],
// Tests duplication and postfix.
[2, '_'],
// Tests duplication, postfix, and start position.
[2, '_', 5],
// Tests duplication, postfix, start position, and length.
[2, '_', 5, 10],
// Tests duplication, postfix, and length.
[2, '_', NULL, 10],
];
}
/**
* Helper function to add expectations to the mock entity query object.
*
* @param int $count
* The number of deduplications to be set up.
*/
protected function entityQueryExpects($count) {
$this->entityQuery->expects($this->exactly($count + 1))
->method('condition')
->will($this->returnValue($this->entityQuery));
$this->entityQuery->expects($this->exactly($count + 1))
->method('count')
->will($this->returnValue($this->entityQuery));
$this->entityQuery->expects($this->exactly($count + 1))
->method('execute')
->will($this->returnCallback(function () use (&$count) {
return $count--;
}));
}
/**
* Test deduplicating only migrated entities.
*/
public function testDedupeMigrated() {
$configuration = [
'entity_type' => 'test_entity_type',
'field' => 'test_field',
'migrated' => TRUE,
];
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
// Setup the entityQuery used in DedupeEntity::exists. The map, $map, is
// an array consisting of the four input parameters to the query condition
// method and then the query to return. Both 'forum' and
// 'test_vocab' are existing entities. There is no 'test_vocab1'.
$map = [];
foreach (['forums', 'test_vocab', 'test_vocab1'] as $id) {
$query = $this->prophesize(QueryInterface::class);
$query->willBeConstructedWith([]);
$query->execute()->willReturn($id === 'test_vocab1' ? [] : [$id]);
$map[] = ['test_field', $id, NULL, NULL, $query->reveal()];
}
$this->entityQuery
->method('condition')
->will($this->returnValueMap($map));
// Entity 'forums' is pre-existing, entity 'test_vocab' was migrated.
$this->idMap
->method('lookupSourceId')
->will($this->returnValueMap([
[['test_field' => 'forums'], FALSE],
[['test_field' => 'test_vocab'], ['source_id' => 42]],
]));
// Existing entity 'forums' was not migrated, it should not be deduplicated.
$actual = $plugin->transform('forums', $this->migrateExecutable, $this->row, 'testproperty');
$this->assertEquals('forums', $actual, 'Pre-existing name is re-used');
// Entity 'test_vocab' was migrated, should be deduplicated.
$actual = $plugin->transform('test_vocab', $this->migrateExecutable, $this->row, 'testproperty');
$this->assertEquals('test_vocab1', $actual, 'Migrated name is deduplicated');
}
}