Automattic\WooCommerce\Internal\PushNotifications\Services

StepLogQuery::for_notification │ public │ WC 11.3.0

Returns every step recorded for one resource's notifications of one type, from the journey file and from the module's error log.

Метод класса: StepLogQuery{}

Хуков нет.

Возвращает

array{rows: array, counts: array<string, int>, covered_from: int, next_to: int|null, logging: array}.

Использование

$StepLogQuery = new StepLogQuery();
$StepLogQuery->for_notification( $type, $resource_id, $from, $to, $limit ): array;
$type(строка) (обязательный)
The notification type, e.g. store_order.
$resource_id(int) (обязательный)
The order, comment or product ID.
$from(int) (обязательный)
Earliest timestamp, inclusive.
$to(int) (обязательный)
Latest timestamp, inclusive.
$limit(int) (обязательный)
Rows to return, newest first.

Список изменений

С версии 11.3.0 Введена.

Код StepLogQuery::for_notification() WC 11.3.0

public function for_notification( string $type, int $resource_id, int $from, int $to, int $limit ): array {
	$sources = array(
		NotificationStepLogger::get_notification_source_for_type( $type ),
		NotificationStepLogger::SUPPRESSED_SOURCE,
		PushNotifications::FEATURE_NAME,
	);

	return $this->query(
		$sources,
		$from,
		$to,
		$limit,
		function ( array $row ) use ( $type, $resource_id ): array {
			$context = $row['context'] ?? array();

			/*
			 * A batch line covers many notifications, so it names each one
			 * by type and resource ID rather than carrying one of its own.
			 */
			if ( isset( $context['notifications'] ) && is_array( $context['notifications'] ) ) {
				foreach ( $context['notifications'] as $covered ) {
					if ( isset( $covered['type'], $covered['resource_id'] )
						&& $type === $covered['type']
						&& $resource_id === (int) $covered['resource_id'] ) {
						return array( $row );
					}
				}

				return array();
			}

			return isset( $context['type'], $context['resource_id'] )
				&& $type === $context['type']
				&& $resource_id === (int) $context['resource_id']
					? array( $row )
					: array();
		}
	);
}