From f967ef7544147665be0b1bac0c4a5cd1c7b38393 Mon Sep 17 00:00:00 2001 From: Haylan Date: Thu, 17 Sep 2026 12:38:39 +0200 Subject: [PATCH] feat(dump): filter admin dump list by from/to date range Adds optional from/to query params to the dumps list endpoint and DumpLister::list(), and bumps the plugin version to 0.0.2. --- composer.json | 2 +- src/Controller/DumpController.php | 31 +++++++++++++++++++++++++++++-- src/Service/DumpLister.php | 10 +++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 9d7c2ac..adc23b7 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Export database dumps for Shopware 6 environments.", "type": "shopware-platform-plugin", "license": "MIT", - "version": "0.0.1", + "version": "0.0.2", "keywords": [ "shopware", "shopware6", diff --git a/src/Controller/DumpController.php b/src/Controller/DumpController.php index fe12eb9..175d498 100644 --- a/src/Controller/DumpController.php +++ b/src/Controller/DumpController.php @@ -11,6 +11,7 @@ use Shopware\Core\Framework\Routing\ApiRouteScope; use Shopware\Core\PlatformRequest; use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -39,16 +40,42 @@ class DumpController defaults: [PlatformRequest::ATTRIBUTE_ACL => ['aeon_dump_manager.viewer']], methods: ['GET'] )] - public function list(): JsonResponse + public function list(Request $request): JsonResponse { $dumps = array_map( static fn ($dumpFile) => $dumpFile->jsonSerialize(), - $this->dumpLister->list() + $this->dumpLister->list( + $this->parseBoundDate($request->query->get('from'), false), + $this->parseBoundDate($request->query->get('to'), true), + ) ); return new JsonResponse(['dumps' => $dumps]); } + /** + * The datepicker emits ISO-8601 UTC strings (e.g. "2026-03-01T00:00:00.000Z") + * in date mode. An empty bound (no date set) stays null so the range is open + * on that side. The "to" side is widened to end-of-day so selecting a date + * includes every dump created that day, not just before midnight. + */ + private function parseBoundDate(?string $value, bool $endOfDay): ?\DateTimeImmutable + { + if ($value === null || trim($value) === '') { + return null; + } + + try { + $dateTime = new \DateTimeImmutable($value); + } catch (\Exception) { + return null; + } + + return $endOfDay + ? $dateTime->setTime(23, 59, 59) + : $dateTime->setTime(0, 0, 0); + } + #[Route( path: '/api/_action/aeon-dump-manager/dumps', name: 'api.action.aeon_dump_manager.dumps.create', diff --git a/src/Service/DumpLister.php b/src/Service/DumpLister.php index a6c8c4f..60b42aa 100644 --- a/src/Service/DumpLister.php +++ b/src/Service/DumpLister.php @@ -18,7 +18,7 @@ class DumpLister /** * @return DumpFile[] newest first */ - public function list(): array + public function list(?\DateTimeImmutable $from = null, ?\DateTimeImmutable $to = null): array { $dumps = []; @@ -33,6 +33,14 @@ class DumpLister continue; } + if ($from !== null && $datetime < $from) { + continue; + } + + if ($to !== null && $datetime > $to) { + continue; + } + $dumps[] = new DumpFile($filename, $datetime, $item->fileSize()); }