Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/src/EventListener/CleanupListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\EventListener;

use App\Event\JobCompletedEvent;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

class CleanupListener
{
public function __construct(
private EntityManagerInterface $entityManager,
private LoggerInterface $logger
)
{
}

#[AsEventListener(event: JobCompletedEvent::class)]
public function onJobCompleted(JobCompletedEvent $event): void
{
// downloadJob has completed, there is no need for the cookies anymore,
// and for privacy reasons, we MUST remove it from the database

$downloadJob = $event->getDownloadJob();
$downloadJob->setCookies(null);
$this->entityManager->persist($downloadJob);
$this->logger->info('Cleaned up cookies for completed job', [
'job_id' => $downloadJob->getId(),
'uri' => $downloadJob->getUri(),
]);
$this->entityManager->flush();
}
}
Loading