Backup #1267

ID1267
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/BackupRestoreController.php
Version10
Typ modified
Größe3.2 KB
Hash42f4333f8b23f541ef5932492458338e6ad2f6a879ce3da26bd5b410a2f10d13
Datum2025-12-25 12:51:39
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

declare(strict_types=1);

namespace Controller;

// @responsibility: HTTP-Endpunkte für Datei-Backup und -Wiederherstellung

use Framework\Controller;
use Infrastructure\Persistence\FileBackupRepository;

class BackupRestoreController extends Controller
{
    private FileBackupRepository $repository;

    public function __construct(FileBackupRepository $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();

        try {
            $this->repository->restore((int) $id);

            // Redirect with success message
            header('Location: /backup-restore/' . $id . '?restored=1');
        } catch (\RuntimeException $e) {
            // Redirect with error message
            header('Location: /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');
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
1766 11 modified 3.2 KB 2025-12-27 12:54
1267 10 modified 3.2 KB 2025-12-25 12:51
696 9 modified 3.2 KB 2025-12-23 07:53
657 8 modified 3.2 KB 2025-12-23 04:50
634 7 modified 3.3 KB 2025-12-23 04:45
606 6 modified 3.4 KB 2025-12-23 04:39
588 5 modified 3.3 KB 2025-12-23 04:24
308 4 modified 3.3 KB 2025-12-22 08:05
245 3 modified 3.4 KB 2025-12-22 01:46
244 2 modified 3.4 KB 2025-12-22 01:46
103 1 modified 3.4 KB 2025-12-20 19:19

← Zurück zur Übersicht