Commit 2ee4a7fb authored by webchick's avatar webchick

Issue #2567571 by mikeryan: Manage per-row messages more rationally

parent 33608908
......@@ -41,17 +41,6 @@ class MigrateExecutable implements MigrateExecutableInterface {
*/
protected $sourceRowStatus;
/**
* The queued messages not yet saved.
*
* Each element in the array is an array with two keys:
* - 'message': The message string.
* - 'level': The level, a MigrationInterface::MESSAGE_* constant.
*
* @var array
*/
protected $queuedMessages = array();
/**
* The ratio of the memory limit at which an operation will be interrupted.
*
......@@ -178,10 +167,6 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa
protected function getSource() {
if (!isset($this->source)) {
$this->source = $this->migration->getSourcePlugin();
// @TODO, find out how to remove this.
// @see https://www.drupal.org/node/2443617
$this->source->migrateExecutable = $this;
}
return $this->source;
}
......@@ -245,11 +230,7 @@ public function import() {
$destination = $this->migration->getDestinationPlugin();
while ($source->valid()) {
$row = $source->current();
if ($this->sourceIdValues = $row->getSourceIdValues()) {
// Wipe old messages, and save any new messages.
$id_map->delete($this->sourceIdValues, TRUE);
$this->saveQueuedMessages();
}
$this->sourceIdValues = $row->getSourceIdValues();
try {
$this->processRow($row);
......@@ -399,23 +380,6 @@ public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR
$this->migration->getIdMap()->saveMessage($this->sourceIdValues, $message, $level);
}
/**
* {@inheritdoc}
*/
public function queueMessage($message, $level = MigrationInterface::MESSAGE_ERROR) {
$this->queuedMessages[] = array('message' => $message, 'level' => $level);
}
/**
* {@inheritdoc}
*/
public function saveQueuedMessages() {
foreach ($this->queuedMessages as $queued_message) {
$this->saveMessage($queued_message['message'], $queued_message['level']);
}
$this->queuedMessages = array();
}
/**
* Takes an Exception object and both saves and displays it.
*
......
......@@ -46,18 +46,4 @@ public function processRow(Row $row, array $process = NULL, $value = NULL);
*/
public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR);
/**
* Queues messages to be later saved through the map class.
*
* @param string $message
* The message to record.
* @param int $level
* (optional) Message severity (defaults to MESSAGE_ERROR).
*/
public function queueMessage($message, $level = MigrationInterface::MESSAGE_ERROR);
/**
* Saves any messages we've queued up to the message table.
*/
public function saveQueuedMessages();
}
......@@ -125,14 +125,6 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
*/
protected $iterator;
/**
* @TODO, find out how to remove this.
* @see https://www.drupal.org/node/2443617
*
* @var MigrateExecutableInterface
*/
public $migrateExecutable;
/**
* {@inheritdoc}
*/
......@@ -199,11 +191,8 @@ public function prepareRow(Row $row) {
if ($skip) {
// Make sure we replace any previous messages for this item with any
// new ones.
$id_map = $this->migration->getIdMap();
$id_map->delete($this->currentSourceIds, TRUE);
$this->migrateExecutable->saveQueuedMessages();
if ($save_to_map) {
$id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->migrateExecutable->rollbackAction);
$this->migration->getIdMap()->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED);
$this->currentRow = NULL;
$this->currentSourceIds = NULL;
}
......@@ -307,6 +296,12 @@ public function next() {
$row->setIdMap($id_map);
}
// Clear any previous messages for this row before potentially adding
// new ones.
if (!empty($this->currentSourceIds)) {
$this->idMap->delete($this->currentSourceIds, TRUE);
}
// Preparing the row gives source plugins the chance to skip.
if ($this->prepareRow($row) === FALSE) {
continue;
......
......@@ -199,10 +199,6 @@ public function testImportWithValidRowNoDestinationValues() {
->method('getDestinationPlugin')
->will($this->returnValue($destination));
$this->idMap->expects($this->once())
->method('delete')
->with(array('id' => 'test'), TRUE);
$this->idMap->expects($this->once())
->method('saveIdMapping')
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
......@@ -378,57 +374,6 @@ public function testImportWithValidRowWithException() {
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
}
/**
* Tests saving of queued messages.
*/
public function testSaveQueuedMessages() {
// Assert no queued messages before save.
$this->assertAttributeEquals(array(), 'queuedMessages', $this->executable);
// Set required source_id_values for MigrateIdMapInterface::saveMessage().
$expected_messages[] = array('message' => 'message 1', 'level' => MigrationInterface::MESSAGE_ERROR);
$expected_messages[] = array('message' => 'message 2', 'level' => MigrationInterface::MESSAGE_WARNING);
$expected_messages[] = array('message' => 'message 3', 'level' => MigrationInterface::MESSAGE_INFORMATIONAL);
foreach ($expected_messages as $queued_message) {
$this->executable->queueMessage($queued_message['message'], $queued_message['level']);
}
$this->executable->setSourceIdValues(array());
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
// No asserts of saved messages since coverage exists
// in MigrateSqlIdMapTest::saveMessage().
$this->executable->saveQueuedMessages();
// Assert no queued messages after save.
$this->assertAttributeEquals(array(), 'queuedMessages', $this->executable);
}
/**
* Tests the queuing of messages.
*/
public function testQueueMessage() {
// Assert no queued messages.
$expected_messages = array();
$this->assertAttributeEquals(array(), 'queuedMessages', $this->executable);
// Assert a single (default level) queued message.
$expected_messages[] = array(
'message' => 'message 1',
'level' => MigrationInterface::MESSAGE_ERROR,
);
$this->executable->queueMessage('message 1');
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
// Assert multiple queued messages.
$expected_messages[] = array(
'message' => 'message 2',
'level' => MigrationInterface::MESSAGE_WARNING,
);
$this->executable->queueMessage('message 2', MigrationInterface::MESSAGE_WARNING);
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
$expected_messages[] = array(
'message' => 'message 3',
'level' => MigrationInterface::MESSAGE_INFORMATIONAL,
);
$this->executable->queueMessage('message 3', MigrationInterface::MESSAGE_INFORMATIONAL);
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
}
/**
* Tests the processRow 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