Unverified Commit da6392f8 authored by alexpott's avatar alexpott

Issue #2714529 by benjifisher, mikeryan, dww, iMiksu, heddn, alisonjo2786,...

Issue #2714529 by benjifisher, mikeryan, dww, iMiksu, heddn, alisonjo2786, alexpott: Add source and destination IDs to the data returned by getMessageIterator()
parent 94361f33
......@@ -676,14 +676,23 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
* {@inheritdoc}
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL) {
$query = $this->getDatabase()->select($this->messageTableName(), 'msg')
->fields('msg');
$query = $this->getDatabase()->select($this->messageTableName(), 'msg');
$condition = sprintf('msg.%s = map.%s', $this::SOURCE_IDS_HASH, $this::SOURCE_IDS_HASH);
$query->addJoin('LEFT', $this->mapTableName(), 'map', $condition);
// Explicitly define the fields we want. The order will be preserved: source
// IDs, destination IDs (if possible), and then the rest.
foreach ($this->sourceIdFields() as $id => $column_name) {
$query->addField('map', $column_name, "src_$id");
}
foreach ($this->destinationIdFields() as $id => $column_name) {
$query->addField('map', $column_name, "dest_$id");
}
$query->fields('msg', ['msgid', $this::SOURCE_IDS_HASH, 'level', 'message']);
if ($source_id_values) {
$query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
$query->condition('msg.' . $this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
}
if ($level) {
$query->condition('level', $level);
$query->condition('msg.level', $level);
}
return $query->execute();
}
......
......@@ -8,6 +8,7 @@
use Drupal\migrate\Event\MigrateIdMapMessageEvent;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessageInterface;
use Drupal\migrate\Plugin\migrate\id_map\Sql;
/**
* Tests whether idmap messages are sent to message interface when requested.
......@@ -96,6 +97,31 @@ public function testMessagesTeed() {
$this->assertIdentical(reset($this->messages), "source_message: 'a message' is not an array");
}
/**
* Tests the return value of getMessageIterator().
*
* This method returns an iterator of StdClass objects. Check that these
* objects have the expected keys.
*/
public function testGetMessageIterator() {
$expected_message = (object) [
'src_name' => 'source_message',
'dest_config_name' => NULL,
'msgid' => '1',
Sql::SOURCE_IDS_HASH => '170cde81762e22552d1b1578cf3804c89afefe9efbc7cc835185d7141060b032',
'level' => '1',
'message' => "'a message' is not an array",
];
$executable = new MigrateExecutable($this->migration, $this);
$executable->import();
$count = 0;
foreach ($this->migration->getIdMap()->getMessageIterator() as $message) {
++$count;
$this->assertEqual($message, $expected_message);
}
$this->assertEqual($count, 1);
}
/**
* Reacts to map message event.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment