Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/migrate_plus
  • issue/migrate_plus-2640516
  • issue/migrate_plus-2678194
  • issue/migrate_plus-3196547
  • issue/migrate_plus-3082078
  • issue/migrate_plus-2947711
  • issue/migrate_plus-3218356
  • issue/migrate_plus-3121204
  • issue/migrate_plus-3223182
  • issue/migrate_plus-3227120
  • issue/migrate_plus-3227245
  • issue/migrate_plus-3227250
  • issue/migrate_plus-3229479
  • issue/migrate_plus-3230549
  • issue/migrate_plus-3232208
  • issue/migrate_plus-3232211
  • issue/migrate_plus-3280809
  • issue/migrate_plus-3279861
  • issue/migrate_plus-3007709
  • issue/migrate_plus-3241509
  • issue/migrate_plus-3243514
  • issue/migrate_plus-3050274
  • issue/migrate_plus-3113394
  • issue/migrate_plus-3251921
  • issue/migrate_plus-3253347
  • issue/migrate_plus-3232488
  • issue/migrate_plus-3028162
  • issue/migrate_plus-3232214
  • issue/migrate_plus-3255945
  • issue/migrate_plus-3256021
  • issue/migrate_plus-3258044
  • issue/migrate_plus-3258552
  • issue/migrate_plus-2980132
  • issue/migrate_plus-3259516
  • issue/migrate_plus-3259530
  • issue/migrate_plus-3259540
  • issue/migrate_plus-3259471
  • issue/migrate_plus-3256823
  • issue/migrate_plus-3015199
  • issue/migrate_plus-3261273
  • issue/migrate_plus-3261274
  • issue/migrate_plus-3261276
  • issue/migrate_plus-3261275
  • issue/migrate_plus-3254969
  • issue/migrate_plus-3261288
  • issue/migrate_plus-3261294
  • issue/migrate_plus-2974206
  • issue/migrate_plus-2938112
  • issue/migrate_plus-3263877
  • issue/migrate_plus-3263893
  • issue/migrate_plus-3263911
  • issue/migrate_plus-3264767
  • issue/migrate_plus-3265262
  • issue/migrate_plus-3225569
  • issue/migrate_plus-3265410
  • issue/migrate_plus-3265411
  • issue/migrate_plus-3267505
  • issue/migrate_plus-3269494
  • issue/migrate_plus-2787219
  • issue/migrate_plus-2822737
  • issue/migrate_plus-3273003
  • issue/migrate_plus-3225457
  • issue/migrate_plus-3096393
  • issue/migrate_plus-3276619
  • issue/migrate_plus-3277622
  • issue/migrate_plus-3050058
  • issue/migrate_plus-3068584
  • issue/migrate_plus-3284318
  • issue/migrate_plus-3294980
  • issue/migrate_plus-2820649
  • issue/migrate_plus-3083838
  • issue/migrate_plus-3330911
  • issue/migrate_plus-3334436
  • issue/migrate_plus-3276799
  • issue/migrate_plus-3320260
  • issue/migrate_plus-3355814
  • issue/migrate_plus-3352503
  • issue/migrate_plus-3400226
  • issue/migrate_plus-3403545
  • issue/migrate_plus-3375685
  • issue/migrate_plus-3380054
  • issue/migrate_plus-3396027
  • issue/migrate_plus-3396583
  • issue/migrate_plus-3396696
  • issue/migrate_plus-3413533
  • issue/migrate_plus-3087614
  • issue/migrate_plus-3427482
  • issue/migrate_plus-3379669
  • issue/migrate_plus-3427939
  • issue/migrate_plus-3443550
  • issue/migrate_plus-2921374
  • issue/migrate_plus-3040427
  • issue/migrate_plus-3232212
  • issue/migrate_plus-3440904
  • issue/migrate_plus-2933531
  • issue/migrate_plus-3458322
  • issue/migrate_plus-3459031
  • issue/migrate_plus-3462520
  • issue/migrate_plus-2830058
  • issue/migrate_plus-3123534
  • issue/migrate_plus-3465782
  • issue/migrate_plus-3466604
  • issue/migrate_plus-3466499
  • issue/migrate_plus-3469900
  • issue/migrate_plus-3476474
  • issue/migrate_plus-3019187
  • issue/migrate_plus-2837684
  • issue/migrate_plus-3478009
  • issue/migrate_plus-3357844
  • issue/migrate_plus-2891964
  • issue/migrate_plus-3481311
  • issue/migrate_plus-3486188
  • issue/migrate_plus-3064562
  • issue/migrate_plus-3488691
  • issue/migrate_plus-3488331
  • issue/migrate_plus-3498416
  • issue/migrate_plus-3498423
  • issue/migrate_plus-3502423
  • issue/migrate_plus-3497174
  • issue/migrate_plus-2944627
  • issue/migrate_plus-3508679
