Fix a bug in the MigrationLookup migration.

The migrations with ID were being skipped by the MigrationLookup plugin.

More info here: https://www.drupal.org/project/drupal/issues/2751825
This commit is contained in:
David Valdez 2018-09-05 21:18:29 -05:00
parent e730f92584
commit 54c3ac9b46
2 changed files with 46 additions and 2 deletions

View file

@ -9,7 +9,7 @@ source:
process:
pid:
-
plugin: migration_lookup
plugin: migration_lookup_with_zero
migration: agaric_comment
source: pid
no_stub: true
@ -37,7 +37,7 @@ process:
subject: subject
uid:
-
plugin: migration_lookup
plugin: migration_lookup_with_zero
migration: agaric_user
source: uid
no_stub: true

View file

@ -0,0 +1,44 @@
<?php
namespace Drupal\agaric_migration\Plugin\migrate\process;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\Plugin\migrate\process\MigrationLookup;
/**
* Looks up the value of a property based on a previous migration.
*
* This plugin just alters the MigrationLookup::skipOnEmpty to consider the
* number zero as a valid ID.
*
* @MigrateProcessPlugin(
* id = "migration_lookup_with_zero"
* )
*/
class MigrationLookupWithZero extends MigrationLookup {
/**
* {@inheritdoc}
*/
protected function skipOnEmpty(array $value) {
if (!array_filter($value, [$this, 'isNotEmpty'])) {
throw new MigrateSkipProcessException();
}
}
/**
* Determines if the value is not empty.
*
* The only values considered empty are: NULL, FALSE and an empty string.
*
* @param string $value
* The value to test if is empty.
*
* @return bool
* Return true if the value is not empty.
*/
protected function isNotEmpty($value) {
return ($value !== NULL && $value !== FALSE && $value !== '');
}
}