Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 18, 2024
1 parent 3656622 commit d565a44
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 82 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenSearch

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![OpenSearch 2.5](https://img.shields.io/badge/OpenSearch-2.5-green.svg)
![Lint Checks](https://github.com/ColdTrick/opensearch/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/opensearch/v/stable.svg)](https://packagist.org/packages/coldtrick/opensearch)
Expand Down
6 changes: 3 additions & 3 deletions classes/ColdTrick/OpenSearch/Di/DeleteQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function name(): string {
*
* @param int $number number of items to dequeue
*/
public function dequeue(int $number = 100) {
public function dequeue(int $number = 100): ?array {
// get a record for processing
$select = Select::fromTable(self::TABLE_NAME);
$select->select('*')
Expand All @@ -49,7 +49,7 @@ public function dequeue(int $number = 100) {

$rows = $this->db->getData($select);
if (empty($rows)) {
return;
return null;
}

$ids = [];
Expand All @@ -65,7 +65,7 @@ public function dequeue(int $number = 100) {
->andWhere($update->expr()->isNull('worker'));

if ($this->db->updateData($update, true) < 1) {
return;
return null;
}

// remove locked record from database
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/OpenSearch/Di/IndexingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function bulkDeleteDocuments(): bool {
// document was removed
opensearch_remove_document_for_deletion($guid);
} else {
// some error occured, reschedule delete
// some error occurred, reschedule delete
opensearch_add_document_for_deletion($guid, $documents[$guid], '+1 hour');
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/OpenSearch/Menus/AdminHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AdminHeader {
/**
* Add menu items to the admin page menu
*
* @param \Elgg\Event $event 'register', 'menu:page'
* @param \Elgg\Event $event 'register', 'menu:admin_header'
*
* @return null|MenuItems
*/
Expand Down
4 changes: 2 additions & 2 deletions classes/ColdTrick/OpenSearch/SearchEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ protected static function detectUnsupportedSearchParams(array $params): bool {

if (!elgg_in_context('search')) {
// make sure all supplied type_subtype_pairs are supported for search
// if a non supported type/subtype is found don't handle the search through OpenSearch
// if a non-supported type/subtype is found don't handle the search through OpenSearch
// if not in the search context
$temp = new SearchParams();
$normalized_params = $temp->normalizeOptions($params);
Expand Down Expand Up @@ -577,7 +577,7 @@ protected static function transformSearchResults(SearchResult $result, array $ev
return $result->getCount();
}

return $result->toEntities($event_params);
return $result->toEntities();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions classes/ColdTrick/OpenSearch/SearchParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getBody(bool $count = false): array {
*
* @return mixed
*/
protected function getParam($name, $default = null) {
protected function getParam(string $name, mixed $default = null): mixed {
if (!isset($this->params[$name])) {
return $default;
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public function setNoMatchFilter(array $filter): void {
*
* @return null|array
*/
public function getNoMatchFilter(): array {
public function getNoMatchFilter(): ?array {
return $this->getParam('no_match_filter');
}

Expand Down Expand Up @@ -324,7 +324,7 @@ public function setSort(array $sort = []): void {
*
* @return void
*/
public function addSort(string $field, $sort_config = []): void {
public function addSort(string $field, array $sort_config = []): void {
if (empty($field)) {
return;
}
Expand Down Expand Up @@ -519,7 +519,7 @@ public function getAggregation(): ?array {
/**
* Set suggestion params for search
*
* @param string $query search query
* @param null|string $query search query
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/OpenSearch/SearchParams/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function getQueryFields(array $search_params = []): array {
break;
case 'annotations':
// support user profile fields
if (strpos($name, 'profile:') === 0) {
if (str_starts_with($name, 'profile:')) {
$name = substr($name, strlen('profile:'));
$result[] = "metadata.{$name}";
break;
Expand Down
12 changes: 2 additions & 10 deletions classes/ColdTrick/OpenSearch/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
*/
class SearchResult {

protected array $result;

protected array $search_params;

/**
* Create a new SearchResults helper
*
* @param array $result results from OpenSearch
* @param array $search_params original search params
*/
public function __construct(array $result, array $search_params) {
$this->result = $result;
$this->search_params = $search_params;
public function __construct(protected array $result, protected array $search_params) {
}

/**
Expand Down Expand Up @@ -100,11 +94,9 @@ public function getSuggestions(): array {
/**
* Convert search results to entities
*
* @param array $params additional params
*
* @return \ElggEntity[]
*/
public function toEntities($params): array {
public function toEntities(): array {
$hits = $this->getHits();
if (empty($hits)) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"opensearch-project/opensearch-php": "^2.0.0"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
}
}
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

use ColdTrick\OpenSearch\Di\DeleteQueue;
use Elgg\Database\MetadataTable;
use Elgg\Database\QueryBuilder;
use Elgg\Database\Select;
use Elgg\Exceptions\ExceptionInterface;
Expand Down Expand Up @@ -94,19 +95,19 @@ function opensearch_get_bulk_options(string $type = 'no_index_ts'): ?array {
return array_merge($defaults, [
'wheres' => [
function (QueryBuilder $qb, $main_alias) {
$select = $qb->subquery('metadata', 'mdi');
$select->select('mdi.entity_guid')
->where($qb->compare('mdi.name', '=', OPENSEARCH_INDEXED_NAME, ELGG_VALUE_STRING));
$select = $qb->subquery(MetadataTable::TABLE_NAME, 'mdi');
$select->select("{$select->getTableAlias()}.entity_guid")
->where($qb->compare("{$select->getTableAlias()}.name", '=', OPENSEARCH_INDEXED_NAME, ELGG_VALUE_STRING));

return $qb->compare("{$main_alias}.guid", 'NOT IN', $select->getSQL());
},
function (QueryBuilder $qb, $main_alias) {
$select = $qb->subquery('metadata', 'b');
$select->select('b.entity_guid')
->joinEntitiesTable('b', 'entity_guid', 'inner', 'be');
$select = $qb->subquery(MetadataTable::TABLE_NAME, 'b');
$select->select("{$select->getTableAlias()}.entity_guid")
->joinEntitiesTable($select->getTableAlias(), 'entity_guid', 'inner', 'be');
$select->where($qb->compare('be.type', '=', 'user', ELGG_VALUE_STRING))
->andWhere($qb->compare('b.name', '=', 'banned', ELGG_VALUE_STRING))
->andWhere($qb->compare('b.value', '=', 'yes', ELGG_VALUE_STRING));
->andWhere($qb->compare("{$select->getTableAlias()}.name", '=', 'banned', ELGG_VALUE_STRING))
->andWhere($qb->compare("{$select->getTableAlias()}.value", '=', 'yes', ELGG_VALUE_STRING));

return $qb->compare("{$main_alias}.guid", 'NOT IN', $select->getSQL());
},
Expand Down Expand Up @@ -167,7 +168,7 @@ function (QueryBuilder $qb, $main_alias) {
*
* @return void
*/
function opensearch_add_document_for_deletion(int $guid, array $info, $time_offset = null): void {
function opensearch_add_document_for_deletion(int $guid, array $info, mixed $time_offset = null): void {
try {
$queue = DeleteQueue::instance();
} catch (\Exception $e) {
Expand Down Expand Up @@ -205,7 +206,7 @@ function opensearch_add_document_for_deletion(int $guid, array $info, $time_offs
*/
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
// 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) {
$entity = get_entity($guid);
if ($entity instanceof \ElggEntity) {
Expand Down Expand Up @@ -257,7 +258,7 @@ function opensearch_get_documents_for_deletion(): array {
*
* @return null|array
*/
function opensearch_inspect_show_values($key, array $merged_values, array $elgg_values, array $opensearch_values, int $depth = 0): ?array {
function opensearch_inspect_show_values(mixed $key, array $merged_values, array $elgg_values, array $opensearch_values, int $depth = 0): ?array {
$rows = [];
if (empty($depth)) {
$rows[] = elgg_format_element('tr', [], elgg_format_element('th', ['colspan' => 3], $key));
Expand Down
1 change: 1 addition & 0 deletions views/default/admin/opensearch/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

echo elgg_view_form('opensearch/admin_search', [
'prevent_double_submit' => false,
'class' => 'mbl',
]);

echo elgg_view_module('info', elgg_echo('opensearch:admin_search:results'), elgg_echo('opensearch:admin_search:results:info'), [
Expand Down
14 changes: 0 additions & 14 deletions views/default/forms/opensearch/admin_search.js

This file was deleted.

15 changes: 15 additions & 0 deletions views/default/forms/opensearch/admin_search.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'jquery';
import Ajax from 'elgg/Ajax';

$(document).on('submit', 'form.elgg-form-opensearch-admin-search', function(event) {
event.preventDefault();

var $form = $(this);
var ajax = new Ajax();
ajax.action('opensearch/admin_search', {
data: ajax.objectify($form),
success: function(data) {
$('#opensearch-admin-search-results > .elgg-body').html(data);
}
});
});
Loading

0 comments on commit d565a44

Please sign in to comment.