Skip to content

Commit

Permalink
Fixed deprecation warning when searching null id.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Nov 20, 2023
1 parent 619c0af commit 2c5116a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 7 additions & 6 deletions application/src/Api/Adapter/AbstractEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,21 @@ public function buildBaseQuery(QueryBuilder $qb, array $query)
{
if (isset($query['id'])) {
$ids = $query['id'];
if (is_string($ids) || is_int($ids)) {
if (is_int($ids)) {
$ids = [(string) $ids];
} elseif (is_string($ids)) {
// Account for comma-delimited IDs.
$ids = false === strpos($ids, ',') ? [$ids] : explode(',', $ids);
} elseif (!is_array($ids)) {
} elseif (is_array($ids)) {
$ids = array_map('strval', $ids);
} else {
// This is an invalid ID. Set to an empty array.
$ids = [];
}
// Exclude null and empty-string IDs. Previous resource-only version
// used is_numeric, but we want this to be able to work for possible
// string IDs also.
$ids = array_map('trim', $ids);
$ids = array_filter($ids, function ($id) {
return !($id === null || $id === '');
});
$ids = array_filter(array_map('trim', $ids), 'strlen');
if ($ids) {
$qb->andWhere($qb->expr()->in(
'omeka_root.id',
Expand Down
15 changes: 9 additions & 6 deletions application/src/View/Helper/SearchFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,19 @@ public function __invoke($partialName = null, array $query = null)

case 'id':
$filterLabel = $translate('ID');
// Avoid a deprecated issue, so convert ids as string.
$ids = $value;
if (is_string($ids) || is_int($ids)) {
$ids = false === strpos($ids, ',') ? [$ids] : explode(',', $ids);
} elseif (!is_array($ids)) {
if (is_int($ids)) {
$ids = [(string) $ids];
} elseif (is_string($ids)) {
$ids = strpos($ids, ',') === false ? [$ids] : explode(',', $ids);
} elseif (is_array($ids)) {
$ids = array_map('strval', $ids);
} else {
$ids = [];
}
$ids = array_map('trim', $ids);
$ids = array_filter($ids, function ($id) {
return !($id === null || $id === '');
});
$ids = array_filter($ids, 'strlen');
$filters[$filterLabel][] = implode(', ', $ids);
break;
}
Expand Down

0 comments on commit 2c5116a

Please sign in to comment.