saveMessage example

$migrate_executable = new MigrateExecutable($migration);
    $row = new Row($source_ids + $migration->getSourceConfiguration()$migration->getSourcePlugin()->getIds(), TRUE);
    $migrate_executable->processRow($row$process);
    foreach ($default_values as $key => $value) {
      $row->setDestinationProperty($key$value);
    }
    $destination_ids = [];
    try {
      $destination_ids = $destination->import($row);
    }
    catch (\Exception $e) {
      $id_map->saveMessage($row->getSourceIdValues()$e->getMessage());
    }
    if ($destination_ids) {
      $id_map->saveIdMapping($row$destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
      return $destination_ids;
    }
    return FALSE;
  }

}
try {
      $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', [$row$this$this->migration]);
      $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', [$row$this$this->migration]);
      // We will skip if any hook returned FALSE.       $skip = ($result_hook && in_array(FALSE, $result_hook)) || ($result_named_hook && in_array(FALSE, $result_named_hook));
      $save_to_map = TRUE;
    }
    catch (MigrateSkipRowException $e) {
      $skip = TRUE;
      $save_to_map = $e->getSaveToMap();
      if ($message = trim($e->getMessage())) {
        $this->idMap->saveMessage($row->getSourceIdValues()$message, MigrationInterface::MESSAGE_INFORMATIONAL);
      }
    }

    // We're explicitly skipping this row - keep track in the map table.     if ($skip) {
      // Make sure we replace any previous messages for this item with any       // new ones.       if ($save_to_map) {
        $this->idMap->saveIdMapping($row[], MigrateIdMapInterface::STATUS_IGNORED);
        $this->currentRow = NULL;
        $this->currentSourceIds = NULL;
      }

  public function import(Row $row, array $old_destination_id_values = []): array|bool {
    $permissions = $row->getDestinationProperty('permissions') ?? [];

    // Get permissions that do not exist on the destination.     $invalid_permissions = array_diff($permissions$this->destinationPermissions);
    if ($invalid_permissions) {
      sort($invalid_permissions);
      // Log the message in the migration message table.       $message = "Permission(s) '" . implode("', '", $invalid_permissions) . "' not found.";
      $this->migration->getIdMap()
        ->saveMessage($row->getSourceIdValues()$message, MigrationInterface::MESSAGE_WARNING);
    }

    $valid_permissions = array_intersect($permissions$this->destinationPermissions);
    $row->setDestinationProperty('permissions', $valid_permissions);
    return parent::import($row$old_destination_id_values);
  }

}
/** * Tests the clear messages method. */
  public function testClearMessages() {
    $message = 'Hello world.';
    $expected_results = [0, 1, 2, 3];
    $id_map = $this->getIdMap();

    // Insert 4 message for later delete.     foreach ($expected_results as $key => $expected_result) {
      $id_map->saveMessage(['source_id_property' => $key]$message);
    }

    // Truncate and check that 4 messages were deleted.     $this->assertSame($id_map->messageCount(), 4);
    $id_map->clearMessages();
    $count = $id_map->messageCount();
    $this->assertSame($count, 0);
  }

  /** * Tests the getRowsNeedingUpdate method for rows that need an update. */

  public function setSourceIdValues($source_id_values) {
    $this->sourceIdValues = $source_id_values;
  }

  /** * {@inheritdoc} */
  public function handleException(\Exception $exception$save = TRUE) {
    $message = $exception->getMessage();
    if ($save) {
      $this->saveMessage($message);
    }
    $this->message->display($message);
  }

  /** * Allows access to the protected memoryExceeded method. * * @return bool * The memoryExceeded value. */
  public function memoryExceeded() {
    
// Get the process pipeline.     $pipeline = FALSE;
    if ($source->valid()) {
      try {
        $pipeline = $this->migration->getProcessPlugins();
      }
      catch (MigrateException $e) {
        $row = $source->current();
        $this->sourceIdValues = $row->getSourceIdValues();
        $this->getIdMap()->saveIdMapping($row[]$e->getStatus());
        $this->saveMessage($e->getMessage()$e->getLevel());
      }
    }

    $return = MigrationInterface::RESULT_COMPLETED;
    if ($pipeline) {
      $id_map = $this->getIdMap();
      $destination = $this->migration->getDestinationPlugin();
      while ($source->valid()) {
        $row = $source->current();
        $this->sourceIdValues = $row->getSourceIdValues();

        
    $widget_types = $this->select('content_node_field_instance', 'cnfi')
      ->fields('cnfi', ['widget_type'])
      ->condition('field_name', $row->getSourceProperty('field_name'))
      ->distinct()
      ->orderBy('widget_type')
      ->execute()
      ->fetchCol();
    // Arbitrarily use the first widget_type - if there are multiples, let the     // migrator know.     $row->setSourceProperty('widget_type', $widget_types[0]);
    if (count($widget_types) > 1) {
      $this->migration->getIdMap()->saveMessage(
        ['field_name' => $row->getSourceProperty('field_name')],
        $this->t('Widget types @types are used in Drupal 6 field instances: widget type @selected_type applied to the Drupal 8 base field', [
          '@types' => implode(', ', $widget_types),
          '@selected_type' => $widget_types[0],
        ])
      );
    }

    // Unserialize data.     $global_settings = unserialize($row->getSourceProperty('global_settings'));
    $db_columns = $row->getSourceProperty('db_columns');
    
    // passing it into the filter manager.     if (is_array($plugin_id)) {
      $plugin_id = implode(':', $plugin_id);
    }

    if ($this->filterManager->hasDefinition($plugin_id)) {
      return $plugin_id;
    }
    else {
      if (in_array(static::getSourceFilterType($value)[FilterInterface::TYPE_TRANSFORM_REVERSIBLE, FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE], TRUE)) {
        $message = sprintf('Filter %s could not be mapped to an existing filter plugin; omitted since it is a transformation-only filter. Install and configure a successor after the migration.', $plugin_id);
        $migrate_executable->saveMessage($message, MigrationInterface::MESSAGE_INFORMATIONAL);
        throw new MigrateSkipProcessException("The transformation-only filter $plugin_id was skipped.");
      }
      $fallback = $this->filterManager->getFallbackPluginId($plugin_id);

      // @see \Drupal\filter\Plugin\migrate\process\FilterSettings::transform()       $message = sprintf('Filter %s could not be mapped to an existing filter plugin; defaulting to %s and dropping all settings. Either redo the migration with the module installed that provides an equivalent filter, or modify the text format after the migration to remove this filter if it is no longer necessary.', $plugin_id$fallback);
      $migrate_executable->saveMessage($message, MigrationInterface::MESSAGE_WARNING);

      return $fallback;
    }
  }

  


    $class_name = $export !== NULL && $is_object
      ? $class_name = get_class($value) . ":\n"
      : '';

    $message = $export === NULL
      ? "Unable to log the value for '$destination_property'"
      : "'$destination_property' value is $class_name'$export'";

    // Log the value.     $migrate_executable->saveMessage($message);
    // Pass through the same value we received.     return $value;
  }

}
Home | Imprint | This part of the site doesn't use cookies.