Automattic\WooCommerce\Internal\PushNotifications\Services
NotificationProcessor::log_recipients
Writes the recipient decision to the step log: one line naming the recipients, and one line naming the tokens that were excluded.
A store can hold thousands of tokens, and a log source has a daily size ceiling past which its oldest lines are overwritten without a trace, so both lines name their tokens in arrays.
Method of the class: NotificationProcessor{}
No Hooks.
Returns
void. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->log_recipients( $notification, $eligible_tokens, $recipients, $suppression_reasons, $step_context ): void;
- $notification(Notification) (required)
- The notification being processed.
- $eligible_tokens(PushToken[]) (required)
- Tokens whose owner has a role that receives push notifications.
- $recipients(PushToken[]) (required)
- The tokens the notification will be sent to.
- $suppression_reasons(array<int, string>) (required)
- The reason each dropped token was excluded, as token ID => reason.
- $step_context(array) (required)
- Fields shared by every line of this attempt.
NotificationProcessor::log_recipients() NotificationProcessor::log recipients code WC 11.3.0
private function log_recipients(
Notification $notification,
array $eligible_tokens,
array $recipients,
array $suppression_reasons,
array $step_context
): void {
if ( ! $this->step_logger->is_active() ) {
return;
}
$recipient_ids = array_map( fn( PushToken $token ) => (int) $token->get_id(), $recipients );
$context = array_merge(
$step_context,
array(
'tokens_total' => $this->data_store->count_tokens(),
'tokens_eligible' => count( $eligible_tokens ),
'recipients' => count( $recipients ),
'held_back' => count( $suppression_reasons ),
'held_back_reasons' => array_count_values( $suppression_reasons ),
)
);
if ( empty( $eligible_tokens ) ) {
$this->step_logger->log_notification_step( $notification, 'recipients', 'none', $context );
} elseif ( empty( $recipients ) ) {
$this->step_logger->log_notification_step( $notification, 'recipients', 'all_excluded', $context );
} else {
$context['token_ids'] = array_slice( $recipient_ids, 0, self::RECIPIENT_ID_CAP );
$this->step_logger->log_notification_step( $notification, 'recipients', 'resolved', $context );
}
$this->log_excluded_tokens( $notification, $suppression_reasons, $step_context );
}