Update the registration logic

When notes are not enabled, we need to unregister/delete them if they were previously registered
This commit is contained in:
Narek Zakarian 2025-08-15 20:32:22 +04:00
parent 63ecb23039
commit 95e85ec51c
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -29,6 +29,11 @@ class InboxNoteRegistrar {
public function register(): void {
foreach ( $this->inbox_notes as $inbox_note ) {
if ( ! $inbox_note->is_enabled() ) {
$this->unregister( $inbox_note->name() );
continue;
}
$inbox_note_name = $inbox_note->name();
if ( Notes::get_note_by_name( $inbox_note_name ) ) {
@ -56,4 +61,17 @@ class InboxNoteRegistrar {
$note->save();
}
}
public function unregister( string $inbox_note_name ): void {
$data_store = Notes::load_data_store();
$existing_note_ids = $data_store->get_notes_with_name( $inbox_note_name );
foreach ( $existing_note_ids as $note_id ) {
$note = Notes::get_note( $note_id );
if ( $note ) {
$data_store->delete( $note );
}
}
}
}