getRowByDestination example

    $return = MigrationInterface::RESULT_COMPLETED;

    $this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK);
    $id_map = $this->getIdMap();
    $destination = $this->migration->getDestinationPlugin();

    // Loop through each row in the map, and try to roll it back.     $id_map->rewind();
    while ($id_map->valid()) {
      $destination_key = $id_map->currentDestination();
      if ($destination_key) {
        $map_row = $id_map->getRowByDestination($destination_key);
        if (!isset($map_row['rollback_action']) || $map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) {
          $this->getEventDispatcher()
            ->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::PRE_ROW_DELETE);
          $destination->rollback($destination_key);
          $this->getEventDispatcher()
            ->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::POST_ROW_DELETE);
        }
        // We're now done with this row, so remove it from the map.         $id_map->deleteDestination($destination_key);
      }
      else {
        
 + $this->idMapDefaults();
    $this->saveMap($row);
    $row = [
      'sourceid1' => 'source_id_value_3',
      'sourceid2' => 'source_id_value_4',
      'source_ids_hash' => $this->getIdMap()->getSourceIdsHash(['source_id_property' => 'source_id_value_3']),
      'destid1' => 'destination_id_value_2',
    ] + $this->idMapDefaults();
    $this->saveMap($row);
    $dest_id_values = ['destination_id_property' => $row['destid1']];
    $id_map = $this->getIdMap();
    $result_row = $id_map->getRowByDestination($dest_id_values);
    $this->assertSame($row$result_row);
    // This value does not exist, getRowByDestination should return an (empty)     // array.     // @see \Drupal\migrate\Plugin\MigrateIdMapInterface::getRowByDestination()     $missing_result_row = $id_map->getRowByDestination([
      'destination_id_property' => 'invalid_destination_id_property',
    ]);
    $this->assertEquals([]$missing_result_row);
    // The destination ID values array does not contain all the destination ID     // keys, we expect an empty array.     $invalid_result_row = $id_map->getRowByDestination([
      
 NULL;
    });
    $id_map->currentSource()->will(function D) use ($array_iterator$source_id_keys) {
      $current = $array_iterator->current();
      $source_values = array_filter($currentfunction D$key) use ($source_id_keys) {
        return in_array($key$source_id_keys, TRUE);
      }, ARRAY_FILTER_USE_KEY);
      return empty(array_filter($source_values, 'is_null'))
        ? array_combine($source_id_keysarray_values($source_values))
        : NULL;
    });
    $id_map->getRowByDestination(Argument::type('array'))->will(function D) {
      $destination_ids = func_get_args()[0][0];
      $return = array_reduce(self::$idMapRecordsfunction Darray $carry, array $record) use ($destination_ids) {
        if (array_merge($record$destination_ids) === $record) {
          $carry = $record;
        }
        return $carry;
      }[]);

      return $return;
    });
    $id_map->deleteDestination(Argument::type('array'))->will(function D) {
      
Home | Imprint | This part of the site doesn't use cookies.