BackupRestoreController.php
- Pfad:
src/Controller/BackupRestoreController.php - Namespace: Controller
- Zeilen: 132 | Größe: 3,497 Bytes
- Geändert: 2025-12-27 12:54:21 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 4
- extends Framework\Controller
- constructor Domain\Repository\FileBackupRepositoryInterface
- use Domain\Repository\FileBackupRepositoryInterface
- use Framework\Controller
Klassen 1
-
BackupRestoreControllerclass Zeile 12
Funktionen 5
-
__construct()public Zeile 16 -
index()public Zeile 25 -
show()public Zeile 59 -
restore()public Zeile 89 -
downloadBackup()public Zeile 120
Versionen 11
-
v11
2025-12-27 12:54 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-25 12:51 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-23 07:53 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-23 04:50 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-23 04:45 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-23 04:39 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-23 04:24 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-22 08:05 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 01:46 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-22 01:46 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-20 19:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Controller;
// @responsibility: HTTP-Endpunkte für Datei-Backup und -Wiederherstellung
use Domain\Repository\FileBackupRepositoryInterface;
use Framework\Controller;
class BackupRestoreController extends Controller
{
private FileBackupRepositoryInterface $repository;
public function __construct(FileBackupRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* GET /backup-restore
* List all backups.
*/
public function index(): void
{
$filters = [];
$search = $this->getString('search');
if ($search !== '') {
$filters['search'] = $search;
}
$changeType = $this->getString('change_type');
if ($changeType !== '') {
$filters['change_type'] = $changeType;
}
$limit = 50;
$offset = $this->getInt('offset');
$backups = $this->repository->findAll($filters, $limit, $offset);
$total = $this->repository->count($filters);
$stats = $this->repository->getStatistics();
$this->view('backup-restore.index', [
'title' => 'File Backup',
'backups' => $backups,
'stats' => $stats,
'total' => $total,
'filters' => $filters,
]);
}
/**
* GET /backup-restore/{id}
* Show backup details.
*/
public function show(string $id): void
{
$backup = $this->repository->findById((int) $id);
if ($backup === null) {
$this->notFound('Backup nicht gefunden');
}
// Get content preview (max 500 lines)
$contentPreview = $this->repository->getContentPreview((int) $id, 500);
// Get other versions of this file
$versions = $this->repository->findByFilePath($backup['file_path']);
// Check if file currently exists
$fileExists = file_exists($backup['file_path']);
$this->view('backup-restore.show', [
'title' => 'Backup #' . $id,
'backup' => $backup,
'contentPreview' => $contentPreview,
'versions' => $versions,
'fileExists' => $fileExists,
]);
}
/**
* POST /backup-restore/{id}/restore
* Restore file from backup.
*/
public function restore(string $id): void
{
$this->requireCsrf();
$isHtmx = $this->isHtmxRequest();
try {
$this->repository->restore((int) $id);
if ($isHtmx) {
$this->htmxRedirect('/backup-restore/' . $id . '?restored=1');
return;
}
$this->redirect('/backup-restore/' . $id . '?restored=1');
} catch (\RuntimeException $e) {
if ($isHtmx) {
$this->htmxError($e->getMessage());
return;
}
$this->redirect('/backup-restore/' . $id . '?error=' . urlencode($e->getMessage()));
}
}
/**
* GET /backup-restore/{id}/download
* Download full backup content as file.
*/
public function downloadBackup(string $id): void
{
$backup = $this->repository->findById((int) $id);
if ($backup === null) {
$this->notFound('Backup nicht gefunden');
}
$filename = basename($backup['file_path']) . '.backup-v' . $backup['version'];
$this->download($backup['file_content'], $filename, 'text/plain');
}
}