diff --git a/core/modules/migrate/src/EventSubscriber/MemoryLimitExceeded.php b/core/modules/migrate/src/EventSubscriber/MemoryLimitExceeded.php index 9ce3fdccad..682b462e07 100644 --- a/core/modules/migrate/src/EventSubscriber/MemoryLimitExceeded.php +++ b/core/modules/migrate/src/EventSubscriber/MemoryLimitExceeded.php @@ -97,42 +97,26 @@ public function reclaim(MigrateMemoryLimitEvent $event) { * A migrate memory limit event. */ public function notify(MigrateMemoryLimitEvent $event) { - $percent = round($event->getUsageRatio() * 100); - $usage = format_size($event->getUsageInBytes()); - $limit = format_size($event->getLimit()); + $results = [ + '@pct' => round($event->getUsageRatio() * 100), + '@usage' => format_size($event->getUsageInBytes()), + '@limit' => format_size($event->getLimit()), + ]; switch ($event->getPhase()) { case MemoryManagerInterface::PRE_RECLAIMED: $this->message->display($this->t( - 'Memory usage is @usage (@pct% of limit @limit), reclaiming memory.', - [ - '@pct' => $percent, - '@usage' => $usage, - '@limit' => $limit, - ] - ), 'warning'); + 'Memory usage is @usage (@pct% of limit @limit), reclaiming memory.', $results), 'warning'); break; case MemoryManagerInterface::STILL_EXCEEDED: $this->message->display($this->t( - 'Memory usage is now @usage (@pct% of limit @limit), not enough reclaimed, starting new batch', - [ - '@pct' => $percent, - '@usage' => $usage, - '@limit' => $limit, - ] - ), 'warning'); + 'Memory usage is now @usage (@pct% of limit @limit), not enough reclaimed, starting new batch', $results), 'warning'); break; case MemoryManagerInterface::REDUCED_ENOUGH_TO_CONTINUE: case '': $this->message->display($this->t( - 'Memory usage is now @usage (@pct% of limit @limit), reclaimed enough, continuing', - [ - '@pct' => $percent, - '@usage' => $usage, - '@limit' => $limit, - ] - )); + 'Memory usage is now @usage (@pct% of limit @limit), reclaimed enough, continuing', $results)); break; } } diff --git a/core/modules/migrate/src/MemoryManagerInterface.php b/core/modules/migrate/src/MemoryManagerInterface.php index 55b3e11f7a..a799159fd1 100644 --- a/core/modules/migrate/src/MemoryManagerInterface.php +++ b/core/modules/migrate/src/MemoryManagerInterface.php @@ -25,11 +25,14 @@ interface MemoryManagerInterface { /** * Tests whether we've exceeded the desired memory threshold. * + * If memory usage is too high, then dispatch a PRE_RECLAIMED MigrateEvent so + * that event listeners can reclaim memory. Then dispatch a STILL_EXCEEDED + * MigrateEvent or a REDUCED_ENOUGH_TO_CONTINUE MigrateEvent, depending on + * whether enough memory was reclaimed. + * * @return bool - * TRUE if the threshold is exceeded, otherwise FALSE. If memory usage has - * exceeded the limit then a PRE_RECLAIMED MigrateEvent is dispatched, This - * is followed by either a STILL_EXCEEDED MigrateEvent or a - * REDUCED_ENOUGH_TO_CONTINUE MigrateEvent if enough memory was reclaimed. + * TRUE if memory usage is low enough, or if enough memory can be reclaimed. + * FALSE if memory usage is too high and not enough can be reclaimed. */ public function ensureMemory(); diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index d14a9bcd7c..c218ea6b38 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -133,7 +133,7 @@ protected function getEventDispatcher() { /** * Gets the migration memory manager. * - * @return \Drupal\migrate\MemoryManager + * @return \Drupal\migrate\MemoryManagerInterface * The migration memory manager. */ protected function getMemoryManager() {