From 980e3b8c8f1de5983dbe858eddb4726996d5f82b Mon Sep 17 00:00:00 2001 From: turegjorup Date: Fri, 28 Mar 2025 12:50:56 +0100 Subject: [PATCH 1/2] 3879: Fix date range filter error for updated field --- CHANGELOG.md | 4 ++++ src/Api/Dto/DailyOccurrence.php | 10 +++++----- src/Api/Dto/Event.php | 10 +++++----- src/Api/Dto/Occurrence.php | 10 +++++----- src/Api/Filter/ElasticSearch/DateRangeFilter.php | 3 ++- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e2e4f..18c41a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ See [keep a changelog] for information about writing changes to this log. ## [Unreleased] +## [1.1.1] - 2025-03-28 + +- Fix date range filter error for updated field + ## [1.1.0] - 2025-03-20 ### Added diff --git a/src/Api/Dto/DailyOccurrence.php b/src/Api/Dto/DailyOccurrence.php index 53622cd..1b89206 100644 --- a/src/Api/Dto/DailyOccurrence.php +++ b/src/Api/Dto/DailyOccurrence.php @@ -70,18 +70,18 @@ #[ApiFilter( DateRangeFilter::class, properties: [ - 'start' => 'start', - 'end' => 'end', - 'updated' => 'start', + 'start' => 'gte', + 'end' => 'lte', + 'updated' => 'gte', ], // Arguments only exist to provide backward compatibility with filters originally defined by the DateFilter arguments: [ 'config' => [ - 'start' => [ + 'gte' => [ 'limit' => DateLimit::gte, 'throwOnInvalid' => true, ], - 'end' => [ + 'lte' => [ 'limit' => DateLimit::lte, 'throwOnInvalid' => true, ], diff --git a/src/Api/Dto/Event.php b/src/Api/Dto/Event.php index b3dbd4a..9adb062 100644 --- a/src/Api/Dto/Event.php +++ b/src/Api/Dto/Event.php @@ -70,18 +70,18 @@ #[ApiFilter( DateRangeFilter::class, properties: [ - 'occurrences.start' => 'start', - 'occurrences.end' => 'end', - 'updated' => 'start', + 'occurrences.start' => 'gte', + 'occurrences.end' => 'lte', + 'updated' => 'gte', ], // Arguments only exist to provide backward compatibility with filters originally defined by the DateFilter arguments: [ 'config' => [ - 'start' => [ + 'gte' => [ 'limit' => DateLimit::gte, 'throwOnInvalid' => true, ], - 'end' => [ + 'lte' => [ 'limit' => DateLimit::lte, 'throwOnInvalid' => true, ], diff --git a/src/Api/Dto/Occurrence.php b/src/Api/Dto/Occurrence.php index 2a07746..e2c16ec 100644 --- a/src/Api/Dto/Occurrence.php +++ b/src/Api/Dto/Occurrence.php @@ -66,18 +66,18 @@ #[ApiFilter( DateRangeFilter::class, properties: [ - 'start' => 'start', - 'end' => 'end', - 'updated' => 'start', + 'start' => 'gte', + 'end' => 'lte', + 'updated' => 'gte', ], // Arguments only exist to provide backward compatibility with filters originally defined by the DateFilter arguments: [ 'config' => [ - 'start' => [ + 'gte' => [ 'limit' => DateLimit::gte, 'throwOnInvalid' => true, ], - 'end' => [ + 'lte' => [ 'limit' => DateLimit::lte, 'throwOnInvalid' => true, ], diff --git a/src/Api/Filter/ElasticSearch/DateRangeFilter.php b/src/Api/Filter/ElasticSearch/DateRangeFilter.php index 798dce2..a920ebf 100644 --- a/src/Api/Filter/ElasticSearch/DateRangeFilter.php +++ b/src/Api/Filter/ElasticSearch/DateRangeFilter.php @@ -83,7 +83,8 @@ public function getDescription(string $resourceClass): array private function getElasticSearchQueryRanges($property, $filter): array { if (!\is_array($filter)) { - $operator = $this->config[$property]->limit; + $fallbackOperator = $this->properties[$property]; + $operator = $this->config[$fallbackOperator]->limit; $value = $filter; } else { $operator = DateLimit::{array_key_first($filter)}; From 251b626ace3fc185386cb3ffcddbe739b9558cd8 Mon Sep 17 00:00:00 2001 From: turegjorup Date: Fri, 28 Mar 2025 12:55:47 +0100 Subject: [PATCH 2/2] 3879: Added null check --- src/Api/Filter/ElasticSearch/DateRangeFilter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Api/Filter/ElasticSearch/DateRangeFilter.php b/src/Api/Filter/ElasticSearch/DateRangeFilter.php index a920ebf..8aff932 100644 --- a/src/Api/Filter/ElasticSearch/DateRangeFilter.php +++ b/src/Api/Filter/ElasticSearch/DateRangeFilter.php @@ -82,6 +82,9 @@ public function getDescription(string $resourceClass): array private function getElasticSearchQueryRanges($property, $filter): array { + if (null === $this->properties) { + throw new \InvalidArgumentException('The property must be defined in the filter.'); + } if (!\is_array($filter)) { $fallbackOperator = $this->properties[$property]; $operator = $this->config[$fallbackOperator]->limit;