Automattic\WooCommerce\Admin\RemoteInboxNotifications
RemoteInboxNotificationsEngine::hide_withdrawn_alerts
Move unactioned WooCommerce.com-owned alerts to pending when the canonical feed no longer lists them.
Only alerts that last changed status well before that read are hidden, so an older read (for example, one cached for another locale) cannot hide an alert that newer specs made visible.
Method of the class: RemoteInboxNotificationsEngine{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = RemoteInboxNotificationsEngine::hide_withdrawn_alerts( $processed_slugs, ?array $snapshot ): void;
- $processed_slugs(string[]) (required)
- Slugs of the specs this run processed, after filtering.
- ?array $snapshot(required)
- .
RemoteInboxNotificationsEngine::hide_withdrawn_alerts() RemoteInboxNotificationsEngine::hide withdrawn alerts code WC 11.3.0
private static function hide_withdrawn_alerts( array $processed_slugs, ?array $snapshot ): void {
if ( null === $snapshot ) {
return;
}
/**
* Note data store.
*
* @var DataStore $data_store
*/
$data_store = Notes::load_data_store();
$alerts = $data_store->lookup_notes(
array(
'source' => array( 'woocommerce.com' ),
'type' => array( Note::E_WC_ADMIN_NOTE_ERROR, Note::E_WC_ADMIN_NOTE_UPDATE ),
'status' => array( Note::E_WC_ADMIN_NOTE_UNACTIONED ),
)
);
if ( empty( $alerts ) ) {
return;
}
$published_slugs = array_fill_keys( array_merge( $snapshot['slugs'], $processed_slugs ), true );
$changed_before = $snapshot['fetched_at'] - self::WITHDRAWN_ALERT_GRACE_PERIOD;
foreach ( $alerts as $alert ) {
// Stored dates are GMT; the creation date moves forward whenever a spec changes the note's status.
$changed_at = wc_string_to_timestamp( $alert->date_created );
if ( isset( $published_slugs[ $alert->name ] ) || (int) $changed_at <= 0 || $changed_at >= $changed_before ) {
continue;
}
$note = Notes::get_note( $alert->note_id );
if ( ! $note instanceof Note ) {
continue;
}
$note->set_status( Note::E_WC_ADMIN_NOTE_PENDING );
$note->save();
wc_get_logger()->info(
'Changed an unactioned Store Alert to pending because it is no longer published by WooCommerce.com.',
array(
'source' => 'remote-inbox-notifications',
'note_id' => $note->get_id(),
'slug' => $note->get_name(),
'fetched_at' => $snapshot['fetched_at'],
)
);
}
}