Files
SIRH/src/State/MileageAllowanceDeleteProcessor.php
tristan 17f871e82d
All checks were successful
Auto Tag Develop / tag (push) Successful in 8s
feat : modification écran RTT + modification écran frais
2026-03-19 17:10:11 +01:00

53 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\MileageAllowance;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
final readonly class MileageAllowanceDeleteProcessor implements ProcessorInterface
{
public function __construct(
private EntityManagerInterface $entityManager,
#[Autowire('%kernel.project_dir%/var/uploads')]
private string $uploadDir,
) {}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): null
{
if (!$data instanceof MileageAllowance) {
return null;
}
$receiptPath = $data->getReceiptPath();
if (null !== $receiptPath) {
$absolutePath = sprintf('%s/%s', $this->uploadDir, $receiptPath);
if (file_exists($absolutePath)) {
unlink($absolutePath);
}
}
$amountReceiptPath = $data->getAmountReceiptPath();
if (null !== $amountReceiptPath) {
$absolutePath = sprintf('%s/%s', $this->uploadDir, $amountReceiptPath);
if (file_exists($absolutePath)) {
unlink($absolutePath);
}
}
$this->entityManager->remove($data);
$this->entityManager->flush();
return null;
}
}