Commit c118040c authored by webchick's avatar webchick

Issue #2554003 by mikeryan, benjy, phenaproxima: isComplete() should not rely on RESULT_COMPLETED

parent 18d4de1a
......@@ -8,6 +8,7 @@
namespace Drupal\file\Tests\Migrate\d6;
use Drupal\file\Entity\File;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\node\Entity\Node;
......@@ -52,7 +53,11 @@ protected function setUp() {
$this->prepareMigrations($id_mappings);
$this->migrateContent();
$this->executeMigration('d6_upload');
// Since we are only testing a subset of the file migration, do not check
// that the full file migration has been run.
$migration = Migration::load('d6_upload');
$migration->set('requirements', []);
$this->executeMigration($migration);
}
/**
......
......@@ -387,7 +387,7 @@ public function checkRequirements() {
$missing_migrations = array_diff($this->requirements, array_keys($required_migrations));
// Check if the dependencies are in good shape.
foreach ($required_migrations as $migration_id => $required_migration) {
if (!$required_migration->isComplete()) {
if (!$required_migration->allRowsProcessed()) {
$missing_migrations[] = $migration_id;
}
}
......@@ -439,15 +439,15 @@ public function getStatusLabel() {
/**
* {@inheritdoc}
*/
public function setMigrationResult($result) {
\Drupal::keyValue('migrate_result')->set($this->id(), $result);
public function getInterruptionResult() {
return \Drupal::keyValue('migrate_interruption_result')->get($this->id(), static::RESULT_INCOMPLETE);
}
/**
* {@inheritdoc}
*/
public function getMigrationResult() {
return \Drupal::keyValue('migrate_result')->get($this->id(), static::RESULT_INCOMPLETE);
public function clearInterruptionResult() {
\Drupal::keyValue('migrate_interruption_result')->delete($this->id());
}
/**
......@@ -455,14 +455,24 @@ public function getMigrationResult() {
*/
public function interruptMigration($result) {
$this->setStatus(MigrationInterface::STATUS_STOPPING);
$this->setMigrationResult($result);
\Drupal::keyValue('migrate_interruption_result')->set($this->id(), $result);
}
/**
* {@inheritdoc}
*/
public function isComplete() {
return $this->getMigrationResult() === static::RESULT_COMPLETED;
public function allRowsProcessed() {
$source_count = $this->getSourcePlugin()->count();
// If the source is uncountable, we have no way of knowing if it's
// complete, so stipulate that it is.
if ($source_count < 0) {
return TRUE;
}
$processed_count = $this->getIdMap()->processedCount();
// We don't use == because in some circumstances (like unresolved stubs
// being created), the processed count may be higher than the available
// source rows.
return $source_count <= $processed_count;
}
/**
......
......@@ -159,12 +159,12 @@ public function getHighWater();
public function saveHighWater($high_water);
/**
* Check if this migration is complete.
* Check if all source rows from this migration have been processed.
*
* @return bool
* TRUE if this migration is complete otherwise FALSE.
*/
public function isComplete();
public function allRowsProcessed();
/**
* Set the current migration status.
......@@ -191,20 +191,17 @@ public function getStatus();
public function getStatusLabel();
/**
* Set the migration result.
* Get the result to return upon interruption.
*
* @param int $result
* One of the RESULT_* constants.
* @return int
* The current interruption result. Defaults to RESULT_INCOMPLETE.
*/
public function setMigrationResult($result);
public function getInterruptionResult();
/**
* Get the current migration result.
*
* @return int
* The current migration result. Defaults to RESULT_INCOMPLETE.
* Clears the result to return upon interruption.
*/
public function getMigrationResult();
public function clearInterruptionResult();
/**
* Signal that the migration should be interrupted with the specified result
......
......@@ -283,7 +283,8 @@ public function import() {
// If anyone has requested we stop, return the requested result.
if ($this->migration->getStatus() == MigrationInterface::STATUS_STOPPING) {
$return = $this->migration->getMigrationResult();
$return = $this->migration->getInterruptionResult();
$this->migration->clearInterruptionResult();
break;
}
......@@ -299,7 +300,6 @@ public function import() {
}
}
$this->migration->setMigrationResult($return);
$this->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration));
$this->migration->setStatus(MigrationInterface::STATUS_IDLE);
return $return;
......@@ -346,7 +346,8 @@ public function rollback() {
// If anyone has requested we stop, return the requested result.
if ($this->migration->getStatus() == MigrationInterface::STATUS_STOPPING) {
$return = $this->migration->getMigrationResult();
$return = $this->migration->getInterruptionResult();
$this->migration->clearInterruptionResult();
break;
}
}
......@@ -356,7 +357,6 @@ public function rollback() {
}
// Notify modules that rollback attempt was complete.
$this->migration->setMigrationResult($return);
$this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($this->migration));
$this->migration->setStatus(MigrationInterface::STATUS_IDLE);
......
......@@ -153,9 +153,6 @@ protected function prepareMigrations(array $id_mappings) {
foreach ($id_mappings as $migration_id => $data) {
// Use loadMultiple() here in order to load all variants.
foreach (Migration::loadMultiple([$migration_id]) as $migration) {
// Mark the dependent migrations as complete.
$migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
$id_map = $migration->getIdMap();
$id_map->setMessage($this);
$source_ids = $migration->getSourcePlugin()->getIds();
......
......@@ -96,13 +96,13 @@ public function testRequirementsForMigrations() {
$migration_d = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
$migration_b->expects($this->once())
->method('isComplete')
->method('allRowsProcessed')
->willReturn(TRUE);
$migration_c->expects($this->once())
->method('isComplete')
->method('allRowsProcessed')
->willReturn(FALSE);
$migration_d->expects($this->once())
->method('isComplete')
->method('allRowsProcessed')
->willReturn(TRUE);
$migration_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
......
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