Unverified Commit 68c0a254 authored by larowlan's avatar larowlan

Issue #3054167 by christinlepson, shubham.prakash, Charlie ChX Negyesi,...

Issue #3054167 by christinlepson, shubham.prakash, Charlie ChX Negyesi, init90, benjifisher, heddn, alexpott: The getMessageIterator() method does not return an instance of Iterator
parent 15c7c6bc
......@@ -120,12 +120,9 @@ public function testFields() {
$this->assertSame($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
// Check that we've reported on a conflict in widget_types.
$messages = [];
foreach ($migration->getIdMap()->getMessageIterator() as $message_row) {
$messages[] = $message_row->message;
}
$messages = iterator_to_array($migration->getIdMap()->getMessages());
$this->assertCount(1, $messages);
$this->assertSame($messages[0], 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');
$this->assertSame($messages[0]->message, 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');
}
}
......@@ -196,10 +196,9 @@ public function testTextFieldInstances() {
// For each text field instances that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field_instance');
$messages = $migration->getIdMap()->getMessageIterator()->fetchAll();
$errors = array_map(function ($message) {
return $message->message;
}, $messages);
}, iterator_to_array($migration->getIdMap()->getMessages()));
$this->assertCount(8, $errors);
sort($errors);
$message = 'Can\'t migrate source field field_text_long_plain_filtered 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';
......
......@@ -173,10 +173,9 @@ public function testTextFields() {
// For each text field bases that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field');
$messages = $migration->getIdMap()->getMessageIterator()->fetchAll();
$errors = array_map(function ($message) {
return $message->message;
}, $messages);
}, iterator_to_array($migration->getIdMap()->getMessages()));
sort($errors);
$this->assertCount(4, $errors);
$this->assertEquals($errors[0], 'Can\'t migrate source field field_text_long_plain_filtered 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');
......
......@@ -105,15 +105,10 @@ public function testMissingEffectPlugin() {
$this->startCollectingMessages();
$this->executeMigration('d6_imagecache_presets');
$messages = $this->migration->getIdMap()->getMessageIterator();
$count = 0;
foreach ($messages as $message) {
$count++;
$this->assertContains('The "image_deprecated_scale" plugin does not exist.', $message->message);
$this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR);
}
// There should be only the one message.
$this->assertEqual($count, 1);
$messages = iterator_to_array($this->migration->getIdMap()->getMessages());
$this->assertCount(1, $messages);
$this->assertContains('The "image_deprecated_scale" plugin does not exist.', $messages[0]->message);
$this->assertEqual($messages[0]->level, MigrationInterface::MESSAGE_ERROR);
}
/**
......
......@@ -41,7 +41,7 @@ public function testMigrationWithNonExistentLanguage() {
$this->executeMigrations(['language', 'default_language']);
// Tests the migration log contains an error message.
$messages = $this->migration->getIdMap()->getMessageIterator();
$messages = $this->migration->getIdMap()->getMessages();
$count = 0;
foreach ($messages as $message) {
$count++;
......@@ -62,7 +62,7 @@ public function testMigrationWithUnsetVariable() {
$this->startCollectingMessages();
$this->executeMigrations(['language', 'default_language']);
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
$messages = $this->migration->getIdMap()->getMessages()->fetchAll();
// Make sure there's no migration exceptions.
$this->assertEmpty($messages);
// Make sure the default langcode is 'en', as it was the default on D6 & D7.
......
......@@ -41,7 +41,7 @@ public function testMigrationWithNonExistentLanguage() {
$this->executeMigrations(['language', 'default_language']);
// Tests the migration log contains an error message.
$messages = $this->migration->getIdMap()->getMessageIterator();
$messages = $this->migration->getIdMap()->getMessages();
$count = 0;
foreach ($messages as $message) {
$count++;
......@@ -62,7 +62,7 @@ public function testMigrationWithUnsetVariable() {
$this->startCollectingMessages();
$this->executeMigrations(['language', 'default_language']);
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
$messages = $this->migration->getIdMap()->getMessages()->fetchAll();
// Make sure there's no migration exceptions.
$this->assertEmpty($messages);
// Make sure the default langcode is 'en', as it was the default on D6 & D7.
......
......@@ -53,7 +53,7 @@ public function testLanguageContent() {
$this->assertSame($config->getDefaultLangcode(), 'site_default');
// Make sure there's no migration exceptions.
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
$messages = $this->migration->getIdMap()->getMessages()->fetchAll();
$this->assertEmpty($messages);
// Assert that a content type translatable with entity_translation is still
......
......@@ -62,6 +62,27 @@ public function saveIdMapping(Row $row, array $destination_id_values, $status =
*/
public function saveMessage(array $source_id_values, $message, $level = MigrationInterface::MESSAGE_ERROR);
/**
* Retrieves a traversable object of messages related to source records.
*
* @param array $source_id_values
* (optional) The source identifier keyed values of the record, e.g.
* ['nid' => 5]. If empty (the default), all messages are retrieved.
* @param int $level
* (optional) Message severity. If NULL (the default), retrieve messages of
* all severities.
*
* @return \Traversable
* Retrieves a traversable object of message objects of unspecified class.
* Each object has the following public properties:
* - source_row_hash: the hash of the entire serialized source row data.
* - message: the text of the message.
* - level: one of MigrationInterface::MESSAGE_ERROR,
* MigrationInterface::MESSAGE_WARNING, MigrationInterface::MESSAGE_NOTICE,
* MigrationInterface::MESSAGE_INFORMATIONAL.
*/
public function getMessages(array $source_id_values = [], $level = NULL);
/**
* Retrieves an iterator over messages relate to source records.
*
......@@ -74,6 +95,11 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
*
* @return \Iterator
* Retrieves an iterator over the message rows.
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
* Use \Drupal\migrate\Plugin\MigrateIdMapInterface::getMessages() instead.
*
* @see https://www.drupal.org/node/3060969
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL);
......
......@@ -84,10 +84,18 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
/**
* {@inheritdoc}
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL) {
public function getMessages(array $source_id_values = [], $level = NULL) {
return new \ArrayIterator([]);
}
/**
* {@inheritdoc}
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL) {
@trigger_error('getMessageIterator() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use getMessages() instead. See https://www.drupal.org/node/3060969', E_USER_DEPRECATED);
return $this->getMessages($source_id_values, $level);
}
/**
* {@inheritdoc}
*/
......
......@@ -676,7 +676,7 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
/**
* {@inheritdoc}
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL) {
public function getMessages(array $source_id_values = [], $level = NULL) {
$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);
......@@ -698,6 +698,14 @@ public function getMessageIterator(array $source_id_values = [], $level = NULL)
return $query->execute();
}
/**
* {@inheritdoc}
*/
public function getMessageIterator(array $source_id_values = [], $level = NULL) {
@trigger_error('getMessageIterator() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use getMessages() instead. See https://www.drupal.org/node/3060969', E_USER_DEPRECATED);
return $this->getMessages($source_id_values, $level);
}
/**
* {@inheritdoc}
*/
......
......@@ -65,7 +65,7 @@ public function testExceptionThrow() {
$this->assertNull($map_row['destid1']);
// Check that a message with the thrown exception has been logged.
$messages = $id_map_plugin->getMessageIterator(['url' => $invalid_url])->fetchAll();
$messages = $id_map_plugin->getMessages(['url' => $invalid_url])->fetchAll();
$this->assertCount(1, $messages);
$message = reset($messages);
$this->assertEquals("Cannot read from non-readable stream ($invalid_url)", $message->message);
......
......@@ -98,12 +98,12 @@ public function testMessagesTeed() {
}
/**
* Tests the return value of getMessageIterator().
* Tests the return value of getMessages().
*
* This method returns an iterator of StdClass objects. Check that these
* objects have the expected keys.
*/
public function testGetMessageIterator() {
public function testGetMessages() {
$expected_message = (object) [
'src_name' => 'source_message',
'dest_config_name' => NULL,
......@@ -115,7 +115,7 @@ public function testGetMessageIterator() {
$executable = new MigrateExecutable($this->migration, $this);
$executable->import();
$count = 0;
foreach ($this->migration->getIdMap()->getMessageIterator() as $message) {
foreach ($this->migration->getIdMap()->getMessages() as $message) {
++$count;
$this->assertEqual($message, $expected_message);
}
......
......@@ -59,14 +59,14 @@ public function testPrepareRowSkip() {
$map_row = $id_map_plugin->getRowBySource(['id' => 1]);
$this->assertEqual(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']);
// Check that no message has been logged for the first exception.
$messages = $id_map_plugin->getMessageIterator(['id' => 1])->fetchAll();
$messages = $id_map_plugin->getMessages(['id' => 1])->fetchAll();
$this->assertEmpty($messages);
// The second row is not recorded in the map.
$map_row = $id_map_plugin->getRowBySource(['id' => 2]);
$this->assertFalse($map_row);
// Check that the correct message has been logged for the second exception.
$messages = $id_map_plugin->getMessageIterator(['id' => 2])->fetchAll();
$messages = $id_map_plugin->getMessages(['id' => 2])->fetchAll();
$this->assertCount(1, $messages);
$message = reset($messages);
$this->assertEquals('skip_and_dont_record message', $message->message);
......
<?php
namespace Drupal\Tests\migrate\Unit;
use Drupal\migrate\Plugin\migrate\id_map\NullIdMap;
/**
* Tests the NULL ID map plugin.
*
* @group migrate
*/
class MigrateNullIdMapTest extends MigrateTestCase {
/**
* Tests the NULL ID map get message iterator method.
*
* @group legacy
*
* @expectedDeprecation getMessageIterator() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use getMessages() instead. See https://www.drupal.org/node/3060969
*/
public function testGetMessageIterator() {
$id_map = new NullIdMap([], 'null', NULL);
$id_map->getMessageIterator();
}
}
......@@ -312,7 +312,7 @@ public function testMessageSave() {
$id_map->saveMessage(['source_id_property' => $key], $message, $original_value['level']);
}
foreach ($id_map->getMessageIterator() as $message_row) {
foreach ($id_map->getMessages() as $message_row) {
$key = $message_row->source_ids_hash;
$this->assertEquals($expected_results[$key]['message'], $message_row->message);
$this->assertEquals($expected_results[$key]['level'], $message_row->level);
......@@ -321,7 +321,7 @@ public function testMessageSave() {
// Insert with default level.
$message_default = 'Hello world default.';
$id_map->saveMessage(['source_id_property' => 5], $message_default);
$messages = $id_map->getMessageIterator(['source_id_property' => 5]);
$messages = $id_map->getMessages(['source_id_property' => 5]);
$count = 0;
foreach ($messages as $key => $message_row) {
$count = 1;
......@@ -331,7 +331,7 @@ public function testMessageSave() {
$this->assertEquals($count, 1);
// Retrieve messages with a specific level.
$messages = $id_map->getMessageIterator([], MigrationInterface::MESSAGE_WARNING);
$messages = $id_map->getMessages([], MigrationInterface::MESSAGE_WARNING);
$count = 0;
foreach ($messages as $key => $message_row) {
$count = 1;
......@@ -340,6 +340,17 @@ public function testMessageSave() {
$this->assertEquals($count, 1);
}
/**
* Tests the SQL ID map get message iterator method.
*
* @group legacy
*
* @expectedDeprecation getMessageIterator() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use getMessages() instead. See https://www.drupal.org/node/3060969
*/
public function testGetMessageIterator() {
$this->getIdMap()->getMessageIterator();
}
/**
* Tests the getRowBySource method.
*/
......
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