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:
parent
e730f92584
commit
54c3ac9b46
2 changed files with 46 additions and 2 deletions
|
@ -9,7 +9,7 @@ source:
|
||||||
process:
|
process:
|
||||||
pid:
|
pid:
|
||||||
-
|
-
|
||||||
plugin: migration_lookup
|
plugin: migration_lookup_with_zero
|
||||||
migration: agaric_comment
|
migration: agaric_comment
|
||||||
source: pid
|
source: pid
|
||||||
no_stub: true
|
no_stub: true
|
||||||
|
@ -37,7 +37,7 @@ process:
|
||||||
subject: subject
|
subject: subject
|
||||||
uid:
|
uid:
|
||||||
-
|
-
|
||||||
plugin: migration_lookup
|
plugin: migration_lookup_with_zero
|
||||||
migration: agaric_user
|
migration: agaric_user
|
||||||
source: uid
|
source: uid
|
||||||
no_stub: true
|
no_stub: true
|
||||||
|
|
|
@ -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 !== '');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue