Commit 2d4ed02c authored by heddn's avatar heddn Committed by heddn
Browse files

Issue #3100463 by heddn: Support Drupal 9

parent c8cc517a
INTRODUCTION
------------
The migrate_example module demonstrates how to implement custom migrations
for Drupal 8. It includes a group of "beer" migrations demonstrating a complete
for Drupal 8+. It includes a group of "beer" migrations demonstrating a complete
simple migration scenario.
THE BEER SITE
......@@ -15,7 +15,7 @@ to the basic structure.
To make the example as simple as to run as possible, the source data is placed
in tables directly in your Drupal database - in most real-world scenarios, your
source data will be in an external database. The migrate_example_setup submodule
creates and populates these tables, as well as configuring your Drupal 8 site
creates and populates these tables, as well as configuring your Drupal 8+ site
(creating a node type, vocabulary, fields, etc.) to receive the data.
STRUCTURE
......
type: module
name: Migrate Example
description: 'Examples of how Drupal 8 migration compares to previous versions.'
description: 'Examples of how Drupal 8+ migration compares to previous versions.'
package: Examples
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:migrate
- migrate_plus:migrate_example_setup
......
......@@ -39,6 +39,7 @@ content:
weight: 7
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......@@ -81,6 +82,7 @@ content:
weight: 1
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......
......@@ -2,8 +2,8 @@ type: module
name: Migrate Example Setup
description: 'Separate site configuration for the example from the actual migration.'
package: Migration
core: 8.x
hidden: 1
core_version_requirement: ^8 || ^9
hidden: true
dependencies:
- drupal:comment
- drupal:image
......
INTRODUCTION
------------
The migrate_example_advanced module demonstrates some techniques for Drupal 8
The migrate_example_advanced module demonstrates some techniques for Drupal 8+
migrations beyond the basics in migrate_example. It includes a group of
migrations with a wine theme.
......@@ -42,7 +42,7 @@ example:
UNDERSTANDING THE MIGRATIONS
----------------------------
Basic techniques demonstrated in the migrate_example module are not rehashed
here - it is expected that if you are learning Drupal 8 migration, you will
here - it is expected that if you are learning Drupal 8+ migration, you will
study and understand those examples first, and use migrate_example_advanced to
learn about specific techniques beyond those basics. This example doesn't have
the narrative form of migrate_example - it's more of a grab-bag demonstrating
......
type: module
name: Migrate Example (Advanced)
description: 'Specialized examples of Drupal 8 migration.'
description: 'Specialized examples of Drupal 8+ migration.'
package: Examples
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:migrate
- migrate_plus:migrate_example_advanced_setup
......
......@@ -30,6 +30,7 @@ content:
weight: 32
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......@@ -63,6 +64,7 @@ content:
weight: 5
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......
......@@ -56,6 +56,7 @@ content:
weight: 34
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......@@ -70,6 +71,7 @@ content:
weight: 33
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......@@ -78,6 +80,7 @@ content:
weight: 32
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......@@ -111,6 +114,7 @@ content:
weight: 5
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
......
......@@ -2,8 +2,8 @@ type: module
name: Migrate Advanced Example Setup
description: 'Separate site configuration for the example from the actual migration.'
package: Migration
core: 8.x
hidden: 1
core_version_requirement: ^8 || ^9
hidden: true
dependencies:
- drupal:comment
- drupal:image
......
......@@ -81,6 +81,7 @@ content:
weight: 5
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
region: content
......
......@@ -2,7 +2,7 @@ type: module
name: Migrate JSON Example
description: 'Simple JSON Migration example'
package: Examples
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:migrate
- migrate_plus:migrate_plus
......@@ -2,10 +2,6 @@ type: module
name: Migrate Plus
description: 'Enhancements to core migration support'
package: Migration
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:migrate
test_dependencies:
- entity
- profile
......@@ -80,10 +80,10 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug
* The data fetcher plugin.
*/
public function getDataFetcherPlugin() {
if (!isset($this->dataFetcherPlugin)) {
$this->dataFetcherPlugin = \Drupal::service('plugin.manager.migrate_plus.data_fetcher')->createInstance($this->configuration['data_fetcher_plugin'], $this->configuration);
if (!isset($this->dataFetcher)) {
$this->dataFetcher = \Drupal::service('plugin.manager.migrate_plus.data_fetcher')->createInstance($this->configuration['data_fetcher_plugin'], $this->configuration);
}
return $this->dataFetcherPlugin;
return $this->dataFetcher;
}
/**
......
......@@ -87,21 +87,18 @@ class Migration extends ConfigEntityBase implements MigrationInterface {
public static function createEntityFromPlugin($plugin_id, $new_plugin_id) {
/** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
$plugin_manager = \Drupal::service('plugin.manager.migration');
/** @var \Drupal\migrate\Plugin\Migration $migration_plugin */
$migration_plugin = $plugin_manager->createInstance($plugin_id);
$entity_array['id'] = $new_plugin_id;
$plugin_definition = $migration_plugin->getPluginDefinition();
$migration_details['class'] = $plugin_definition['class'];
if (isset($plugin_definition['field_plugin_method'])) {
$migration_details['field_plugin_method'] = $plugin_definition['field_plugin_method'];
}
$entity_array['migration_tags'] = $migration_plugin->get('migration_tags');
$entity_array['migration_tags'] = $plugin_definition['migration_tags'];
$entity_array['label'] = $migration_plugin->label();
$entity_array['source'] = $migration_plugin->getSourceConfiguration();
$entity_array['destination'] = $migration_plugin->getDestinationConfiguration();
$entity_array['process'] = $migration_plugin->getProcess();
$entity_array['migration_dependencies'] = $migration_plugin->getMigrationDependencies();
$migration_entity = static::create($entity_array);
return $migration_entity;
return static::create($entity_array);
}
}
......@@ -161,6 +161,7 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface,
// When batching, make sure we have the same properties in the same order
// every time.
$values = [];
if ($batch_inserts) {
$destination_properties = array_keys($this->migration->getProcess());
$destination_properties = array_merge($destination_properties,
......
......@@ -2,7 +2,6 @@ type: module
name: Migrate Plus Test
description: 'Test module to test Migrate Plus.'
package: Testing
core: 8.x
dependencies:
- drupal:migrate (>=8.3)
- drupal:migrate
- migrate_plus:migrate_plus
......@@ -12,7 +12,6 @@ use Drupal\Tests\BrowserTestBase;
*/
class LoadTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
......@@ -32,6 +31,11 @@ class LoadTest extends BrowserTestBase {
*/
protected $user;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
......
<?php
namespace Drupal\Tests\migrate_plus\Functional;
namespace Drupal\Tests\migrate_plus\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Row;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
/**
......@@ -13,14 +14,18 @@ use Drupal\user\Entity\User;
*
* @group migrate_plus
*/
class EntityLookupAccessTest extends BrowserTestBase {
class EntityLookupAccessTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'migrate_plus',
'entity_test',
'migrate',
'migrate_plus',
'system',
'user',
];
/**
......@@ -47,6 +52,11 @@ class EntityLookupAccessTest extends BrowserTestBase {
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', ['sequences']);
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installConfig('user');
$this->user = $this->createUser(['view all entity_test_query_access entities']);
$this->entity = EntityTest::create(['name' => $this->randomMachineName(8)]);
}
......@@ -80,15 +90,24 @@ class EntityLookupAccessTest extends BrowserTestBase {
// Set access_check true.
$configuration = $configuration_base + ['access_check' => TRUE];
// Test as anonymous.
$anonymous = User::getAnonymousUser();
$this->setCurrentUser($anonymous);
$plugin = \Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_lookup', $configuration, $migration);
// Check the entity is not found.
$value = $plugin->transform($this->entity->id(), $executable, $row, 'id');
$this->assertNull($value);
// Test as authenticated user.
$this->setCurrentUser($this->user);
$plugin = \Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_lookup', $configuration, $migration);
// Check the entity is found.
$value = $plugin->transform($this->entity->id(), $executable, $row, 'id');
$this->assertSame($this->entity->id(), $value);
// Retest with access check false.
$configuration = $configuration_base + ['access_check' => FALSE];
$plugin = \Drupal::service('plugin.manager.migrate.process')
......
......@@ -60,7 +60,7 @@ class MigrationConfigEntityTest extends MigrateTestBase {
]);
$config->save();
$this->assertTrue($this->pluginManager->getDefinition('test'));
$this->assertNotEmpty($this->pluginManager->getDefinition('test'));
$this->assertSame('Label A', $this->pluginManager->getDefinition('test')['label']);
// Clear static cache in the plugin manager, the cache tag take care of the
......@@ -107,7 +107,8 @@ class MigrationConfigEntityTest extends MigrateTestBase {
$this->assertCount(1, $definitions);
$this->assertArrayHasKey('test_active', $definitions);
$this->setExpectedException(PluginNotFoundException::class, 'The "test_inactive" plugin does not exist.');
$this->expectException(PluginNotFoundException::class);
$this->expectExceptionMessage('The "test_inactive" plugin does not exist.');
$this->pluginManager->getDefinition('test_inactive');
}
......
......@@ -264,7 +264,7 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
$migration = $this->migrationPluginManager->createStubMigration($definition);
$migrationExecutable = (new MigrateExecutable($migration, $this));
$migrationExecutable->import();
$this->assertEquals('Destination field type integer is not a recognized reference type.', $migration->getIdMap()->getMessageIterator()->fetch()->message);
$this->assertEquals('Destination field type integer is not a recognized reference type.', $migration->getIdMap()->getMessages()->fetch()->message);
$this->assertSame(1, $migration->getIdMap()->messageCount());
// Enough context is provided so this should work.
......
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