diff -u b/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php --- b/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Entity/Migration.php @@ -212,24 +212,17 @@ protected $entityManager; /** - * {@inheritdoc} + * Labels corresponding to each defined status. + * + * @var array */ - public function getStatusLabel() { - $status_list = [ - static::STATUS_IDLE => 'Idle', - static::STATUS_IMPORTING => 'Importing', - static::STATUS_ROLLING_BACK => 'Rolling back', - static::STATUS_STOPPING => 'Stopping', - static::STATUS_DISABLED => 'Disabled', - ]; - - if (isset($status_list[$this->getMigrationStatus()])) { - return $status_list[$this->getMigrationStatus()]; - } - else { - return ''; - } - } + protected $statusLabels = [ + self::STATUS_IDLE => 'Idle', + self::STATUS_IMPORTING => 'Importing', + self::STATUS_ROLLING_BACK => 'Rolling back', + self::STATUS_STOPPING => 'Stopping', + self::STATUS_DISABLED => 'Disabled', + ]; /** * {@inheritdoc} @@ -392,7 +385,7 @@ /** * {@inheritdoc} */ - public function setMigrationStatus($status) { + public function setStatus($status) { $migrate_status_store = \Drupal::keyValue('migrate_status'); $migrate_status_store->set($this->id(), $status); } @@ -400,7 +393,7 @@ /** * {@inheritdoc} */ - public function getMigrationStatus() { + public function getStatus() { $migrate_status_store = \Drupal::keyValue('migrate_status'); return $migrate_status_store->get($this->id(), static::STATUS_IDLE); } @@ -408,6 +401,18 @@ /** * {@inheritdoc} */ + public function getStatusLabel() { + if (isset($this->statusLabels[$this->getStatus()])) { + return $this->statusLabels[$this->getStatus()]; + } + else { + return ''; + } + } + + /** + * {@inheritdoc} + */ public function setMigrationResult($result) { $migrate_result_store = \Drupal::keyValue('migrate_result'); $migrate_result_store->set($this->id(), $result); diff -u b/core/modules/migrate/src/Entity/MigrationInterface.php b/core/modules/migrate/src/Entity/MigrationInterface.php --- b/core/modules/migrate/src/Entity/MigrationInterface.php +++ b/core/modules/migrate/src/Entity/MigrationInterface.php @@ -100,14 +100,6 @@ const RESULT_DISABLED = 6; /** - * Retrieve a label for the current status. - * - * @return string - * User-friendly string corresponding to a STATUS_ constant. - */ - public function getStatusLabel(); - - /** * Returns the initialized source plugin. * * @return \Drupal\migrate\Plugin\MigrateSourceInterface @@ -180,7 +172,7 @@ * @param int $result * One of the STATUS_* constants. */ - public function setMigrationStatus($status); + public function setStatus($status); /** * Get the current migration status. @@ -188,7 +180,15 @@ * @return int * The current migration status. Defaults to STATUS_IDLE. */ - public function getMigrationStatus(); + public function getStatus(); + + /** + * Retrieve a label for the current status. + * + * @return string + * User-friendly string corresponding to a STATUS_ constant. + */ + public function getStatusLabel(); /** * Set the migration result. diff -u b/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php --- b/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -10,7 +10,6 @@ use Drupal\Core\Utility\Error; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\migrate\Entity\MigrationInterface; -use Drupal\migrate\Entity\Migration; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -239,7 +238,7 @@ */ public function import() { // Only begin the import operation if the migration is currently idle. - if ($this->migration->getMigrationStatus() !== MigrationInterface::STATUS_IDLE) { + if ($this->migration->getStatus() !== MigrationInterface::STATUS_IDLE) { $this->message->display($this->t('Migration @id is busy with another operation: @status', array( '@id' => $this->migration->id(), @@ -262,7 +261,7 @@ return MigrationInterface::RESULT_FAILED; } - $this->migration->setMigrationStatus(MigrationInterface::STATUS_IMPORTING); + $this->migration->setStatus(MigrationInterface::STATUS_IMPORTING); $return = MigrationInterface::RESULT_COMPLETED; $source = $this->getSource(); $id_map = $this->migration->getIdMap(); @@ -273,7 +272,7 @@ catch (\Exception $e) { $this->message->display( $this->t('Migration failed with source plugin exception: !e', array('!e' => $e->getMessage())), 'error'); - $this->migration->setMigrationStatus(MigrationInterface::STATUS_IDLE); + $this->migration->setStatus(MigrationInterface::STATUS_IDLE); return MigrationInterface::RESULT_FAILED; } @@ -281,7 +280,7 @@ while ($source->valid()) { // Primarily looking for STATUS_STOPPING here, but we should quit on any // unexpected status. - if ($this->migration->getMigrationStatus() !== MigrationInterface::STATUS_IMPORTING) { + if ($this->migration->getStatus() !== MigrationInterface::STATUS_IMPORTING) { break; } $row = $source->current(); @@ -340,7 +339,7 @@ unset($sourceValues, $destinationValues); $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED; - if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { + if (($return = $this->checkThresholds()) != MigrationInterface::RESULT_COMPLETED) { break; } if ($this->timeOptionExceeded()) { @@ -353,7 +352,7 @@ $this->message->display( $this->t('Migration failed with source plugin exception: !e', array('!e' => $e->getMessage())), 'error'); - $this->migration->setMigrationStatus(MigrationInterface::STATUS_IDLE); + $this->migration->setStatus(MigrationInterface::STATUS_IDLE); return MigrationInterface::RESULT_FAILED; } } @@ -364,7 +363,7 @@ #$this->progressMessage($return); $this->migration->setMigrationResult($return); - $this->migration->setMigrationStatus(MigrationInterface::STATUS_IDLE); + $this->migration->setStatus(MigrationInterface::STATUS_IDLE); return $return; } @@ -489,33 +488,15 @@ } /** - * Checks for exceptional conditions, and display feedback. - * - * Standard top-of-loop stuff, common between rollback and import. + * Checks for exceeded resource thresholds. */ - protected function checkStatus() { + protected function checkThresholds() { if ($this->memoryExceeded()) { return MigrationInterface::RESULT_INCOMPLETE; } if ($this->maxExecTimeExceeded()) { return MigrationInterface::RESULT_INCOMPLETE; } - /* - * @TODO uncomment this - if ($this->getStatus() == MigrationInterface::STATUS_STOPPING) { - return MigrationBase::RESULT_STOPPED; - } - */ - // If feedback is requested, produce a progress message at the proper time - /* - * @TODO uncomment this - if (isset($this->feedback)) { - if (($this->feedback_unit == 'seconds' && time() - $this->lastfeedback >= $this->feedback) || - ($this->feedback_unit == 'items' && $this->processed_since_feedback >= $this->feedback)) { - $this->progressMessage(MigrationInterface::RESULT_INCOMPLETE); - } - } - */ return MigrationInterface::RESULT_COMPLETED; } diff -u b/core/modules/migrate/src/Tests/MigrateStatusTest.php b/core/modules/migrate/src/Tests/MigrateStatusTest.php --- b/core/modules/migrate/src/Tests/MigrateStatusTest.php +++ b/core/modules/migrate/src/Tests/MigrateStatusTest.php @@ -42,7 +42,7 @@ $migration->save(); // Default status is idle. - $status = $migration->getMigrationStatus(); + $status = $migration->getStatus(); $this->assertIdentical($status, MigrationInterface::STATUS_IDLE); // Test setting and retrieving all known status values. @@ -54,8 +54,8 @@ MigrationInterface::STATUS_DISABLED, ); foreach ($status_list as $status) { - $migration->setMigrationStatus($status); - $this->assertIdentical($migration->getMigrationStatus(), $status); + $migration->setStatus($status); + $this->assertIdentical($migration->getStatus(), $status); } }