Handles Patch (persist + sync + recurrence check) and Delete (remove + cleanup Zimbra events). Updates TaskNumberProcessor to sync newly created tasks to calendar. Wires TaskCalendarProcessor as processor for Patch/Delete on Task entity. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\Metadata\Post;
|
|
use ApiPlatform\State\ProcessorInterface;
|
|
use App\Entity\Task;
|
|
use App\Repository\TaskRepository;
|
|
use App\Service\CalDavService;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
|
|
/**
|
|
* @implements ProcessorInterface<Task, Task>
|
|
*/
|
|
final readonly class TaskNumberProcessor implements ProcessorInterface
|
|
{
|
|
/**
|
|
* @param ProcessorInterface<Task, Task> $persistProcessor
|
|
*/
|
|
public function __construct(
|
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
|
private ProcessorInterface $persistProcessor,
|
|
private TaskRepository $taskRepository,
|
|
private EntityManagerInterface $entityManager,
|
|
private CalDavService $calDavService,
|
|
) {}
|
|
|
|
/**
|
|
* @param Task $data
|
|
*/
|
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
|
{
|
|
if ($operation instanceof Post && null !== $data->getProject()) {
|
|
$result = $this->entityManager->wrapInTransaction(function () use ($data, $operation, $uriVariables, $context) {
|
|
$maxNumber = $this->taskRepository->findMaxNumberByProjectForUpdate($data->getProject());
|
|
$data->setNumber($maxNumber + 1);
|
|
|
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
|
});
|
|
|
|
$this->calDavService->syncTask($data);
|
|
$this->entityManager->flush();
|
|
|
|
return $result;
|
|
}
|
|
|
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
|
}
|
|
}
|