From b5bff4b4e7a02b5466fff0823a00f9115bd3b5fb Mon Sep 17 00:00:00 2001 From: Daniel Sasser <221539+dsasser@users.noreply.github.com> Date: Fri, 7 Mar 2025 08:01:45 -0800 Subject: [PATCH] VACMS-20726: Change the behavior of logging widget updates so it is more clear which nodes get updates and which do not. --- .../ReactWidgetUpdatesForMHVMigration.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/docroot/modules/custom/va_gov_batch/src/cbo_scripts/ReactWidgetUpdatesForMHVMigration.php b/docroot/modules/custom/va_gov_batch/src/cbo_scripts/ReactWidgetUpdatesForMHVMigration.php index cde04420f1..02ba46085a 100644 --- a/docroot/modules/custom/va_gov_batch/src/cbo_scripts/ReactWidgetUpdatesForMHVMigration.php +++ b/docroot/modules/custom/va_gov_batch/src/cbo_scripts/ReactWidgetUpdatesForMHVMigration.php @@ -129,8 +129,9 @@ public function processOne(string $key, mixed $item, array &$sandbox): string { private function updateWidget(NodeInterface $node): string { $path = $node->toUrl()->toString(); $nodeMessage = "node_{$node->id()}: {$node->getTitle()}:{$path}: "; - // Store message for each widget we find. Some nodes may have multiple. - $foundWidgets = []; + // Store message for each widget we update. While unlikely that a node will + // have multiple widgets, we need to ensure we are not missing any updates. + $updates = []; // The widget will always be in field field_content_block as a paragraph. /** @var \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem $item */ foreach ($node->get('field_content_block') as $item) { @@ -144,19 +145,25 @@ private function updateWidget(NodeInterface $node): string { // Update the name of this widget to the new MHV widget name. $paragraph->set(self::WIDGET_FIELD_NAME, $newWidgetName); $paragraph->save(); - $foundWidgets[] = $nodeMessage . "updated widget from {$currentWidgetName} to {$newWidgetName} in paragraph id {$paragraph->id()}"; + $updates[] = $nodeMessage . "updated widget from {$currentWidgetName} to {$newWidgetName} in paragraph id {$paragraph->id()}"; } catch (EntityStorageException $e) { - return "Error saving paragraph id {$paragraph->id()}. This is unexpected and manual migration may be required. The error was {$e->getMessage()}"; + $this->batchOpLog->appendError($nodeMessage . "Error saving paragraph id {$paragraph->id()}. This is unexpected and manual migration may be required. The error was {$e->getMessage()}"); } } else { - $foundWidgets[] = $nodeMessage . "node has a React widget {$currentWidgetName} but it is not in target list."; + $this->batchOpLog->appendLog($nodeMessage . "node has a React widget {$currentWidgetName} but it is not in target list."); } } } - array_walk($foundWidgets, fn($message) => $this->batchOpLog->appendLog($message)); - return "Finished widget updates."; + if (count($updates) > 0) { + array_walk($updates, fn($message) => $this->batchOpLog->appendLog($message)); + $count = count($updates); + return $nodeMessage . "{$count} widget update(s) made."; + } + else { + return $nodeMessage . "no widget updates were made."; + } } }