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 @@ -27,20 +27,6 @@ protected $migration; /** - * The number of successfully imported rows since feedback was given. - * - * @var int - */ - protected $successesSinceFeedback = 0; - - /** - * The number of rows that were successfully processed. - * - * @var int - */ - protected $totalSuccesses = 0; - - /** * Status of one row. * * The value is a MigrateIdMapInterface::STATUS_* constant, for example: @@ -51,15 +37,6 @@ protected $sourceRowStatus; /** - * The number of rows processed. - * - * The total attempted, whether or not they were successful. - * - * @var int - */ - protected $totalProcessed = 0; - - /** * The queued messages not yet saved. * * Each element in the array is an array with two keys: @@ -81,6 +58,13 @@ protected $options; /** + * An object for tracking statistics. + * + * @var MigrationStatistics + */ + protected $statistics; + + /** * The PHP max_execution_time. * * @var int @@ -116,13 +100,6 @@ protected $sourceIdValues; /** - * The number of rows processed since feedback was given. - * - * @var int - */ - protected $processedSinceFeedback = 0; - - /** * The PHP memory_limit expressed in bytes. * * @var int @@ -183,10 +160,14 @@ * * @throws \Drupal\migrate\MigrateException */ - public function __construct(MigrationInterface $migration, MigrateMessageInterface $message) { + public function __construct(MigrationInterface $migration, MigrateMessageInterface $message, MigrationStatisticsInterface $statistics = NULL) { $this->migration = $migration; $this->message = $message; $this->migration->getIdMap()->setMessage($message); + if (is_null($statistics)) { + $statistics = new MigrationStatistics(); + } + $this->statistics = $statistics; // Record the memory limit in bytes $limit = trim(ini_get('memory_limit')); if ($limit == '-1') { @@ -290,8 +271,7 @@ if ($destination_id_values !== TRUE) { $id_map->saveIdMapping($row, $destination_id_values, $this->sourceRowStatus, $this->rollbackAction); } - $this->successesSinceFeedback++; - $this->totalSuccesses++; + $this->statistics->incrementSuccesses(); } else { $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); @@ -312,8 +292,7 @@ $this->handleException($e); } } - $this->totalProcessed++; - $this->processedSinceFeedback++; + $this->statistics->incrementProcessed(); if ($high_water_property = $this->migration->get('highWaterProperty')) { $this->migration->saveHighWater($row->getSourceProperty($high_water_property['name'])); } @@ -605,57 +584,12 @@ } /** - * Returns the number of items successfully imported since the last feedback. - * - * @param boolean $reset - * TRUE to reset the number of successes since feedback to 0. - * - * @return int - * The number of successes since last feedback. - */ - public function getSuccessesSinceFeedback($reset = FALSE) { - $num_successes = $this->successesSinceFeedback; - if ($reset) { - $this->successesSinceFeedback = 0; - } - return $num_successes; - } - - /** - * Returns the number of items successfully imported on this run. - * - * @return int - * The total number of successes. - */ - public function getTotalSuccesses() { - return $this->totalSuccesses; - } - - /** - * Returns the number of items processed since the last feedback. - * - * @param boolean $reset - * TRUE to reset the number of processed since feedback to 0. - * - * @return int - * The number of items processed since last feedback. - */ - public function getProcessedSinceFeedback($reset = FALSE) { - $num_processed = $this->processedSinceFeedback; - if ($reset) { - $this->processedSinceFeedback = 0; - } - return $num_processed; - } - - /** - * Returns the number of items processed on this run. + * Return an object containing current execution statistics for a migration. * - * @return int - * The total number of items processed. + * @return MigrationStatistics */ - public function getTotalProcessed() { - return $this->totalProcessed; + public function getStatistics() { + return $this->statistics; } /** diff -u b/core/modules/migrate/src/MigrateExecutableInterface.php b/core/modules/migrate/src/MigrateExecutableInterface.php --- b/core/modules/migrate/src/MigrateExecutableInterface.php +++ b/core/modules/migrate/src/MigrateExecutableInterface.php @@ -45,42 +45,11 @@ public function getTimeLimit(); /** - * Returns the number of items successfully imported since the last feedback. + * Return an object containing current execution statistics for a migration. * - * @param boolean $reset - * TRUE to reset the number of successes since feedback to 0. - * - * @return int - * The number of successes since last feedback. - */ - public function getSuccessesSinceFeedback($reset = FALSE); - - /** - * Returns the number of items successfully imported on this run. - * - * @return int - * The total number of successes. - */ - public function getTotalSuccesses(); - - /** - * Returns the number of items processed since the last feedback. - * - * @param boolean $reset - * TRUE to reset the number of processed since feedback to 0. - * - * @return int - * The number of items processed since last feedback. - */ - public function getProcessedSinceFeedback($reset = FALSE); - - /** - * Returns the number of items processed on this run. - * - * @return int - * The total number of items processed. + * @return MigrationStatistics */ - public function getTotalProcessed(); + public function getStatistics(); /** * Passes messages through to the map class. only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/MigrationStatistics.php @@ -0,0 +1,115 @@ +successesSinceFeedback; + if ($reset) { + $this->successesSinceFeedback = 0; + } + return $num_successes; + } + + /** + * Returns the number of items successfully imported on this run. + * + * @return int + * The total number of successes. + */ + public function getTotalSuccesses() { + return $this->totalSuccesses; + } + + /** + * Increment the success statistics. + */ + public function incrementSuccesses() { + $this->successesSinceFeedback++; + $this->totalSuccesses++; + } + + /** + * Returns the number of items processed since the last feedback. + * + * @param boolean $reset + * TRUE to reset the number of processed since feedback to 0. + * + * @return int + * The number of items processed since last feedback. + */ + public function getProcessedSinceFeedback($reset = FALSE) { + $num_processed = $this->processedSinceFeedback; + if ($reset) { + $this->processedSinceFeedback = 0; + } + return $num_processed; + } + + /** + * Returns the number of items processed on this run. + * + * @return int + * The total number of items processed. + */ + public function getTotalProcessed() { + return $this->totalProcessed; + } + + /** + * Increment the processed statistics. + */ + public function incrementProcessed() { + $this->processedSinceFeedback++; + $this->totalProcessed++; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/MigrationStatisticsInterface.php @@ -0,0 +1,63 @@ +assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import()); - $this->assertSame(1, $this->executable->getSuccessesSinceFeedback()); - $this->assertSame(1, $this->executable->getTotalSuccesses()); - $this->assertSame(1, $this->executable->getTotalProcessed()); - $this->assertSame(1, $this->executable->getProcessedSinceFeedback()); + $statistics = $this->executable->getStatistics(); + $this->assertSame(1, $statistics->getSuccessesSinceFeedback()); + $this->assertSame(1, $statistics->getTotalSuccesses()); + $this->assertSame(1, $statistics->getTotalProcessed()); + $this->assertSame(1, $statistics->getProcessedSinceFeedback()); } /** @@ -171,10 +172,11 @@ public function testImportWithValidRowWithoutDestinationId() { $this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import()); - $this->assertSame(1, $this->executable->getSuccessesSinceFeedback()); - $this->assertSame(1, $this->executable->getTotalSuccesses()); - $this->assertSame(1, $this->executable->getTotalProcessed()); - $this->assertSame(1, $this->executable->getProcessedSinceFeedback()); + $statistics = $this->executable->getStatistics(); + $this->assertSame(1, $statistics->getSuccessesSinceFeedback()); + $this->assertSame(1, $statistics->getTotalSuccesses()); + $this->assertSame(1, $statistics->getTotalProcessed()); + $this->assertSame(1, $statistics->getProcessedSinceFeedback()); } /**