Have NavigationNudge and NavigationFeedback self-delete when irrelevant (https://github.com/woocommerce/woocommerce-admin/pull/7914)

* If the navigation feature does not exist, have the NavigationNudge note self-action.

* Create delete_if_not_supported method on NavigationNudge note.
If we encounter this situation again we might consider adding a version of this method to NoteTraits.

* Add possibly_delete_notes() to do_wc_admin_daily().

* Add changelog entry for Issue 7807.

* Add should_note_exist() method to NavigationNudge note.

* Add should_note_exist() and delete_if_not_supported() to NavigationFeedback.

* Add NavigationFeedback::delete_if_not_supported() to possibly_delete_notes() in daily cron.

* Fix changelog missing PR number.

* Update changelog to include navigation feedback note.

* Rename should_note_exist and delete_if_not_supported to is_applicable and delete_if_not_applicable, add to NoteTraits.
This commit is contained in:
Jacob Sewell 2021-11-15 22:51:53 -06:00 committed by GitHub
parent 1ccb1f6e1d
commit f0aebb8046
5 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: Fix
Navigation nudge note and navigation feedback notes will delete themselves if the navigation feature is not available. #7914

View File

@ -97,6 +97,7 @@ class Events {
*/
public function do_wc_admin_daily() {
$this->possibly_add_notes();
$this->possibly_delete_notes();
if ( $this->is_remote_inbox_notifications_enabled() ) {
DataSourcePoller::get_instance()->read_specs_from_data_sources();
@ -156,6 +157,14 @@ class Events {
UpdateStoreDetails::possibly_add_note();
}
/**
* Deletes notes that should be deleted.
*/
protected function possibly_delete_notes() {
NavigationNudge::delete_if_not_applicable();
NavigationFeedback::delete_if_not_applicable();
}
/**
* Checks if remote inbox notifications are enabled.
*

View File

@ -24,6 +24,13 @@ class NavigationFeedback {
*/
const NOTE_NAME = 'wc-admin-navigation-feedback';
/**
* Should this note exist? (The navigation feature should exist.)
*/
public static function is_applicable() {
return Features::exists( 'navigation' );
}
/**
* Get the note.
*

View File

@ -33,13 +33,20 @@ class NavigationNudge {
add_action( 'update_option_' . Navigation::TOGGLE_OPTION_NAME, array( $this, 'action_note' ), 10, 2 );
}
/**
* Should this note exist? (The navigation feature should exist.)
*/
public static function is_applicable() {
return Features::exists( 'navigation' );
}
/**
* Get the note.
*
* @return Note
*/
public static function get_note() {
if ( Features::is_enabled( 'navigation' ) || ! Features::exists( 'navigation' ) ) {
if ( Features::is_enabled( 'navigation' ) || ! self::is_applicable() ) {
return;
}

View File

@ -98,6 +98,31 @@ trait NoteTraits {
self::possibly_add_note();
}
/**
* Should this note exist? (Default implementation is generous. Override as needed.)
*/
public static function is_applicable() {
return true;
}
/**
* Delete this note if it is not applicable, unless has been soft-deleted or actioned already.
*/
public static function delete_if_not_applicable() {
if ( ! self::is_applicable() ) {
$data_store = Notes::load_data_store();
$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
if ( ! empty( $note_ids ) ) {
$note = Notes::get_note( $note_ids[0] );
if ( ! $note->get_is_deleted() && ( Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) ) {
return self::possibly_delete_note();
}
}
}
}
/**
* Possibly delete the note, if it exists in the database. Note that this
* is a hard delete, for where it doesn't make sense to soft delete or