Skip to content

Commit

Permalink
Log each run of updateEntity()
Browse files Browse the repository at this point in the history
  • Loading branch information
lkmorlan committed Dec 5, 2023
1 parent 66076db commit 88e23e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion html/modules/custom/bc_dc/bc_dc.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
13 changes: 11 additions & 2 deletions html/modules/custom/bc_dc/src/Service/UpdateReviewStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,6 +15,7 @@
*/
class UpdateReviewStatus implements ContainerInjectionInterface {

use LoggerChannelTrait;
use ReviewReminderTrait;

const REVIEW_NEEDED = 1;
Expand All @@ -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,
) {
}

Expand All @@ -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'),
);
}

Expand All @@ -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;
}
Expand All @@ -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());
}

}

0 comments on commit 88e23e9

Please sign in to comment.