Skip to content
Snippets Groups Projects

Issue #3015199: Allow SkipOnValue to include a message in the MigrateSkipRowException.

Files
2
@@ -24,6 +24,9 @@ use Drupal\migrate\Row;
@@ -24,6 +24,9 @@ use Drupal\migrate\Row;
* configuration key value. Possible values:
* configuration key value. Possible values:
* - row: Skips the entire row.
* - row: Skips the entire row.
* - process: Prevents further processing of the input property
* - 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
* @codingStandardsIgnoreStart
*
*
@@ -50,9 +53,11 @@ use Drupal\migrate\Row;
@@ -50,9 +53,11 @@ use Drupal\migrate\Row;
* value:
* value:
* - article
* - article
* - testimonial
* - testimonial
 
* message: 'Not an article nor a testimonial content type'
* @endcode
* @endcode
* The above example will skip processing any row for which the source row's
* 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
* @codingStandardsIgnoreEnd
*/
*/
@@ -65,7 +70,6 @@ class SkipOnValue extends ProcessPluginBase {
@@ -65,7 +70,6 @@ class SkipOnValue extends ProcessPluginBase {
if (empty($configuration['value']) && !array_key_exists('value', $configuration)) {
if (empty($configuration['value']) && !array_key_exists('value', $configuration)) {
throw new \InvalidArgumentException('Skip on value plugin is missing value configuration.');
throw new \InvalidArgumentException('Skip on value plugin is missing value configuration.');
}
}
parent::__construct($configuration, $plugin_id, $plugin_definition);
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
}
@@ -73,6 +77,8 @@ class SkipOnValue extends ProcessPluginBase {
@@ -73,6 +77,8 @@ class SkipOnValue extends ProcessPluginBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
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'])) {
if (is_array($this->configuration['value'])) {
$value_in_array = FALSE;
$value_in_array = FALSE;
$not_equals = isset($this->configuration['not_equals']);
$not_equals = isset($this->configuration['not_equals']);
@@ -82,11 +88,11 @@ class SkipOnValue extends ProcessPluginBase {
@@ -82,11 +88,11 @@ class SkipOnValue extends ProcessPluginBase {
}
}
if (($not_equals && !$value_in_array) || (!$not_equals && $value_in_array)) {
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']))) {
elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
throw new MigrateSkipRowException();
throw new MigrateSkipRowException($message);
}
}
return $value;
return $value;
Loading