Skip to content

Commit

Permalink
(Small refactor, for tighter code.)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhgov committed Jun 27, 2024
1 parent 864de16 commit 7487abc
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions html/modules/custom/bc_dc/src/Service/ReviewReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,27 @@ public function sendRemindersToAllUsers(): void {
public function sendRemindersToOneUser(int $uid, array $notifications): ?bool {
$account = $this->entityTypeManager->getStorage('user')->load($uid);
$email = $account?->getEmail();
$logger = $this->getLogger('bc_dc');

if (!$email) {
$context = [
'@uid' => $uid,
];
$this->getLogger('bc_dc')->error('ReviewReminder: User @uid has no email address.', $context);
$logger->error('ReviewReminder: User @uid has no email address.', ['@uid' => $uid]);
return NULL;
}

$body = $this->generateBody($notifications);
if (!$body) {
$context = [
'@uid' => $uid,
];
$this->getLogger('bc_dc')->error('ReviewReminder: Empty message for user @uid.', $context);
$logger->error('ReviewReminder: Empty message for user @uid.', ['@uid' => $uid]);
return NULL;
}

$subject = $this->t('Metadata records you maintain need updates', [], ['langcode' => $account->getPreferredLangcode()]);

$success = GcNotifyApiService::sendMessage([$email], $subject, $body);
if ($success) {
$context = [
'@uid' => $uid,
];
$this->getLogger('bc_dc')->notice('Sent ReviewReminder message to user @uid.', $context);
$logger->notice('Sent ReviewReminder message to user @uid.', ['@uid' => $uid]);
}
else {
$context = [
'@uid' => $uid,
];
$this->getLogger('bc_dc')->error('Failed to send ReviewReminder message to user @uid.', $context);
$logger->error('Failed to send ReviewReminder message to user @uid.', ['@uid' => $uid]);
}

return $success;
Expand Down

0 comments on commit 7487abc

Please sign in to comment.