From 88e23e97f1acfbbe78483150befa6455a6b1de73 Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Tue, 5 Dec 2023 17:40:12 -0500 Subject: [PATCH] Log each run of updateEntity() --- html/modules/custom/bc_dc/bc_dc.services.yml | 2 +- .../custom/bc_dc/src/Service/UpdateReviewStatus.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/html/modules/custom/bc_dc/bc_dc.services.yml b/html/modules/custom/bc_dc/bc_dc.services.yml index fbb410ab..0fafd01b 100644 --- a/html/modules/custom/bc_dc/bc_dc.services.yml +++ b/html/modules/custom/bc_dc/bc_dc.services.yml @@ -4,4 +4,4 @@ services: arguments: ['@config.factory', '@entity_type.manager', '@logger.factory', '@string_translation'] bc_dc.update_review_status: class: Drupal\bc_dc\Service\UpdateReviewStatus - arguments: ['@entity_type.manager'] + arguments: ['@entity_type.manager', '@logger.factory'] diff --git a/html/modules/custom/bc_dc/src/Service/UpdateReviewStatus.php b/html/modules/custom/bc_dc/src/Service/UpdateReviewStatus.php index b5b8b85b..a4d8276d 100644 --- a/html/modules/custom/bc_dc/src/Service/UpdateReviewStatus.php +++ b/html/modules/custom/bc_dc/src/Service/UpdateReviewStatus.php @@ -5,6 +5,8 @@ use Drupal\bc_dc\Trait\ReviewReminderTrait; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -13,6 +15,7 @@ */ class UpdateReviewStatus implements ContainerInjectionInterface { + use LoggerChannelTrait; use ReviewReminderTrait; const REVIEW_NEEDED = 1; @@ -23,9 +26,12 @@ class UpdateReviewStatus implements ContainerInjectionInterface { * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity_type.manager service. + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory + * The logger.factory service. */ public function __construct( protected EntityTypeManagerInterface $entityTypeManager, + LoggerChannelFactoryInterface $loggerFactory, ) { } @@ -35,6 +41,7 @@ public function __construct( public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), + $container->get('logger.factory'), ); } @@ -51,14 +58,14 @@ public function updateAll(): void { foreach ($data_set_nids as $data_set_nid) { $data_set = $node_storage->load($data_set_nid); - static::updateEntity($data_set); + $this->updateEntity($data_set); } } /** * Update field_review_status for a single node. */ - public static function updateEntity(NodeInterface $entity): void { + public function updateEntity(NodeInterface $entity): void { if (!$entity->hasField('field_review_status')) { return; } @@ -71,6 +78,8 @@ public static function updateEntity(NodeInterface $entity): void { $update_value = static::dataSetReviewNeeded($entity); $update_value = $status_mapping[$update_value] ?? NULL; $entity->set('field_review_status', $update_value)->save(); + + $this->getLogger('bc_dc')->notice('Update review status: ' . ($update_value ?? 'NULL') . ': ' . $entity->getTitle()); } }