Compare commits
20
Commits
b89a878b92
..
v0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec5c40c9f2 | ||
|
|
56ada0cedc | ||
|
|
f50154b96b | ||
|
|
7aa11b0396 | ||
|
|
161c35dc8a | ||
|
|
a1f0160ab9 | ||
|
|
1ee83aad37 | ||
|
|
b2c2a8d80b | ||
|
|
31b9e61adb | ||
|
|
5a482b49bb | ||
|
|
6094b6f49c | ||
|
|
e5c3a5b28f | ||
|
|
f967ef7544 | ||
|
|
20492e8c80 | ||
|
|
2c7a105332 | ||
|
|
0401859227 | ||
|
|
2683792fee | ||
|
|
29abb1cd59 | ||
|
|
05e1d0eeb9 | ||
|
|
59e48c8f21 |
@@ -0,0 +1,40 @@
|
||||
name: version-changelog
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
version-changelog:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check version bump and changelog entry
|
||||
run: |
|
||||
set -e
|
||||
PR_VERSION=$(grep -m1 '"version"' composer.json | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
|
||||
MAIN_VERSION=$(git show origin/main:composer.json | grep -m1 '"version"' | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
|
||||
|
||||
echo "main version: $MAIN_VERSION"
|
||||
echo "PR version: $PR_VERSION"
|
||||
|
||||
if [ "$MAIN_VERSION" = "$PR_VERSION" ]; then
|
||||
echo "::error::composer.json version ($PR_VERSION) was not bumped from main ($MAIN_VERSION)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HIGHEST=$(printf '%s\n%s\n' "$MAIN_VERSION" "$PR_VERSION" | sort -V | tail -n1)
|
||||
if [ "$HIGHEST" != "$PR_VERSION" ]; then
|
||||
echo "::error::composer.json version ($PR_VERSION) is not greater than main's ($MAIN_VERSION)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -qF "## [$PR_VERSION]" CHANGELOG.md; then
|
||||
echo "::error::CHANGELOG.md is missing a '## [$PR_VERSION]' heading"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "OK: version bumped to $PR_VERSION and documented in CHANGELOG.md"
|
||||
@@ -0,0 +1,100 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
SERVER_URL: https://git.arthurerlich.de
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
||||
|
||||
- name: Determine version and guard against re-release
|
||||
id: version
|
||||
run: |
|
||||
set -e
|
||||
VERSION=$(grep -m1 '"version"' composer.json | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
|
||||
TAG="v${VERSION}"
|
||||
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}"; then
|
||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||
echo "Tag ${TAG} already exists, nothing to release."
|
||||
else
|
||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Extract changelog section
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: |
|
||||
awk -v ver="${{ steps.version.outputs.version }}" '
|
||||
BEGIN { found=0 }
|
||||
/^## \[/ {
|
||||
if (found) exit
|
||||
if ($0 ~ "\[" ver "\]") { found=1; next }
|
||||
}
|
||||
found { print }
|
||||
' CHANGELOG.md > release-notes.md
|
||||
cat release-notes.md
|
||||
|
||||
- name: Create and push tag
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: |
|
||||
git config user.name "gitea-actions"
|
||||
git config user.email "actions@git.arthurerlich.de"
|
||||
git tag "${{ steps.version.outputs.tag }}"
|
||||
git push origin "${{ steps.version.outputs.tag }}"
|
||||
|
||||
- name: Install shopware-cli
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: |
|
||||
curl -sL -o /tmp/shopware-cli.tar.gz \
|
||||
https://github.com/shopware/shopware-cli/releases/latest/download/shopware-cli_Linux_x86_64.tar.gz
|
||||
mkdir -p /tmp/swcli-extract
|
||||
tar -xzf /tmp/shopware-cli.tar.gz -C /tmp/swcli-extract
|
||||
cp /tmp/swcli-extract/shopware-cli /usr/local/bin/shopware-cli
|
||||
|
||||
- name: Validate extension (informational only, does not gate the release)
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: shopware-cli extension validate . || true
|
||||
|
||||
- name: Package Store-style zip for the Gitea Release asset
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: |
|
||||
shopware-cli extension package . --output-directory .build \
|
||||
--filename "AeonDumpManager-${{ steps.version.outputs.tag }}.zip"
|
||||
|
||||
- name: Build root-level zip for the Composer registry
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: git archive --format=zip -o "composer-package-${{ steps.version.outputs.tag }}.zip" "${{ steps.version.outputs.tag }}"
|
||||
|
||||
- name: Create Gitea Release
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
server_url: ${{ env.SERVER_URL }}
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
||||
tag_name: ${{ steps.version.outputs.tag }}
|
||||
name: ${{ steps.version.outputs.tag }}
|
||||
body_path: release-notes.md
|
||||
files: .build/AeonDumpManager-${{ steps.version.outputs.tag }}.zip
|
||||
|
||||
- name: Publish to Composer registry
|
||||
if: steps.version.outputs.skip == 'false'
|
||||
run: |
|
||||
STATUS=$(curl -s -o /tmp/composer-publish.log -w "%{http_code}" \
|
||||
-u "haylan:${{ secrets.RELEASE_TOKEN }}" \
|
||||
-T "composer-package-${{ steps.version.outputs.tag }}.zip" \
|
||||
"https://git.arthurerlich.de/api/packages/haylan/composer")
|
||||
cat /tmp/composer-publish.log
|
||||
if [ "$STATUS" != "201" ] && [ "$STATUS" != "409" ]; then
|
||||
echo "Unexpected HTTP status $STATUS publishing to the Composer registry"
|
||||
exit 1
|
||||
fi
|
||||
@@ -12,6 +12,11 @@ composer.phar
|
||||
/custom/
|
||||
/src/Shopware/Platform
|
||||
|
||||
# Frontend
|
||||
*.vite/
|
||||
**/public/administration/js/
|
||||
**/public/static/js/
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to AeonDumpManager will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.0.3] - 2026-09-17
|
||||
|
||||
### Added
|
||||
|
||||
- Filter the dump list by date range and sort by date or size; dates use Shopware's locale-aware
|
||||
formatting.
|
||||
|
||||
## [0.0.2] - 2026-09-21
|
||||
|
||||
### Added
|
||||
|
||||
- Automated release pipeline: a pre-merge check enforcing a semver version bump and a matching
|
||||
CHANGELOG entry on every PR into `main`, and a post-merge workflow that tags the release,
|
||||
packages the plugin with `shopware-cli`, publishes a Gitea Release with the packaged zip, and
|
||||
publishes the package to this Gitea instance's Composer registry.
|
||||
- `main` is now a protected branch: no direct pushes, merges require the version/changelog check
|
||||
to pass.
|
||||
|
||||
## [0.0.1] - 2026-09-15
|
||||
|
||||
### Added
|
||||
|
||||
- List, create, delete, and download gzip-compressed SQL dumps from a Settings admin page (async
|
||||
creation with a polling progress bar) or via the `aeon:dump:list`, `aeon:dump:create`, and
|
||||
`aeon:dump:remove` console commands (sync). Dumps are produced with `mysqldump`/`mariadb-dump`
|
||||
(auto-detected, overridable via `dumpBinaryName`) and stored in the plugin's private filesystem.
|
||||
- Retention controls: `maxDumps` purges the oldest dump when the limit is reached; `retantionDays`
|
||||
purges expired dumps and stale job rows via a scheduled task.
|
||||
- ACL-gated by `aeon_dump_manager.viewer`/`.creator`/`.deleter`, enforced client- and server-side.
|
||||
+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.3",
|
||||
"keywords": [
|
||||
"shopware",
|
||||
"shopware6",
|
||||
|
||||
@@ -6,10 +6,15 @@ use AeonDumpManager\MessageQueue\Message\CreateDumpMessage;
|
||||
use AeonDumpManager\Service\DumpJobStatusService;
|
||||
use AeonDumpManager\Service\DumpLister;
|
||||
use AeonDumpManager\Service\DumpService;
|
||||
use Shopware\Core\Framework\Api\Route\ApiRouteScope;
|
||||
use AeonDumpManager\Service\Exception\DumpNotFoundException;
|
||||
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;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
@@ -35,16 +40,46 @@ 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 admin's date filter sends mixed shapes: the "from" bound is a naive local
|
||||
* date string with no timezone marker (e.g. "2026-03-01T00:00:00"), while
|
||||
* sw-date-filter widens "to" to end-of-day client-side via `Date#toISOString()`,
|
||||
* which is always UTC (e.g. "2026-03-01T23:59:59.000Z"). Re-expressing both in
|
||||
* PHP's default timezone (the same one DumpFilenameParser uses) before applying
|
||||
* our own day-boundary keeps the calendar day the user actually picked, regardless
|
||||
* of which shape arrived. An empty bound (no date set) stays null so the range is
|
||||
* open on that side.
|
||||
*/
|
||||
private function parseBoundDate(?string $value, bool $endOfDay): ?\DateTimeImmutable
|
||||
{
|
||||
if ($value === null || trim($value) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$dateTime = (new \DateTimeImmutable($value))->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
} 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',
|
||||
@@ -67,11 +102,41 @@ class DumpController
|
||||
)]
|
||||
public function delete(string $filename): JsonResponse
|
||||
{
|
||||
$this->dumpService->delete($filename);
|
||||
try {
|
||||
$this->dumpService->delete($filename);
|
||||
} catch (DumpNotFoundException $exception) {
|
||||
return new JsonResponse(['message' => $exception->getMessage()], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
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(
|
||||
path: '/api/_action/aeon-dump-manager/dumps/jobs/{jobId}',
|
||||
name: 'api.action.aeon_dump_manager.dumps.jobs.status',
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Shopware injects its Administration API as untyped globals at runtime; there's
|
||||
// no official @shopware-ag type package for plugin authors to install against
|
||||
// (per docs/research/admin-dump-manager-ui.md §4), so these are declared loosely
|
||||
// as `any` — good enough for editor support, and the build (swc, type-stripping
|
||||
// only, no tsc typecheck) doesn't need them at all.
|
||||
declare const Shopware: any;
|
||||
|
||||
interface Window {
|
||||
Shopware: typeof Shopware;
|
||||
}
|
||||
|
||||
declare module '*.html.twig' {
|
||||
const template: string;
|
||||
export default template;
|
||||
}
|
||||
|
||||
declare module '*.json' {
|
||||
const value: Record<string, unknown>;
|
||||
export default value;
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import DumpApiService from './service/dump-api.service';
|
||||
import './module/aeon-dump-manager';
|
||||
|
||||
Shopware.Application.addServiceProvider('aeonDumpManagerApiService', (container) => {
|
||||
Shopware.Application.addServiceProvider('aeonDumpManagerApiService', (container: { loginService: unknown }) => {
|
||||
const initContainer = Shopware.Application.getContainer('init');
|
||||
|
||||
return new DumpApiService(initContainer.httpClient, container.loginService);
|
||||
@@ -1,39 +0,0 @@
|
||||
import './acl';
|
||||
import './page/aeon-dump-manager-list';
|
||||
import deDE from './snippet/de-DE.json';
|
||||
import enGB from './snippet/en-GB.json';
|
||||
|
||||
Shopware.Module.register('aeon-dump-manager', {
|
||||
type: 'plugin',
|
||||
name: 'DumpManager',
|
||||
title: 'aeon-dump-manager.general.mainMenuItemGeneral',
|
||||
description: 'aeon-dump-manager.general.descriptionTextModule',
|
||||
color: '#ff3d58',
|
||||
icon: 'default-object-storage',
|
||||
|
||||
snippets: {
|
||||
'de-DE': deDE,
|
||||
'en-GB': enGB,
|
||||
},
|
||||
|
||||
routes: {
|
||||
list: {
|
||||
component: 'aeon-dump-manager-list',
|
||||
path: 'list',
|
||||
meta: {
|
||||
parentPath: 'sw.settings.index.system',
|
||||
privilege: 'aeon_dump_manager.viewer',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Shown as a card on the Settings page's "System" group, next to
|
||||
// Plugins/Cache — matches the locked ACL/menu-naming decision. Plugins
|
||||
// cannot register a first-level main-menu entry.
|
||||
settingsItem: {
|
||||
group: 'system',
|
||||
to: 'aeon.dump.manager.list',
|
||||
icon: 'default-object-storage',
|
||||
privilege: 'aeon_dump_manager.viewer',
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import './acl';
|
||||
import './page/aeon-dump-manager-list';
|
||||
import deDE from './snippet/de-DE.json';
|
||||
import enGB from './snippet/en-GB.json';
|
||||
|
||||
Shopware.Module.register('aeon-dump-manager', {
|
||||
type: 'plugin',
|
||||
name: 'DumpManager',
|
||||
title: 'aeon-dump-manager.general.mainMenuItemGeneral',
|
||||
description: 'aeon-dump-manager.general.descriptionTextModule',
|
||||
color: '#ff3d58',
|
||||
icon: 'regular-database',
|
||||
|
||||
snippets: {
|
||||
'de-DE': deDE,
|
||||
'en-GB': enGB,
|
||||
},
|
||||
|
||||
routes: {
|
||||
list: {
|
||||
component: 'aeon-dump-manager-list',
|
||||
path: 'list',
|
||||
meta: {
|
||||
parentPath: 'sw.settings.index.system',
|
||||
privilege: 'aeon_dump_manager.viewer',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Per https://developer.shopware.com/docs/v6.6/guides/plugins/plugins/administration/routing-navigation/add-menu-entry.html —
|
||||
// plugins can't register a first-level main-menu entry, so this nests
|
||||
// under the core 'sw-settings' navigation node. Clicking Settings in the
|
||||
// main sidebar shows this as a sub-item, landing at #/sw/settings/.
|
||||
navigation: [{
|
||||
id: 'aeon-dump-manager-list',
|
||||
label: 'aeon-dump-manager.general.mainMenuItemGeneral',
|
||||
color: '#ff3d58',
|
||||
path: 'aeon.dump.manager.list',
|
||||
icon: 'regular-database',
|
||||
parent: 'sw-settings',
|
||||
position: 100,
|
||||
privilege: 'aeon_dump_manager.viewer',
|
||||
}],
|
||||
|
||||
// Also shown as a card on the Settings overview page's "System" group,
|
||||
// next to Plugins/Cache — complements the navigation entry above.
|
||||
settingsItem: {
|
||||
group: 'system',
|
||||
to: 'aeon.dump.manager.list',
|
||||
icon: 'regular-database',
|
||||
privilege: 'aeon_dump_manager.viewer',
|
||||
},
|
||||
});
|
||||
+96
-40
@@ -4,6 +4,7 @@
|
||||
<sw-button
|
||||
v-if="acl.can('aeon_dump_manager.creator')"
|
||||
variant="primary"
|
||||
:is-loading="pendingJob !== null"
|
||||
:disabled="pendingJob !== null"
|
||||
@click="onCreate"
|
||||
>
|
||||
@@ -12,54 +13,109 @@
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<sw-card-view>
|
||||
<sw-card>
|
||||
<sw-data-grid
|
||||
:data-source="dumps"
|
||||
:columns="columns"
|
||||
:is-loading="isLoading"
|
||||
:show-selection="false"
|
||||
identifier="filename"
|
||||
>
|
||||
<template #before-item-list>
|
||||
<tr v-if="pendingJob !== null" class="aeon-dump-manager-list__pending-row">
|
||||
<td colspan="3">
|
||||
<span>{{ $tc('aeon-dump-manager.list.creating') }}</span>
|
||||
<sw-progress-bar :max-value="100" :value="pendingJob.percent || 0" />
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<div class="aeon-dump-manager-list__content">
|
||||
<sw-filter-panel
|
||||
:filters="listFilters"
|
||||
:defaults="defaultFilters"
|
||||
:store-key="storeKey"
|
||||
@criteria-changed="onCriteriaChanged"
|
||||
/>
|
||||
|
||||
<template #column-datetime="{ item }">
|
||||
{{ formatDatetime(item.datetime) }}
|
||||
</template>
|
||||
<sw-data-grid
|
||||
:data-source="sortedDumps"
|
||||
:columns="columns"
|
||||
:is-loading="isLoading"
|
||||
:show-selection="acl.can('aeon_dump_manager.deleter')"
|
||||
:full-page="true"
|
||||
:sort-by="sortBy"
|
||||
:sort-direction="sortDirection"
|
||||
identifier="filename"
|
||||
@selection-change="onSelectionChange"
|
||||
@column-sort="onSortColumn"
|
||||
>
|
||||
<template #bulk>
|
||||
<a
|
||||
v-if="acl.can('aeon_dump_manager.deleter')"
|
||||
class="link link-danger aeon-dump-manager-list__bulk-delete"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@click="onRequestBulkDelete"
|
||||
@keydown.enter="onRequestBulkDelete"
|
||||
>
|
||||
{{ $tc('aeon-dump-manager.list.bulkDeleteButton', 0, { count: selectionCount }) }}
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<template #column-sizeBytes="{ item }">
|
||||
{{ formatSize(item.sizeBytes) }}
|
||||
</template>
|
||||
<template #column-datetime="{ item }">
|
||||
{{ formatDatetime(item.datetime) }}
|
||||
</template>
|
||||
|
||||
<template #actions="{ item }">
|
||||
<sw-context-menu-item
|
||||
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 #column-sizeBytes="{ item }">
|
||||
{{ formatSize(item.sizeBytes) }}
|
||||
</template>
|
||||
|
||||
<template #empty-state>
|
||||
{{ $tc('aeon-dump-manager.list.empty') }}
|
||||
</template>
|
||||
</sw-data-grid>
|
||||
</sw-card>
|
||||
</sw-card-view>
|
||||
<template #actions="{ item }">
|
||||
<sw-context-menu-item
|
||||
v-if="acl.can('aeon_dump_manager.viewer')"
|
||||
@click="onDownload(item.filename)"
|
||||
>
|
||||
{{ $tc('aeon-dump-manager.list.buttonDownload') }}
|
||||
</sw-context-menu-item>
|
||||
<sw-context-menu-item
|
||||
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>
|
||||
{{ $tc('aeon-dump-manager.list.empty') }}
|
||||
</template>
|
||||
</sw-data-grid>
|
||||
</div>
|
||||
</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
|
||||
v-if="deleteFilename !== null"
|
||||
v-if="deleteFilenames !== null"
|
||||
: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"
|
||||
@cancel="onCancelDelete"
|
||||
@close="onCancelDelete"
|
||||
|
||||
-137
@@ -1,137 +0,0 @@
|
||||
import template from './aeon-dump-manager-list.html.twig';
|
||||
|
||||
const { Component } = Shopware;
|
||||
|
||||
Component.register('aeon-dump-manager-list', {
|
||||
template,
|
||||
|
||||
inject: ['aeonDumpManagerApiService', 'acl'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
dumps: [],
|
||||
isLoading: false,
|
||||
pendingJob: null,
|
||||
deleteFilename: null,
|
||||
pollTimer: null,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
columns() {
|
||||
return [
|
||||
{
|
||||
property: 'datetime',
|
||||
label: this.$tc('aeon-dump-manager.list.columnDatetime'),
|
||||
allowResize: true,
|
||||
},
|
||||
{
|
||||
property: 'filename',
|
||||
label: this.$tc('aeon-dump-manager.list.columnFilename'),
|
||||
allowResize: true,
|
||||
},
|
||||
{
|
||||
property: 'sizeBytes',
|
||||
label: this.$tc('aeon-dump-manager.list.columnSize'),
|
||||
align: 'right',
|
||||
allowResize: true,
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
|
||||
created() {
|
||||
this.loadList();
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.stopPolling();
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadList() {
|
||||
this.isLoading = true;
|
||||
|
||||
return this.aeonDumpManagerApiService.getList()
|
||||
.then((response) => {
|
||||
this.dumps = response.dumps;
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
|
||||
formatDatetime(value) {
|
||||
return new Date(value).toLocaleString();
|
||||
},
|
||||
|
||||
formatSize(bytes) {
|
||||
return Shopware.Utils.format.fileSize(bytes);
|
||||
},
|
||||
|
||||
onCreate() {
|
||||
this.pendingJob = { percent: 0, status: 'pending' };
|
||||
|
||||
this.aeonDumpManagerApiService.create()
|
||||
.then((response) => {
|
||||
this.pollJobStatus(response.jobId);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.pendingJob = null;
|
||||
this.createNotificationError({
|
||||
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: error.message }),
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
pollJobStatus(jobId) {
|
||||
this.stopPolling();
|
||||
|
||||
this.pollTimer = window.setInterval(() => {
|
||||
this.aeonDumpManagerApiService.getJobStatus(jobId).then((job) => {
|
||||
if (job.status === 'done') {
|
||||
this.stopPolling();
|
||||
this.pendingJob = null;
|
||||
this.createNotificationSuccess({ message: this.$tc('aeon-dump-manager.list.createSuccess') });
|
||||
this.loadList();
|
||||
return;
|
||||
}
|
||||
|
||||
if (job.status === 'failed') {
|
||||
this.stopPolling();
|
||||
this.pendingJob = null;
|
||||
this.createNotificationError({
|
||||
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: job.errorMessage }),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.pendingJob = job;
|
||||
});
|
||||
}, 2000);
|
||||
},
|
||||
|
||||
stopPolling() {
|
||||
if (this.pollTimer !== null) {
|
||||
window.clearInterval(this.pollTimer);
|
||||
this.pollTimer = null;
|
||||
}
|
||||
},
|
||||
|
||||
onRequestDelete(filename) {
|
||||
this.deleteFilename = filename;
|
||||
},
|
||||
|
||||
onCancelDelete() {
|
||||
this.deleteFilename = null;
|
||||
},
|
||||
|
||||
onConfirmDelete() {
|
||||
const filename = this.deleteFilename;
|
||||
this.deleteFilename = null;
|
||||
|
||||
return this.aeonDumpManagerApiService.remove(filename)
|
||||
.then(() => this.loadList());
|
||||
},
|
||||
},
|
||||
});
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
import template from './aeon-dump-manager-list.html.twig';
|
||||
import type DumpApiService, { DumpFile, DumpJob } from '../../../../service/dump-api.service';
|
||||
|
||||
const { Component, Mixin } = Shopware;
|
||||
|
||||
interface PendingJob {
|
||||
status: string;
|
||||
percent: number | null;
|
||||
errorMessage?: string | null;
|
||||
}
|
||||
|
||||
const CREATE_MODAL_AUTO_CLOSE_MS = 1500;
|
||||
|
||||
interface DateRangeCriteria {
|
||||
type: string;
|
||||
field: string;
|
||||
parameters?: { gte?: string; lte?: string };
|
||||
}
|
||||
|
||||
interface ComponentData {
|
||||
dumps: DumpFile[];
|
||||
isLoading: boolean;
|
||||
pendingJob: PendingJob | null;
|
||||
deleteFilenames: string[] | null;
|
||||
selection: Record<string, DumpFile>;
|
||||
pollTimer: number | null;
|
||||
dateFrom: string | null;
|
||||
dateTo: string | null;
|
||||
sortBy: string;
|
||||
sortDirection: string;
|
||||
storeKey: string;
|
||||
defaultFilters: string[];
|
||||
}
|
||||
|
||||
interface ComponentInstance extends ComponentData {
|
||||
aeonDumpManagerApiService: DumpApiService;
|
||||
$tc: (key: string, count?: number, values?: Record<string, unknown>) => string;
|
||||
createNotificationError: (options: { message: string }) => void;
|
||||
createNotificationSuccess: (options: { message: string }) => void;
|
||||
getList: () => Promise<void>;
|
||||
stopPolling: () => void;
|
||||
pollJobStatus: (jobId: string) => void;
|
||||
selectionCount: number;
|
||||
sortedDumps: DumpFile[];
|
||||
listFilters: Record<string, unknown>[];
|
||||
}
|
||||
|
||||
Component.register('aeon-dump-manager-list', {
|
||||
template,
|
||||
|
||||
mixins: [
|
||||
// Provides createNotificationSuccess/createNotificationError, used below.
|
||||
Mixin.getByName('notification'),
|
||||
// Provides sortBy/sortDirection state, onSortColumn(), and route-query
|
||||
// persistence for them (same mixin sw-product-list etc. use) — our own
|
||||
// data() below overrides the defaults to keep "newest first".
|
||||
Mixin.getByName('listing'),
|
||||
],
|
||||
|
||||
inject: ['aeonDumpManagerApiService', 'acl'],
|
||||
|
||||
data(): ComponentData {
|
||||
return {
|
||||
dumps: [],
|
||||
isLoading: false,
|
||||
pendingJob: null,
|
||||
deleteFilenames: null,
|
||||
selection: {},
|
||||
pollTimer: null,
|
||||
dateFrom: null,
|
||||
dateTo: null,
|
||||
sortBy: 'datetime',
|
||||
sortDirection: 'DESC',
|
||||
storeKey: 'grid.filter.aeon-dump-manager',
|
||||
defaultFilters: ['datetime'],
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
listFilters(this: ComponentInstance) {
|
||||
return [
|
||||
{
|
||||
name: 'datetime',
|
||||
type: 'date-filter',
|
||||
property: 'datetime',
|
||||
label: this.$tc('aeon-dump-manager.list.columnDatetime'),
|
||||
dateType: 'date',
|
||||
fromFieldLabel: this.$tc('aeon-dump-manager.list.filterFromLabel'),
|
||||
toFieldLabel: this.$tc('aeon-dump-manager.list.filterToLabel'),
|
||||
fromPlaceholder: this.$tc('aeon-dump-manager.list.filterFromPlaceholder'),
|
||||
toPlaceholder: this.$tc('aeon-dump-manager.list.filterToPlaceholder'),
|
||||
showTimeframe: false,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
columns() {
|
||||
return [
|
||||
{
|
||||
property: 'datetime',
|
||||
dataIndex: 'datetime',
|
||||
label: this.$tc('aeon-dump-manager.list.columnDatetime'),
|
||||
allowResize: true,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
property: 'filename',
|
||||
dataIndex: 'filename',
|
||||
label: this.$tc('aeon-dump-manager.list.columnFilename'),
|
||||
allowResize: true,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
property: 'sizeBytes',
|
||||
dataIndex: 'sizeBytes',
|
||||
label: this.$tc('aeon-dump-manager.list.columnSize'),
|
||||
align: 'right',
|
||||
allowResize: true,
|
||||
sortable: true,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
selectionCount(this: ComponentInstance): number {
|
||||
return Object.keys(this.selection).length;
|
||||
},
|
||||
|
||||
sortedDumps(this: ComponentInstance): DumpFile[] {
|
||||
const direction = this.sortDirection === 'ASC' ? 1 : -1;
|
||||
|
||||
return [...this.dumps].sort((a, b) => {
|
||||
let compareVal: number;
|
||||
|
||||
switch (this.sortBy) {
|
||||
case 'sizeBytes':
|
||||
compareVal = a.sizeBytes - b.sizeBytes;
|
||||
break;
|
||||
case 'datetime':
|
||||
compareVal = new Date(a.datetime).getTime() - new Date(b.datetime).getTime();
|
||||
break;
|
||||
default:
|
||||
compareVal = a.filename.localeCompare(b.filename, undefined, { numeric: true });
|
||||
}
|
||||
|
||||
return compareVal * direction;
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
beforeDestroy(this: ComponentInstance) {
|
||||
this.stopPolling();
|
||||
},
|
||||
|
||||
methods: {
|
||||
getList(this: ComponentInstance): Promise<void> {
|
||||
this.isLoading = true;
|
||||
|
||||
return this.aeonDumpManagerApiService.getList({ from: this.dateFrom, to: this.dateTo })
|
||||
.then((response) => {
|
||||
this.dumps = response.dumps;
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
|
||||
formatDatetime(value: string): string {
|
||||
return Shopware.Utils.format.date(value);
|
||||
},
|
||||
|
||||
onCriteriaChanged(this: ComponentInstance, criteria: DateRangeCriteria[]) {
|
||||
const range = criteria.find((filter) => filter.type === 'range' && filter.field === 'datetime');
|
||||
|
||||
this.dateFrom = range?.parameters?.gte ?? null;
|
||||
this.dateTo = range?.parameters?.lte ?? null;
|
||||
this.getList();
|
||||
},
|
||||
|
||||
formatSize(bytes: number): string {
|
||||
return Shopware.Utils.format.fileSize(bytes);
|
||||
},
|
||||
|
||||
onSelectionChange(this: ComponentInstance, selection: Record<string, DumpFile>) {
|
||||
this.selection = selection;
|
||||
},
|
||||
|
||||
onCreate(this: ComponentInstance) {
|
||||
this.pendingJob = { percent: 0, status: 'pending' };
|
||||
|
||||
this.aeonDumpManagerApiService.create()
|
||||
.then((response) => {
|
||||
this.pollJobStatus(response.jobId);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
// Shown in the progress modal itself, not a notification —
|
||||
// stays open so the user can actually read what went wrong.
|
||||
this.pendingJob = { status: 'failed', percent: null, errorMessage: error.message };
|
||||
});
|
||||
},
|
||||
|
||||
pollJobStatus(this: ComponentInstance, jobId: string) {
|
||||
this.stopPolling();
|
||||
|
||||
this.pollTimer = window.setInterval(() => {
|
||||
this.aeonDumpManagerApiService.getJobStatus(jobId).then((job: DumpJob) => {
|
||||
this.pendingJob = job;
|
||||
|
||||
if (job.status === 'done') {
|
||||
this.stopPolling();
|
||||
this.getList();
|
||||
window.setTimeout(() => {
|
||||
this.pendingJob = null;
|
||||
}, CREATE_MODAL_AUTO_CLOSE_MS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (job.status === 'failed') {
|
||||
this.stopPolling();
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
},
|
||||
|
||||
stopPolling(this: ComponentInstance) {
|
||||
if (this.pollTimer !== null) {
|
||||
window.clearInterval(this.pollTimer);
|
||||
this.pollTimer = null;
|
||||
}
|
||||
},
|
||||
|
||||
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) {
|
||||
this.deleteFilenames = [filename];
|
||||
},
|
||||
|
||||
onRequestBulkDelete(this: ComponentInstance) {
|
||||
this.deleteFilenames = Object.keys(this.selection);
|
||||
},
|
||||
|
||||
onCancelDelete(this: ComponentInstance) {
|
||||
this.deleteFilenames = null;
|
||||
},
|
||||
|
||||
onConfirmDelete(this: ComponentInstance): Promise<void> {
|
||||
const filenames = this.deleteFilenames as string[];
|
||||
this.deleteFilenames = null;
|
||||
|
||||
// Optimistic UI update: pull the rows out immediately rather than
|
||||
// waiting on a full reload, so the grid never looks stale even if
|
||||
// getList() 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.getList())
|
||||
.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.getList();
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -8,14 +8,24 @@
|
||||
"columnFilename": "Name",
|
||||
"columnDatetime": "Erstellt am",
|
||||
"columnSize": "Größe",
|
||||
"filterFromLabel": "Von",
|
||||
"filterFromPlaceholder": "Startdatum auswählen...",
|
||||
"filterToLabel": "Bis",
|
||||
"filterToPlaceholder": "Enddatum auswählen...",
|
||||
"buttonCreate": "Dump erstellen",
|
||||
"buttonDownload": "Herunterladen",
|
||||
"buttonDelete": "Löschen",
|
||||
"bulkDeleteButton": "Auswahl löschen ({count})",
|
||||
"confirmDeleteTitle": "Dump löschen?",
|
||||
"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.",
|
||||
"creating": "Dump wird erstellt…",
|
||||
"progressTitle": "Dump wird erstellt",
|
||||
"progressText": "Dump wird erstellt…",
|
||||
"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}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,24 @@
|
||||
"columnFilename": "Name",
|
||||
"columnDatetime": "Created at",
|
||||
"columnSize": "Size",
|
||||
"filterFromLabel": "From",
|
||||
"filterFromPlaceholder": "Select start date...",
|
||||
"filterToLabel": "To",
|
||||
"filterToPlaceholder": "Select end date...",
|
||||
"buttonCreate": "Create dump",
|
||||
"buttonDownload": "Download",
|
||||
"buttonDelete": "Delete",
|
||||
"bulkDeleteButton": "Delete selected ({count})",
|
||||
"confirmDeleteTitle": "Delete dump?",
|
||||
"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.",
|
||||
"creating": "Creating dump…",
|
||||
"progressTitle": "Creating dump",
|
||||
"progressText": "Creating dump…",
|
||||
"createFailed": "Could not create dump: {error}",
|
||||
"createSuccess": "Dump created."
|
||||
"createSuccess": "Dump created.",
|
||||
"deleteFailed": "Could not delete dump: {error}",
|
||||
"downloadFailed": "Could not download dump: {error}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
const { ApiService } = Shopware.Classes;
|
||||
|
||||
export default class DumpApiService extends ApiService {
|
||||
constructor(httpClient, loginService, apiEndpoint = 'aeon-dump-manager') {
|
||||
super(httpClient, loginService, apiEndpoint);
|
||||
}
|
||||
|
||||
getList() {
|
||||
return this.httpClient
|
||||
.get('/_action/aeon-dump-manager/dumps', { headers: this.getBasicHeaders() })
|
||||
.then((response) => ApiService.handleResponse(response));
|
||||
}
|
||||
|
||||
create() {
|
||||
return this.httpClient
|
||||
.post('/_action/aeon-dump-manager/dumps', {}, { headers: this.getBasicHeaders() })
|
||||
.then((response) => ApiService.handleResponse(response));
|
||||
}
|
||||
|
||||
remove(filename) {
|
||||
return this.httpClient
|
||||
.delete(`/_action/aeon-dump-manager/dumps/${encodeURIComponent(filename)}`, { headers: this.getBasicHeaders() })
|
||||
.then((response) => ApiService.handleResponse(response));
|
||||
}
|
||||
|
||||
getJobStatus(jobId) {
|
||||
return this.httpClient
|
||||
.get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(jobId)}`, { headers: this.getBasicHeaders() })
|
||||
.then((response) => ApiService.handleResponse(response));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
export interface DumpFile {
|
||||
filename: string;
|
||||
datetime: string;
|
||||
sizeBytes: number;
|
||||
}
|
||||
|
||||
export interface DumpList {
|
||||
dumps: DumpFile[];
|
||||
}
|
||||
|
||||
export interface CreateDumpResponse {
|
||||
jobId: string;
|
||||
}
|
||||
|
||||
export type DumpJobStatus = 'pending' | 'running' | 'done' | 'failed';
|
||||
|
||||
export interface DumpJob {
|
||||
id: string;
|
||||
status: DumpJobStatus;
|
||||
percent: number | null;
|
||||
filename: string | null;
|
||||
errorMessage: string | null;
|
||||
}
|
||||
|
||||
// Shopware.Classes.ApiService has no official type package for plugin authors
|
||||
// (per docs/research/admin-dump-manager-ui.md §4) — redeclaring the inherited
|
||||
// member this class actually uses keeps everything below typed without one.
|
||||
// `declare` is required here: a normal field declaration compiles to a real
|
||||
// `this.httpClient = void 0` in the constructor, which runs *after* `super()`
|
||||
// and silently clobbers the value the base class just set.
|
||||
const { ApiService } = Shopware.Classes;
|
||||
|
||||
export default class DumpApiService extends ApiService {
|
||||
protected declare httpClient: {
|
||||
get: (url: string, config?: unknown) => Promise<unknown>;
|
||||
post: (url: string, data: unknown, config?: unknown) => Promise<unknown>;
|
||||
delete: (url: string, config?: unknown) => Promise<unknown>;
|
||||
};
|
||||
|
||||
protected declare getBasicHeaders: (additionalHeaders?: Record<string, string>) => Record<string, string>;
|
||||
|
||||
constructor(httpClient: unknown, loginService: unknown, apiEndpoint = 'aeon-dump-manager') {
|
||||
super(httpClient, loginService, apiEndpoint);
|
||||
}
|
||||
|
||||
getList(filter: { from?: string | null; to?: string | null } = {}): Promise<DumpList> {
|
||||
return this.httpClient
|
||||
.get('/_action/aeon-dump-manager/dumps', {
|
||||
headers: this.getBasicHeaders(),
|
||||
params: { from: filter.from ?? undefined, to: filter.to ?? undefined },
|
||||
})
|
||||
.then((response: unknown) => ApiService.handleResponse(response));
|
||||
}
|
||||
|
||||
create(): Promise<CreateDumpResponse> {
|
||||
return this.httpClient
|
||||
.post('/_action/aeon-dump-manager/dumps', {}, { headers: this.getBasicHeaders() })
|
||||
.then((response: unknown) => ApiService.handleResponse(response));
|
||||
}
|
||||
|
||||
remove(filename: string): Promise<void> {
|
||||
return this.httpClient
|
||||
.delete(`/_action/aeon-dump-manager/dumps/${encodeURIComponent(filename)}`, { headers: this.getBasicHeaders() })
|
||||
.then((response: unknown) => ApiService.handleResponse(response));
|
||||
}
|
||||
|
||||
getJobStatus(jobId: string): Promise<DumpJob> {
|
||||
return this.httpClient
|
||||
.get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(jobId)}`, { headers: this.getBasicHeaders() })
|
||||
.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": false,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"allowJs": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["**/*.ts", "global.d.ts"]
|
||||
}
|
||||
@@ -6,12 +6,12 @@
|
||||
<card>
|
||||
<title>Minimal configuration</title>
|
||||
|
||||
<input-field type="number">
|
||||
<input-field type="int">
|
||||
<name>maxDumps</name>
|
||||
<label>Maximum allowed dumps to exist</label>
|
||||
<defaultValue>6</defaultValue>
|
||||
</input-field>
|
||||
<input-field type="number">
|
||||
<input-field type="int">
|
||||
<name>retantionDays</name>
|
||||
<label>How many Days the dumps kept in the Storage. 0 Means unlimited</label>
|
||||
<defaultValue>0</defaultValue>
|
||||
@@ -19,7 +19,6 @@
|
||||
<input-field type="text">
|
||||
<name>dumpBinaryName</name>
|
||||
<label>Name of the mysqldump/mariadb-dump binary to look up on PATH (e.g. if your distro renamed it). Leave empty to auto-detect.</label>
|
||||
<defaultValue>""</defaultValue>
|
||||
</input-field>
|
||||
</card>
|
||||
|
||||
|
||||
@@ -5,81 +5,82 @@
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<services>
|
||||
|
||||
<!-- Services -->
|
||||
|
||||
<service id="Symfony\Component\Process\ExecutableFinder"/>
|
||||
|
||||
<service id="AeonDumpManager\Service\DumpFilenameParser"/>
|
||||
<service id="aeon_dump_manager.dump_filename_parser" class="AeonDumpManager\Service\DumpFilenameParser"/>
|
||||
|
||||
<service id="AeonDumpManager\Service\DumpBinaryLocator">
|
||||
<service id="aeon_dump_manager.dump_binary_locator" class="AeonDumpManager\Service\DumpBinaryLocator">
|
||||
<argument type="service" id="Doctrine\DBAL\Connection"/>
|
||||
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
|
||||
<argument type="service" id="Symfony\Component\Process\ExecutableFinder"/>
|
||||
</service>
|
||||
|
||||
<service id="AeonDumpManager\Service\DumpJobStatusService">
|
||||
<service id="aeon_dump_manager.dump_job_status_service" class="AeonDumpManager\Service\DumpJobStatusService">
|
||||
<argument type="service" id="Doctrine\DBAL\Connection"/>
|
||||
</service>
|
||||
|
||||
<service id="AeonDumpManager\Service\DumpLister">
|
||||
<service id="aeon_dump_manager.dump_lister" class="AeonDumpManager\Service\DumpLister">
|
||||
<argument type="service" id="aeon_dump_manager.filesystem.private"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpFilenameParser"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_filename_parser"/>
|
||||
</service>
|
||||
|
||||
<service id="AeonDumpManager\Service\DumpService">
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpLister"/>
|
||||
<service id="aeon_dump_manager.dump_service" class="AeonDumpManager\Service\DumpService">
|
||||
<argument type="service" id="aeon_dump_manager.dump_lister"/>
|
||||
<argument type="service" id="aeon_dump_manager.filesystem.private"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpBinaryLocator"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_binary_locator"/>
|
||||
<argument type="service" id="Doctrine\DBAL\Connection"/>
|
||||
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpFilenameParser"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_filename_parser"/>
|
||||
</service>
|
||||
|
||||
<!-- Async create job -->
|
||||
|
||||
<service id="AeonDumpManager\MessageQueue\Handler\CreateDumpHandler">
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpService"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpJobStatusService"/>
|
||||
<service id="aeon_dump_manager.message_queue.create_dump_handler" class="AeonDumpManager\MessageQueue\Handler\CreateDumpHandler">
|
||||
<argument type="service" id="aeon_dump_manager.dump_service"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_job_status_service"/>
|
||||
<tag name="messenger.message_handler"/>
|
||||
</service>
|
||||
|
||||
<!-- Retention -->
|
||||
|
||||
<service id="AeonDumpManager\ScheduledTask\PurgeDumpsTask">
|
||||
<service id="aeon_dump_manager.scheduled_task.purge_dumps_task" class="AeonDumpManager\ScheduledTask\PurgeDumpsTask">
|
||||
<tag name="shopware.scheduled.task"/>
|
||||
</service>
|
||||
|
||||
<service id="AeonDumpManager\ScheduledTask\PurgeDumpsTaskHandler">
|
||||
<service id="aeon_dump_manager.scheduled_task.purge_dumps_task_handler" class="AeonDumpManager\ScheduledTask\PurgeDumpsTaskHandler">
|
||||
<argument type="service" id="scheduled_task.repository"/>
|
||||
<argument type="service" id="logger"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpService"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpJobStatusService"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_service"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_job_status_service"/>
|
||||
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
|
||||
<tag name="messenger.message_handler" handles="AeonDumpManager\ScheduledTask\PurgeDumpsTask"/>
|
||||
</service>
|
||||
|
||||
<!-- Console commands -->
|
||||
|
||||
<service id="AeonDumpManager\Command\DumpListCommand">
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpLister"/>
|
||||
<service id="aeon_dump_manager.command.dump_list" class="AeonDumpManager\Command\DumpListCommand">
|
||||
<argument type="service" id="aeon_dump_manager.dump_lister"/>
|
||||
<tag name="console.command"/>
|
||||
</service>
|
||||
|
||||
<service id="AeonDumpManager\Command\DumpCreateCommand">
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpService"/>
|
||||
<service id="aeon_dump_manager.command.dump_create" class="AeonDumpManager\Command\DumpCreateCommand">
|
||||
<argument type="service" id="aeon_dump_manager.dump_service"/>
|
||||
<tag name="console.command"/>
|
||||
</service>
|
||||
|
||||
<service id="AeonDumpManager\Command\DumpRemoveCommand">
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpService"/>
|
||||
<service id="aeon_dump_manager.command.dump_remove" class="AeonDumpManager\Command\DumpRemoveCommand">
|
||||
<argument type="service" id="aeon_dump_manager.dump_service"/>
|
||||
<tag name="console.command"/>
|
||||
</service>
|
||||
|
||||
<!-- Admin API controller -->
|
||||
|
||||
<service id="AeonDumpManager\Controller\DumpController" public="true">
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpLister"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpService"/>
|
||||
<argument type="service" id="AeonDumpManager\Service\DumpJobStatusService"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_lister"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_service"/>
|
||||
<argument type="service" id="aeon_dump_manager.dump_job_status_service"/>
|
||||
<argument type="service" id="messenger.default_bus"/>
|
||||
</service>
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ class DumpBinaryLocator
|
||||
|
||||
private function isMariaDb(): bool
|
||||
{
|
||||
return MySqlVariant::isMariaDb($this->connection->getServerVersion());
|
||||
// Connection::getServerVersion() is private in the DBAL version this
|
||||
// repo pins against — SELECT VERSION() is the stable public way to get
|
||||
// the same string.
|
||||
return MySqlVariant::isMariaDb((string) $this->connection->fetchOne('SELECT VERSION()'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,23 @@ class DumpService
|
||||
$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
|
||||
{
|
||||
$maxDumps = $this->systemConfigService->getInt('AeonDumpManager.config.maxDumps');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace AeonDumpManager\Tests\Service;
|
||||
|
||||
use AeonDumpManager\Service\DumpFilenameParser;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DumpFilenameParserTest extends TestCase
|
||||
@@ -29,9 +30,7 @@ class DumpFilenameParserTest extends TestCase
|
||||
self::assertEquals($dateTime, $this->parser->parse($filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidFilenameProvider
|
||||
*/
|
||||
#[DataProvider('invalidFilenameProvider')]
|
||||
public function testParseRejectsInvalidFilenames(string $filename): void
|
||||
{
|
||||
self::assertNull($this->parser->parse($filename));
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
namespace AeonDumpManager\Tests\Service;
|
||||
|
||||
use AeonDumpManager\Service\MySqlVariant;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MySqlVariantTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider versionProvider
|
||||
*/
|
||||
#[DataProvider('versionProvider')]
|
||||
public function testIsMariaDb(string $version, bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, MySqlVariant::isMariaDb($version));
|
||||
|
||||
Reference in New Issue
Block a user