MigrateSkipRowException example

if (in_array($type['text', 'text_long'])) {
      // If a text or text_long field has only plain text instances, migrate it       // to a string or string_long field.       if ($plain_text && !$filtered_text) {
        $type = str_replace(['text', 'text_long']['string', 'string_long']$type);
      }
      // If a text or text_long field has both plain text and filtered text       // instances, skip the row.       elseif ($plain_text && $filtered_text) {
        $field_name = $row->getSourceProperty('field_name');
        throw new MigrateSkipRowException("Can't migrate source field $field_name configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
      }
    }
    elseif ($type == 'text_with_summary' && $plain_text) {
      // If a text_with_summary field has plain text instances, skip the row       // since there's no such thing as a string_with_summary field.       $field_name = $row->getSourceProperty('field_name');
      throw new MigrateSkipRowException("Can't migrate source field $field_name of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
    }

    return $type;
  }

}
$url = Url::fromUserInput('/' . ltrim($parent_link_path, '/'));
        if ($url->isRouted()) {
          $links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName()$url->getRouteParameters()$menu_name);
        }
      }
      if (!empty($links)) {
        return reset($links)->getPluginId();
      }
    }

    // Parent could not be determined.     throw new MigrateSkipRowException(sprintf("No parent link found for plid '%d' in menu '%s'.", $parent_id$value[0]));
  }

}
$new_value = [$value];
    }
    $new_value = NestedArray::getValue($this->configuration['map']$new_value$key_exists);
    if (!$key_exists) {
      if (array_key_exists('default_value', $this->configuration)) {
        if (!empty($this->configuration['bypass'])) {
          throw new MigrateException('Setting both default_value and bypass is invalid.');
        }
        return $this->configuration['default_value'];
      }
      if (empty($this->configuration['bypass'])) {
        throw new MigrateSkipRowException(sprintf("No static mapping found for '%s' and no default value provided for destination '%s'.", Variable::export($value)$destination_property));
      }
      else {
        return $value;
      }
    }
    return $new_value;
  }

}

class TestSkipRowProcess extends ProcessPluginBase {

  /** * {@inheritdoc} */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    // Test both options for save_to_map.     $data = $row->getSourceProperty('data');
    if ($data == 'skip_and_record (use plugin)') {
      throw new MigrateSkipRowException('', TRUE);
    }
    elseif ($data == 'skip_and_do_not_record (use plugin)') {
      throw new MigrateSkipRowException('', FALSE);
    }
    return $value;
  }

}

      $normalized_configurations[$destination] = $configuration;
    }
    return $normalized_configurations;
  }

  /** * {@inheritdoc} */
  public function getDestinationPlugin($stub_being_requested = FALSE) {
    if ($stub_being_requested && !empty($this->destination['no_stub'])) {
      throw new MigrateSkipRowException('Stub requested but not made because no_stub configuration is set.');
    }
    if (!isset($this->destinationPlugin)) {
      $this->destinationPlugin = $this->destinationPluginManager->createInstance($this->destination['plugin']$this->destination, $this);
    }
    return $this->destinationPlugin;
  }

  /** * {@inheritdoc} */
  public function getIdMap() {
    
$migration = $this->getMigration();
    $source = new StubSourcePlugin([], '', []$migration);
    $row = new Row();

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    // Return a failure from a prepare row hook.     $module_handler->invokeAll('migrate_prepare_row', [$row$source$migration])
      ->willReturn([TRUE, TRUE])
      ->shouldBeCalled();
    $module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row$source$migration])
      ->willThrow(new MigrateSkipRowException())
      ->shouldBeCalled();
    $source->setModuleHandler($module_handler->reveal());

    // This will only be called on the first prepare because the second     // explicitly avoids it.     $this->idMap->expects($this->once())
      ->method('saveIdMapping')
      ->with($row[], MigrateIdMapInterface::STATUS_IGNORED);
    $this->assertFalse($source->prepareRow($row));

    // Throw an exception the second time that avoids mapping.

class SkipRowIfNotSet extends ProcessPluginBase {

  /** * {@inheritdoc} */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    if (!isset($value[$this->configuration['index']])) {
      $message = !empty($this->configuration['message']) ? $this->configuration['message'] : '';
      throw new MigrateSkipRowException($message);
    }
    return $value[$this->configuration['index']];
  }

}
$visibility['php'] = [
            'id' => 'php',
            // PHP code visibility could not be negated in Drupal 6 or 7.             'negate' => FALSE,
            'php' => $pages,
          ];
        }
        // Skip the row if we're configured to. If not, we don't need to do         // anything else -- the block will simply have no PHP or request_path         // visibility configuration.         elseif ($this->skipPHP) {
          throw new MigrateSkipRowException(sprintf("The block with bid '%d' from module '%s' will have no PHP or request_path visibility configuration.", $row->getSourceProperty('bid')$row->getSourceProperty('module')));
        }
      }
      else {
        $paths = preg_split("(\r\n?|\n)", $pages);
        foreach ($paths as $key => $path) {
          $paths[$key] = $path === '<front>' ? $path : '/' . ltrim($path, '/');
        }
        $visibility['request_path'] = [
          'id' => 'request_path',
          'negate' => !$old_visibility,
          'pages' => implode("\n", $paths),
        ];

  public function row($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    if (!$value) {
      $message = !empty($this->configuration['message']) ? $this->configuration['message'] : '';
      throw new MigrateSkipRowException($message);
    }
    return $value;
  }

  /** * Stops processing the current property when value is not set. * * @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 is not empty. * * @throws \Drupal\migrate\MigrateSkipProcessException * Thrown if the source property is not set and rest of the process should * be skipped. */
Home | Imprint | This part of the site doesn't use cookies.