Automattic\WooCommerce\Admin\RemoteInboxNotifications

RemoteInboxNotificationsDataSourcePoller::merge_specs │ protected │ WC 11.3.0

Merge runnable specs and track canonical publication identities independently of validation.

Method of the class: RemoteInboxNotificationsDataSourcePoller{}

No Hooks.

Returns

void. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->merge_specs( $specs_to_merge_in, $specs, $url );
$specs_to_merge_in(array) (required)
The specs to merge in to $specs.
$specs(array) (required) (passed by reference — &)
The list of specs being merged into.
$url(string) (required)
The url of the feed being merged in.

Changelog

Since 11.3.0 Introduced.

RemoteInboxNotificationsDataSourcePoller::merge_specs() code WC 11.3.0

protected function merge_specs( $specs_to_merge_in, &$specs, $url ) {
	parent::merge_specs( $specs_to_merge_in, $specs, $url );

	if ( ! in_array( $url, self::get_data_sources(), true ) ) {
		return;
	}

	$this->published_slugs = null;
	$slugs                 = array();
	foreach ( $specs_to_merge_in as $spec ) {
		if ( ! isset( $spec->slug ) || ! is_scalar( $spec->slug ) || '' === (string) $spec->slug ) {
			return;
		}
		$slug = (string) $spec->slug;
		if ( isset( $slugs[ $slug ] ) ) {
			wc_get_logger()->warning(
				'Skipping Store Alert withdrawal cleanup because the canonical feed contains a duplicate slug.',
				array(
					'source' => $url,
					'slug'   => $slug,
				)
			);
			return;
		}
		$slugs[ $slug ] = $slug;
	}
	// An empty list is inconclusive: WooCommerce.com also serves one when its own notifications query fails.
	if ( ! empty( $slugs ) ) {
		$this->published_slugs = array_values( $slugs );
	}
}