Skip to content

Commit

Permalink
Merge pull request #2118 from Daniel-KM/fix/deprecation_warning
Browse files Browse the repository at this point in the history
Fix/deprecation warning
  • Loading branch information
zerocrates authored Dec 15, 2023
2 parents 0b5d4a2 + 4f8a1c2 commit 94d120f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 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
2 changes: 1 addition & 1 deletion application/src/Form/Element/ArrayTextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function stringToList($string)
*/
protected function fixEndOfLine($string)
{
return str_replace(["\r\n", "\n\r", "\r"], ["\n", "\n", "\n"], $string);
return str_replace(["\r\n", "\n\r", "\r"], ["\n", "\n", "\n"], (string) $string);
}

/**
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 94d120f

Please sign in to comment.