Skip to content

Commit

Permalink
added: support for restorable / trashed entities
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 20, 2024
1 parent d7d90ad commit c25ee9a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion classes/ColdTrick/OpenSearch/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
],
],
],
'trash:after' => [
'all' => [
'\ColdTrick\OpenSearch\EventDispatcher::delete' => [],
],
],
'update' => [
'all' => [
'\ColdTrick\OpenSearch\EventDispatcher::update' => [],
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
10 changes: 7 additions & 3 deletions views/default/admin/opensearch/inspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'method' => 'GET',
'action' => 'admin/opensearch/inspect',
'disable_security' => true,
'class' => 'mbl',
];
echo elgg_view_form('opensearch/inspect', $form_vars);

Expand All @@ -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'),
]);
Expand Down

0 comments on commit c25ee9a

Please sign in to comment.