Backup #825

ID825
Dateipfad/var/www/dev.campus.systemische-tools.de/src/UseCases/Task/DeleteTaskUseCase.php
Version2
Typ modified
Größe1.5 KB
Hash393b6cc255d9c1ff7a73332e7d1d6df20bb43f94aeb16687ec403db154de6fd0
Datum2025-12-23 08:14:56
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

declare(strict_types=1);

namespace UseCases\Task;

// @responsibility: Löscht Tasks nach Validierung der Subtask-Abhängigkeiten

use Infrastructure\Persistence\TaskRepository;

class DeleteTaskUseCase
{
    private TaskRepository $taskRepository;

    public function __construct(?TaskRepository $taskRepository = null)
    {
        $this->taskRepository = $taskRepository ?? new TaskRepository();
    }

    public function execute(int $taskId): bool
    {
        $task = $this->taskRepository->find($taskId);
        if ($task === null) {
            throw new \InvalidArgumentException("Task {$taskId} not found");
        }

        $subtasks = $this->taskRepository->findSubtasks($taskId);
        if (count($subtasks) > 0) {
            throw new \InvalidArgumentException(
                'Cannot delete task with subtasks. Delete subtasks first or use cascade delete.'
            );
        }

        return $this->taskRepository->delete($taskId);
    }

    public function executeCascade(int $taskId): int
    {
        $task = $this->taskRepository->find($taskId);
        if ($task === null) {
            throw new \InvalidArgumentException("Task {$taskId} not found");
        }

        $deleted = 0;

        $subtasks = $this->taskRepository->findSubtasks($taskId);
        foreach ($subtasks as $subtask) {
            $deleted += $this->executeCascade($subtask->getId());
        }

        $this->taskRepository->delete($taskId);
        $deleted++;

        return $deleted;
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
825 2 modified 1.5 KB 2025-12-23 08:14
707 1 modified 1.4 KB 2025-12-23 07:54

← Zurück zur Übersicht