feat(dump): date-range filter, sortable columns, native date formatting #10
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"description": "Export database dumps for Shopware 6 environments.",
|
"description": "Export database dumps for Shopware 6 environments.",
|
||||||
"type": "shopware-platform-plugin",
|
"type": "shopware-platform-plugin",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"shopware",
|
"shopware",
|
||||||
"shopware6",
|
"shopware6",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use Shopware\Core\Framework\Routing\ApiRouteScope;
|
|||||||
use Shopware\Core\PlatformRequest;
|
use Shopware\Core\PlatformRequest;
|
||||||
use Symfony\Component\HttpFoundation\HeaderUtils;
|
use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
@@ -39,16 +40,42 @@ class DumpController
|
|||||||
defaults: [PlatformRequest::ATTRIBUTE_ACL => ['aeon_dump_manager.viewer']],
|
defaults: [PlatformRequest::ATTRIBUTE_ACL => ['aeon_dump_manager.viewer']],
|
||||||
methods: ['GET']
|
methods: ['GET']
|
||||||
)]
|
)]
|
||||||
public function list(): JsonResponse
|
public function list(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$dumps = array_map(
|
$dumps = array_map(
|
||||||
static fn ($dumpFile) => $dumpFile->jsonSerialize(),
|
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]);
|
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(
|
#[Route(
|
||||||
path: '/api/_action/aeon-dump-manager/dumps',
|
path: '/api/_action/aeon-dump-manager/dumps',
|
||||||
name: 'api.action.aeon_dump_manager.dumps.create',
|
name: 'api.action.aeon_dump_manager.dumps.create',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class DumpLister
|
|||||||
/**
|
/**
|
||||||
* @return DumpFile[] newest first
|
* @return DumpFile[] newest first
|
||||||
*/
|
*/
|
||||||
public function list(): array
|
public function list(?\DateTimeImmutable $from = null, ?\DateTimeImmutable $to = null): array
|
||||||
{
|
{
|
||||||
$dumps = [];
|
$dumps = [];
|
||||||
|
|
||||||
@@ -33,6 +33,14 @@ class DumpLister
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($from !== null && $datetime < $from) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($to !== null && $datetime > $to) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$dumps[] = new DumpFile($filename, $datetime, $item->fileSize());
|
$dumps[] = new DumpFile($filename, $datetime, $item->fileSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user