feat(dump): add download functionality for dumps and improve UI interactions

This commit is contained in:
2026-09-14 23:54:57 +02:00
parent 29abb1cd59
commit 2683792fee
8 changed files with 233 additions and 67 deletions
+29
View File
@@ -9,8 +9,11 @@ use AeonDumpManager\Service\DumpService;
use AeonDumpManager\Service\Exception\DumpNotFoundException; use AeonDumpManager\Service\Exception\DumpNotFoundException;
use Shopware\Core\Framework\Routing\ApiRouteScope; use Shopware\Core\Framework\Routing\ApiRouteScope;
use Shopware\Core\PlatformRequest; use Shopware\Core\PlatformRequest;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@@ -77,6 +80,32 @@ class DumpController
return new JsonResponse(null, Response::HTTP_NO_CONTENT); return new JsonResponse(null, Response::HTTP_NO_CONTENT);
} }
#[Route(
path: '/api/_action/aeon-dump-manager/dumps/{filename}/download',
name: 'api.action.aeon_dump_manager.dumps.download',
defaults: [PlatformRequest::ATTRIBUTE_ACL => ['aeon_dump_manager.viewer']],
methods: ['GET']
)]
public function download(string $filename): StreamedResponse
{
try {
$stream = $this->dumpService->readStream($filename);
} catch (DumpNotFoundException $exception) {
throw new NotFoundHttpException($exception->getMessage());
}
$response = new StreamedResponse(static function () use ($stream): void {
fpassthru($stream);
});
$response->headers->set('Content-Type', 'application/gzip');
$response->headers->set(
'Content-Disposition',
HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $filename)
);
return $response;
}
#[Route( #[Route(
path: '/api/_action/aeon-dump-manager/dumps/jobs/{jobId}', path: '/api/_action/aeon-dump-manager/dumps/jobs/{jobId}',
name: 'api.action.aeon_dump_manager.dumps.jobs.status', name: 'api.action.aeon_dump_manager.dumps.jobs.status',
@@ -4,6 +4,7 @@
<sw-button <sw-button
v-if="acl.can('aeon_dump_manager.creator')" v-if="acl.can('aeon_dump_manager.creator')"
variant="primary" variant="primary"
:is-loading="pendingJob !== null"
:disabled="pendingJob !== null" :disabled="pendingJob !== null"
@click="onCreate" @click="onCreate"
> >
@@ -12,54 +13,99 @@
</template> </template>
<template #content> <template #content>
<sw-card-view> <div class="aeon-dump-manager-list__content">
<sw-card> <sw-data-grid
<sw-data-grid :data-source="dumps"
:data-source="dumps" :columns="columns"
:columns="columns" :is-loading="isLoading"
:is-loading="isLoading" :show-selection="acl.can('aeon_dump_manager.deleter')"
:show-selection="false" :full-page="true"
identifier="filename" identifier="filename"
> @selection-change="onSelectionChange"
<template #before-item-list> >
<tr v-if="pendingJob !== null" class="aeon-dump-manager-list__pending-row"> <template #bulk>
<td colspan="3"> <a
<span>{{ $tc('aeon-dump-manager.list.creating') }}</span> v-if="acl.can('aeon_dump_manager.deleter')"
<sw-progress-bar :max-value="100" :value="pendingJob.percent || 0" /> class="link link-danger aeon-dump-manager-list__bulk-delete"
</td> role="button"
</tr> tabindex="0"
</template> @click="onRequestBulkDelete"
@keydown.enter="onRequestBulkDelete"
>
{{ $tc('aeon-dump-manager.list.bulkDeleteButton', 0, { count: selectionCount }) }}
</a>
</template>
<template #column-datetime="{ item }"> <template #column-datetime="{ item }">
{{ formatDatetime(item.datetime) }} {{ formatDatetime(item.datetime) }}
</template> </template>
<template #column-sizeBytes="{ item }"> <template #column-sizeBytes="{ item }">
{{ formatSize(item.sizeBytes) }} {{ formatSize(item.sizeBytes) }}
</template> </template>
<template #actions="{ item }"> <template #actions="{ item }">
<sw-context-menu-item <sw-context-menu-item
v-if="acl.can('aeon_dump_manager.deleter')" v-if="acl.can('aeon_dump_manager.viewer')"
variant="danger" @click="onDownload(item.filename)"
@click="onRequestDelete(item.filename)" >
> {{ $tc('aeon-dump-manager.list.buttonDownload') }}
{{ $tc('aeon-dump-manager.list.buttonDelete') }} </sw-context-menu-item>
</sw-context-menu-item> <sw-context-menu-item
</template> v-if="acl.can('aeon_dump_manager.deleter')"
variant="danger"
@click="onRequestDelete(item.filename)"
>
{{ $tc('aeon-dump-manager.list.buttonDelete') }}
</sw-context-menu-item>
</template>
<template #empty-state> <template #empty-state>
{{ $tc('aeon-dump-manager.list.empty') }} {{ $tc('aeon-dump-manager.list.empty') }}
</template> </template>
</sw-data-grid> </sw-data-grid>
</sw-card> </div>
</sw-card-view>
</template> </template>
{% block aeon_dump_manager_list_progress_modal %}
<sw-modal
v-if="pendingJob !== null"
:title="$tc('aeon-dump-manager.list.progressTitle')"
variant="small"
class="aeon-dump-manager-list__progress-modal"
@modal-close="onCloseProgressModal"
>
<div class="aeon-dump-manager-list__progress-wrapper">
<template v-if="pendingJob.status === 'done'">
<sw-alert variant="success">
{{ $tc('aeon-dump-manager.list.createSuccess') }}
</sw-alert>
</template>
<template v-else-if="pendingJob.status === 'failed'">
<sw-alert variant="error">
{{ $tc('aeon-dump-manager.list.createFailed', 0, { error: pendingJob.errorMessage || '' }) }}
</sw-alert>
</template>
<template v-else>
<sw-progress-bar
:value="pendingJob.percent || 0"
:max-value="100"
/>
<span class="aeon-dump-manager-list__progress-text">
{{ $tc('aeon-dump-manager.list.progressText') }}
</span>
</template>
</div>
</sw-modal>
{% endblock %}
<sw-confirm-modal <sw-confirm-modal
v-if="deleteFilename !== null" v-if="deleteFilenames !== null"
:title="$tc('aeon-dump-manager.list.confirmDeleteTitle')" :title="$tc('aeon-dump-manager.list.confirmDeleteTitle')"
:text="$tc('aeon-dump-manager.list.confirmDeleteText', 0, { filename: deleteFilename })" :text="deleteFilenames.length > 1
? $tc('aeon-dump-manager.list.confirmDeleteTextMultiple', 0, { count: deleteFilenames.length })
: $tc('aeon-dump-manager.list.confirmDeleteText', 0, { filename: deleteFilenames[0] })"
type="delete"
@confirm="onConfirmDelete" @confirm="onConfirmDelete"
@cancel="onCancelDelete" @cancel="onCancelDelete"
@close="onCancelDelete" @close="onCancelDelete"
@@ -1,7 +1,7 @@
import template from './aeon-dump-manager-list.html.twig'; import template from './aeon-dump-manager-list.html.twig';
import type DumpApiService, { DumpFile, DumpJob } from '../../../../service/dump-api.service'; import type DumpApiService, { DumpFile, DumpJob } from '../../../../service/dump-api.service';
const { Component } = Shopware; const { Component, Mixin } = Shopware;
interface PendingJob { interface PendingJob {
status: string; status: string;
@@ -9,11 +9,14 @@ interface PendingJob {
errorMessage?: string | null; errorMessage?: string | null;
} }
const CREATE_MODAL_AUTO_CLOSE_MS = 1500;
interface ComponentData { interface ComponentData {
dumps: DumpFile[]; dumps: DumpFile[];
isLoading: boolean; isLoading: boolean;
pendingJob: PendingJob | null; pendingJob: PendingJob | null;
deleteFilename: string | null; deleteFilenames: string[] | null;
selection: Record<string, DumpFile>;
pollTimer: number | null; pollTimer: number | null;
} }
@@ -25,11 +28,15 @@ interface ComponentInstance extends ComponentData {
loadList: () => Promise<void>; loadList: () => Promise<void>;
stopPolling: () => void; stopPolling: () => void;
pollJobStatus: (jobId: string) => void; pollJobStatus: (jobId: string) => void;
selectionCount: number;
} }
Component.register('aeon-dump-manager-list', { Component.register('aeon-dump-manager-list', {
template, template,
// Provides createNotificationSuccess/createNotificationError, used below.
mixins: [Mixin.getByName('notification')],
inject: ['aeonDumpManagerApiService', 'acl'], inject: ['aeonDumpManagerApiService', 'acl'],
data(): ComponentData { data(): ComponentData {
@@ -37,7 +44,8 @@ Component.register('aeon-dump-manager-list', {
dumps: [], dumps: [],
isLoading: false, isLoading: false,
pendingJob: null, pendingJob: null,
deleteFilename: null, deleteFilenames: null,
selection: {},
pollTimer: null, pollTimer: null,
}; };
}, },
@@ -63,6 +71,10 @@ Component.register('aeon-dump-manager-list', {
}, },
]; ];
}, },
selectionCount(this: ComponentInstance): number {
return Object.keys(this.selection).length;
},
}, },
created(this: ComponentInstance) { created(this: ComponentInstance) {
@@ -94,6 +106,10 @@ Component.register('aeon-dump-manager-list', {
return Shopware.Utils.format.fileSize(bytes); return Shopware.Utils.format.fileSize(bytes);
}, },
onSelectionChange(this: ComponentInstance, selection: Record<string, DumpFile>) {
this.selection = selection;
},
onCreate(this: ComponentInstance) { onCreate(this: ComponentInstance) {
this.pendingJob = { percent: 0, status: 'pending' }; this.pendingJob = { percent: 0, status: 'pending' };
@@ -102,10 +118,9 @@ Component.register('aeon-dump-manager-list', {
this.pollJobStatus(response.jobId); this.pollJobStatus(response.jobId);
}) })
.catch((error: Error) => { .catch((error: Error) => {
this.pendingJob = null; // Shown in the progress modal itself, not a notification —
this.createNotificationError({ // stays open so the user can actually read what went wrong.
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: error.message }), this.pendingJob = { status: 'failed', percent: null, errorMessage: error.message };
});
}); });
}, },
@@ -114,24 +129,20 @@ Component.register('aeon-dump-manager-list', {
this.pollTimer = window.setInterval(() => { this.pollTimer = window.setInterval(() => {
this.aeonDumpManagerApiService.getJobStatus(jobId).then((job: DumpJob) => { this.aeonDumpManagerApiService.getJobStatus(jobId).then((job: DumpJob) => {
this.pendingJob = job;
if (job.status === 'done') { if (job.status === 'done') {
this.stopPolling(); this.stopPolling();
this.pendingJob = null;
this.createNotificationSuccess({ message: this.$tc('aeon-dump-manager.list.createSuccess') });
this.loadList(); this.loadList();
window.setTimeout(() => {
this.pendingJob = null;
}, CREATE_MODAL_AUTO_CLOSE_MS);
return; return;
} }
if (job.status === 'failed') { if (job.status === 'failed') {
this.stopPolling(); this.stopPolling();
this.pendingJob = null;
this.createNotificationError({
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: job.errorMessage ?? '' }),
});
return;
} }
this.pendingJob = job;
}); });
}, 2000); }, 2000);
}, },
@@ -143,20 +154,62 @@ Component.register('aeon-dump-manager-list', {
} }
}, },
onCloseProgressModal(this: ComponentInstance) {
this.stopPolling();
this.pendingJob = null;
},
onDownload(this: ComponentInstance, filename: string) {
this.aeonDumpManagerApiService.download(filename)
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
})
.catch((error: Error) => {
this.createNotificationError({
message: this.$tc('aeon-dump-manager.list.downloadFailed', 0, { error: error.message }),
});
});
},
onRequestDelete(this: ComponentInstance, filename: string) { onRequestDelete(this: ComponentInstance, filename: string) {
this.deleteFilename = filename; this.deleteFilenames = [filename];
},
onRequestBulkDelete(this: ComponentInstance) {
this.deleteFilenames = Object.keys(this.selection);
}, },
onCancelDelete(this: ComponentInstance) { onCancelDelete(this: ComponentInstance) {
this.deleteFilename = null; this.deleteFilenames = null;
}, },
onConfirmDelete(this: ComponentInstance): Promise<void> { onConfirmDelete(this: ComponentInstance): Promise<void> {
const filename = this.deleteFilename as string; const filenames = this.deleteFilenames as string[];
this.deleteFilename = null; this.deleteFilenames = null;
return this.aeonDumpManagerApiService.remove(filename) // Optimistic UI update: pull the rows out immediately rather than
.then(() => this.loadList()); // waiting on a full reload, so the grid never looks stale even if
// loadList() is slow or a later delete in the batch fails.
this.dumps = this.dumps.filter((dumpFile) => !filenames.includes(dumpFile.filename));
this.selection = {};
return Promise.all(filenames.map((filename) => this.aeonDumpManagerApiService.remove(filename)))
.then(() => this.loadList())
.catch((error: Error) => {
this.createNotificationError({
message: this.$tc('aeon-dump-manager.list.deleteFailed', 0, { error: error.message }),
});
// A delete failed after the optimistic removal — reload to
// show the real state rather than leave a wrong guess on screen.
return this.loadList();
});
}, },
}, },
}); });
@@ -9,13 +9,19 @@
"columnDatetime": "Erstellt am", "columnDatetime": "Erstellt am",
"columnSize": "Größe", "columnSize": "Größe",
"buttonCreate": "Dump erstellen", "buttonCreate": "Dump erstellen",
"buttonDownload": "Herunterladen",
"buttonDelete": "Löschen", "buttonDelete": "Löschen",
"bulkDeleteButton": "Auswahl löschen ({count})",
"confirmDeleteTitle": "Dump löschen?", "confirmDeleteTitle": "Dump löschen?",
"confirmDeleteText": "Möchten Sie \"{filename}\" wirklich löschen? Dies kann nicht rückgängig gemacht werden.", "confirmDeleteText": "Möchten Sie \"{filename}\" wirklich löschen? Dies kann nicht rückgängig gemacht werden.",
"confirmDeleteTextMultiple": "Möchten Sie {count} Dumps wirklich löschen? Dies kann nicht rückgängig gemacht werden.",
"empty": "Keine Dumps gefunden.", "empty": "Keine Dumps gefunden.",
"creating": "Dump wird erstellt", "progressTitle": "Dump wird erstellt",
"progressText": "Dump wird erstellt…",
"createFailed": "Dump konnte nicht erstellt werden: {error}", "createFailed": "Dump konnte nicht erstellt werden: {error}",
"createSuccess": "Dump erstellt." "createSuccess": "Dump erstellt.",
"deleteFailed": "Dump konnte nicht gelöscht werden: {error}",
"downloadFailed": "Dump konnte nicht heruntergeladen werden: {error}"
} }
} }
} }
@@ -9,13 +9,19 @@
"columnDatetime": "Created at", "columnDatetime": "Created at",
"columnSize": "Size", "columnSize": "Size",
"buttonCreate": "Create dump", "buttonCreate": "Create dump",
"buttonDownload": "Download",
"buttonDelete": "Delete", "buttonDelete": "Delete",
"bulkDeleteButton": "Delete selected ({count})",
"confirmDeleteTitle": "Delete dump?", "confirmDeleteTitle": "Delete dump?",
"confirmDeleteText": "Are you sure you want to delete \"{filename}\"? This cannot be undone.", "confirmDeleteText": "Are you sure you want to delete \"{filename}\"? This cannot be undone.",
"confirmDeleteTextMultiple": "Are you sure you want to delete {count} dumps? This cannot be undone.",
"empty": "No dumps found.", "empty": "No dumps found.",
"creating": "Creating dump", "progressTitle": "Creating dump",
"progressText": "Creating dump…",
"createFailed": "Could not create dump: {error}", "createFailed": "Could not create dump: {error}",
"createSuccess": "Dump created." "createSuccess": "Dump created.",
"deleteFailed": "Could not delete dump: {error}",
"downloadFailed": "Could not download dump: {error}"
} }
} }
} }
@@ -66,4 +66,13 @@ export default class DumpApiService extends ApiService {
.get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(jobId)}`, { headers: this.getBasicHeaders() }) .get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(jobId)}`, { headers: this.getBasicHeaders() })
.then((response: unknown) => ApiService.handleResponse(response)); .then((response: unknown) => ApiService.handleResponse(response));
} }
download(filename: string): Promise<Blob> {
return this.httpClient
.get(`/_action/aeon-dump-manager/dumps/${encodeURIComponent(filename)}/download`, {
headers: this.getBasicHeaders(),
responseType: 'blob',
})
.then((response: unknown) => ApiService.handleResponse(response) as Blob);
}
} }
File diff suppressed because one or more lines are too long
+17
View File
@@ -71,6 +71,23 @@ class DumpService
$this->aeonDumpManagerFilesystemPrivate->delete($path); $this->aeonDumpManagerFilesystemPrivate->delete($path);
} }
/**
* @return resource
*/
public function readStream(string $filename)
{
if (!$this->filenameParser->isValid($filename)) {
throw DumpNotFoundException::create($filename);
}
$path = DumpLister::path($filename);
if (!$this->aeonDumpManagerFilesystemPrivate->fileExists($path)) {
throw DumpNotFoundException::create($filename);
}
return $this->aeonDumpManagerFilesystemPrivate->readStream($path);
}
public function enforceMaxDumps(): void public function enforceMaxDumps(): void
{ {
$maxDumps = $this->systemConfigService->getInt('AeonDumpManager.config.maxDumps'); $maxDumps = $this->systemConfigService->getInt('AeonDumpManager.config.maxDumps');