Loading core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +14 −5 Original line number Diff line number Diff line Loading @@ -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(); } Loading core/modules/migrate/tests/src/Kernel/MigrateMessageTest.php +26 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. * Loading Loading
core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +14 −5 Original line number Diff line number Diff line Loading @@ -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(); } Loading
core/modules/migrate/tests/src/Kernel/MigrateMessageTest.php +26 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. * Loading