Unverified Commit 29734423 authored by alexpott's avatar alexpott

Issue #2999478 by heddn, mikelutz: Refactor MigrateExecutable::rollback()

parent be64fa99
......@@ -105,7 +105,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
public function __construct(MigrationInterface $migration, MigrateMessageInterface $message = NULL, EventDispatcherInterface $event_dispatcher = NULL) {
$this->migration = $migration;
$this->message = $message ?: new MigrateMessage();
$this->migration->getIdMap()->setMessage($this->message);
$this->getIdMap()->setMessage($this->message);
$this->eventDispatcher = $event_dispatcher;
// Record the memory limit in bytes
$limit = trim(ini_get('memory_limit'));
......@@ -182,7 +182,7 @@ public function import() {
$this->migration->setStatus(MigrationInterface::STATUS_IMPORTING);
$return = MigrationInterface::RESULT_COMPLETED;
$source = $this->getSource();
$id_map = $this->migration->getIdMap();
$id_map = $this->getIdMap();
try {
$source->rewind();
......@@ -204,7 +204,7 @@ public function import() {
$save = TRUE;
}
catch (MigrateException $e) {
$this->migration->getIdMap()->saveIdMapping($row, [], $e->getStatus());
$this->getIdMap()->saveIdMapping($row, [], $e->getStatus());
$this->saveMessage($e->getMessage(), $e->getLevel());
$save = FALSE;
}
......@@ -241,11 +241,11 @@ public function import() {
}
}
catch (MigrateException $e) {
$this->migration->getIdMap()->saveIdMapping($row, [], $e->getStatus());
$this->getIdMap()->saveIdMapping($row, [], $e->getStatus());
$this->saveMessage($e->getMessage(), $e->getLevel());
}
catch (\Exception $e) {
$this->migration->getIdMap()->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_FAILED);
$this->getIdMap()->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_FAILED);
$this->handleException($e);
}
}
......@@ -299,11 +299,12 @@ public function rollback() {
$return = MigrationInterface::RESULT_COMPLETED;
$this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK);
$id_map = $this->migration->getIdMap();
$id_map = $this->getIdMap();
$destination = $this->migration->getDestinationPlugin();
// Loop through each row in the map, and try to roll it back.
foreach ($id_map as $map_row) {
$id_map->rewind();
while ($id_map->valid()) {
$destination_key = $id_map->currentDestination();
if ($destination_key) {
$map_row = $id_map->getRowByDestination($destination_key);
......@@ -323,6 +324,7 @@ public function rollback() {
$source_key = $id_map->currentSource();
$id_map->delete($source_key);
}
$id_map->next();
// Check for memory exhaustion.
if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) {
......@@ -344,6 +346,16 @@ public function rollback() {
return $return;
}
/**
* Get the ID map from the current migration.
*
* @return \Drupal\migrate\Plugin\MigrateIdMapInterface
* The ID map.
*/
protected function getIdMap() {
return $this->migration->getIdMap();
}
/**
* {@inheritdoc}
*/
......@@ -416,7 +428,7 @@ protected function currentSourceIds() {
* {@inheritdoc}
*/
public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR) {
$this->migration->getIdMap()->saveMessage($this->sourceIdValues, $message, $level);
$this->getIdMap()->saveMessage($this->sourceIdValues, $message, $level);
}
/**
......
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