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.
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user