121 results
Show changes
Commits on Source (14)
......@@ -151,7 +151,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt
}
else {
if ($langcode) {
throw new \InvalidArgumentException('Langcode can only be used with content entities currently.');
throw new MigrateException('Langcode can only be used with content entities currently.');
}
}
try {
......
......@@ -84,21 +84,28 @@ class Gate extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (empty($this->configuration['valid_keys']) && !array_key_exists('valid_keys', $this->configuration)) {
throw new MigrateException('Gate plugin is missing valid_keys configuration.');
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
if (!array_key_exists('valid_keys', $configuration)) {
throw new \InvalidArgumentException('Gate plugin is missing valid_keys configuration.');
}
if (empty($this->configuration['use_as_key']) && !array_key_exists('use_as_key', $this->configuration)) {
throw new MigrateException('Gate plugin is missing use_as_key configuration.');
if (!array_key_exists('use_as_key', $configuration)) {
throw new \InvalidArgumentException('Gate plugin is missing use_as_key configuration.');
}
if (empty($this->configuration['key_direction']) && !array_key_exists('key_direction', $this->configuration)) {
throw new MigrateException('Gate plugin is missing key_direction configuration.');
if (!array_key_exists('key_direction', $configuration)) {
throw new \InvalidArgumentException('Gate plugin is missing key_direction configuration.');
}
if (!in_array($this->configuration['key_direction'], ['lock', 'unlock'], TRUE)) {
throw new MigrateException('Gate plugin only accepts the following values for key_direction: lock and unlock.');
if (!in_array($configuration['key_direction'], ['lock', 'unlock'], TRUE)) {
throw new \InvalidArgumentException('Gate plugin only accepts the following values for key_direction: lock and unlock.');
}
$valid_keys = is_array($this->configuration['valid_keys']) ? $this->configuration['valid_keys'] : [$this->configuration['valid_keys']];
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$valid_keys = (array) $this->configuration['valid_keys'];
$key = $row->get($this->configuration['use_as_key']);
$key_is_valid = in_array($key, $valid_keys, TRUE);
$key_direction = $this->configuration['key_direction'];
......
......@@ -24,6 +24,9 @@ use Drupal\migrate\Row;
* configuration key value. Possible values:
* - row: Skips the entire row.
* - process: Prevents further processing of the input property
* - message: (optional) A message to be logged in the {migrate_message_*} table
* for this row. Messages are only logged for the 'row' method. If not set,
* nothing is logged in the message table.
*
* @codingStandardsIgnoreStart
*
......@@ -50,9 +53,11 @@ use Drupal\migrate\Row;
* value:
* - article
* - testimonial
* message: 'Not an article nor a testimonial content type'
* @endcode
* The above example will skip processing any row for which the source row's
* content type field is not "article" or "testimonial".
* content type field is not "article" or "testimonial", and log the message 'Not
* an article nor a testimonial content type' to the message table.
*
* @codingStandardsIgnoreEnd
*/
......@@ -61,10 +66,35 @@ class SkipOnValue extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (empty($this->configuration['value']) && !array_key_exists('value', $this->configuration)) {
throw new MigrateException('Skip on value plugin is missing value configuration.');
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
if (empty($configuration['value']) && !array_key_exists('value', $configuration)) {
throw new \InvalidArgumentException('Skip on value plugin is missing value configuration.');
}
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* Skips the current row when input value evaluates to a configured value.
*
* @param mixed $value
* The input value.
* @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.
* @param string $destination_property
* The destination property currently worked on. This is only used together
* with the $row above.
*
* @return mixed
* The input value, $value, if it doesn't evaluate to a configured value.
*
* @throws \Drupal\migrate\MigrateSkipRowException
* Thrown if the source property evaluates to a configured value and the
* row should be skipped, records with STATUS_IGNORED status in the map.
*/
public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$message = !empty($this->configuration['message']) ? $this->configuration['message'] : '';
if (is_array($this->configuration['value'])) {
$value_in_array = FALSE;
......@@ -75,24 +105,38 @@ class SkipOnValue extends ProcessPluginBase {
}
if (($not_equals && !$value_in_array) || (!$not_equals && $value_in_array)) {
throw new MigrateSkipRowException();
throw new MigrateSkipRowException($message);
}
}
elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
throw new MigrateSkipRowException();
throw new MigrateSkipRowException($message);
}
return $value;
}
/**
* {@inheritdoc}
* Stops processing the current property when input value evaluates to a
* configured value.
*
* @param mixed $value
* The input value.
* @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.
* @param string $destination_property
* The destination property currently worked on. This is only used together
* with the $row above.
*
* @return mixed
* The input value, $value, if it doesn't evaluate to a configured value.
*
* @throws \Drupal\migrate\MigrateSkipProcessException
* Thrown if the source property evaluates to a configured value and rest
* of the process should be skipped.
*/
public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (empty($this->configuration['value']) && !array_key_exists('value', $this->configuration)) {
throw new MigrateException('Skip on value plugin is missing value configuration.');
}
if (is_array($this->configuration['value'])) {
$value_in_array = FALSE;
$not_equals = isset($this->configuration['not_equals']);
......
......@@ -81,13 +81,21 @@ class StrReplace extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!isset($this->configuration['search'])) {
throw new MigrateException('"search" must be configured.');
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
if (!isset($configuration['search'])) {
throw new \InvalidArgumentException('The "search" must be set.');
}
if (!isset($this->configuration['replace'])) {
throw new MigrateException('"replace" must be configured.');
if (!isset($configuration['replace'])) {
throw new \InvalidArgumentException('The "replace" must be set.');
}
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$this->multiple = is_array($value);
$this->configuration += [
'case_insensitive' => FALSE,
......
......@@ -3,6 +3,7 @@
namespace Drupal\migrate_plus\Plugin\migrate\source;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Plugin\MigrationInterface;
......@@ -141,4 +142,14 @@ class Table extends SqlBase {
return $this->idFields;
}
/**
* {@inheritdoc}
*/
public function checkRequirements() {
if (!$this->getDatabase()->schema()->tableExists($this->tableName)) {
throw new RequirementsException("Source database table '{$this->tableName}' does not exist", ['source_table' => $this->tableName]);
}
parent::checkRequirements();
}
}
......@@ -3,10 +3,12 @@
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\node\Entity\Node;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
/**
* Tests the entity_value plugin.
......@@ -150,6 +152,31 @@ class EntityValueTest extends KernelTestBase {
$this->assertTrue($this->plugin->multiple());
}
/**
* Test the EntityLoad plugin failure.
*
* @covers ::transform
*/
public function testEntityValueLangException() {
$config_entity = NodeType::create(['type' => 'page', 'name' => 'page']);
$config_entity->save();
$this->plugin = \Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_value', [
'entity_type' => 'node_type',
'langcode' => 'es',
'field_name' => 'type',
]);
$executable = $this->prophesize(MigrateExecutableInterface::class)
->reveal();
$row = new Row();
// Ensure that the entity is returned if it really exists.
$this->expectException(MigrateException::class);
$this->expectExceptionMessage('Langcode can only be used with content entities currently.');
$this->plugin->transform([$config_entity->id()], $executable, $row, 'dummmy');
}
/**
* Test the EntityLoad plugin throwing.
*
......@@ -161,7 +188,7 @@ class EntityValueTest extends KernelTestBase {
*/
public function testEntityValueConfig($config) {
$this->expectException(\InvalidArgumentException::class);
$plugin = \Drupal::service('plugin.manager.migrate.process')
\Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_value', $config);
}
......
<?php
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\source;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests Table source plugin.
*
* @covers \Drupal\migrate_plus\Plugin\migrate\source\Table
*
* @group migrate_plus
*/
class TableTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['migrate_plus'];
/**
* The migration plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected $migrationPluginManager;
/**
* Definition of a test migration.
*
* @var array
*/
protected $migrationDefinition;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->migrationPluginManager = \Drupal::service('plugin.manager.migration');
$this->migrationDefinition = [
'id' => 'test',
'source' => [
'plugin' => 'table',
'table_name' => 'foo',
'fields' => [],
'id_fields' => [],
],
'process' => [],
'destination' => [
'plugin' => 'null',
],
];
}
/**
* Tests 'Table' source plugin requirements.
*/
public function testCheckRequirements() {
$this->expectException(RequirementsException::class);
$this->expectExceptionMessage("Source database table 'foo' does not exist");
$this->migrationPluginManager->createStubMigration($this->migrationDefinition)
->getSourcePlugin()
->checkRequirements();
}
}
......@@ -155,11 +155,10 @@ class GateTest extends MigrateProcessTestCase {
*
* @dataProvider badConfigurationProvider
*/
public function testGateBadConfigration($configuration, $message): void {
$this->expectException(MigrateException::class);
public function testGateBadConfiguration($configuration, $message): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage($message);
$plugin = new Gate($configuration, 'gate', []);
$plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
new Gate($configuration, 'gate', []);
}
/**
......
......@@ -106,6 +106,23 @@ class SkipOnValueTest extends MigrateProcessTestCase {
->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* Tests that a skip row exception with a message is raised.
*
* @covers ::row
*/
public function testRowSkipWithMessage() {
$configuration = [
'method' => 'row',
'value' => 86,
'message' => 'The value is 86',
];
$process = new SkipOnValue($configuration, 'skip_on_value', []);
$this->expectException(MigrateSkipRowException::class);
$this->expectExceptionMessage('The value is 86');
$process->transform(86, $this->migrateExecutable, $this->row, 'destination_property');
}
/**
* @covers ::row
*/
......@@ -123,23 +140,14 @@ class SkipOnValueTest extends MigrateProcessTestCase {
}
/**
* @covers ::row
* @covers ::__construct
*/
public function testRequiredRowConfiguration(): void {
public function testRequiredConfiguration() {
// It doesn't meter which method we will put here, because it should throw
// error on contraction of Plugin.
$configuration['method'] = 'row';
$this->expectException(MigrateException::class);
(new SkipOnValue($configuration, 'skip_on_value', []))
->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* @covers ::process
*/
public function testRequiredProcessConfiguration(): void {
$configuration['method'] = 'process';
$this->expectException(MigrateException::class);
(new SkipOnValue($configuration, 'skip_on_value', []))
->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
$this->expectException(\InvalidArgumentException::class);
(new SkipOnValue($configuration, 'skip_on_value', []));
}
}
......@@ -55,27 +55,23 @@ class StrReplaceTest extends MigrateProcessTestCase {
}
/**
* Test for MigrateException for "search" configuration.
* Test for InvalidArgumentException for "search" configuration.
*/
public function testSearchMigrateException(): void {
$value = 'vero eos et accusam et justo vero';
public function testSearchInvalidArgumentException(): void {
$configuration['replace'] = 'that';
$plugin = new StrReplace($configuration, 'str_replace', []);
$this->expectException(MigrateException::class);
$this->expectExceptionMessage('"search" must be configured.');
$plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "search" must be set.');
new StrReplace($configuration, 'str_replace', []);
}
/**
* Test for MigrateException for "replace" configuration.
* Test for InvalidArgumentException for "replace" configuration.
*/
public function testReplaceMigrateException(): void {
$value = 'vero eos et accusam et justo vero';
public function testReplaceInvalidArgumentException(): void {
$configuration['search'] = 'et';
$plugin = new StrReplace($configuration, 'str_replace', []);
$this->expectException(MigrateException::class);
$this->expectExceptionMessage('"replace" must be configured.');
$plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "replace" must be set.');
new StrReplace($configuration, 'str_replace', []);
}
/**
......