From c25ee9ad53124d528fe3e4eb9e01f88e22591185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B4me=20Bakker?= Date: Thu, 20 Jun 2024 14:24:55 +0200 Subject: [PATCH] added: support for restorable / trashed entities --- classes/ColdTrick/OpenSearch/EventDispatcher.php | 2 +- elgg-plugin.php | 5 +++++ lib/functions.php | 2 +- views/default/admin/opensearch/inspect.php | 10 +++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/classes/ColdTrick/OpenSearch/EventDispatcher.php b/classes/ColdTrick/OpenSearch/EventDispatcher.php index c63e115..bb53845 100644 --- a/classes/ColdTrick/OpenSearch/EventDispatcher.php +++ b/classes/ColdTrick/OpenSearch/EventDispatcher.php @@ -46,7 +46,7 @@ public static function update(\Elgg\Event $event): void { /** * Listen to all delete events and update OpenSearch as needed * - * @param \Elgg\Event $event 'delete', 'all' + * @param \Elgg\Event $event 'delete|trash:after', 'all' * * @return void */ diff --git a/elgg-plugin.php b/elgg-plugin.php index 324cdd7..2091df9 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -153,6 +153,11 @@ ], ], ], + 'trash:after' => [ + 'all' => [ + '\ColdTrick\OpenSearch\EventDispatcher::delete' => [], + ], + ], 'update' => [ 'all' => [ '\ColdTrick\OpenSearch\EventDispatcher::update' => [], diff --git a/lib/functions.php b/lib/functions.php index 0e3d479..1351d37 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -207,7 +207,7 @@ function opensearch_add_document_for_deletion(int $guid, array $info, mixed $tim function opensearch_remove_document_for_deletion(int $guid): void { // check if the entity still exists in Elgg (could be unregistered as searchable) // and remove indexing timestamp, so it can be reindexed when needed - elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES | ELGG_DISABLE_SYSTEM_LOG, function() use ($guid) { + elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES | ELGG_DISABLE_SYSTEM_LOG | ELGG_SHOW_DELETED_ENTITIES, function() use ($guid) { $entity = get_entity($guid); if ($entity instanceof \ElggEntity) { unset($entity->{OPENSEARCH_INDEXED_NAME}); diff --git a/views/default/admin/opensearch/inspect.php b/views/default/admin/opensearch/inspect.php index ee7831e..0e8ad36 100644 --- a/views/default/admin/opensearch/inspect.php +++ b/views/default/admin/opensearch/inspect.php @@ -7,6 +7,7 @@ 'method' => 'GET', 'action' => 'admin/opensearch/inspect', 'disable_security' => true, + 'class' => 'mbl', ]; echo elgg_view_form('opensearch/inspect', $form_vars); @@ -20,9 +21,12 @@ $registered_types = opensearch_get_registered_entity_types(); -$entity = get_entity($guid); -if (empty($entity)) { - // Entity doesn't exist in Elgg +$entity = elgg_call(ELGG_SHOW_DELETED_ENTITIES, function() use ($guid) { + return get_entity($guid); +}); + +if (!$entity instanceof \ElggEntity) { + // Entity doesn't exist in Elgg or was trashed $result = elgg_view('output/longtext', [ 'value' => elgg_echo('notfound'), ]);