Skip to content

Commit

Permalink
remove useless call #3610
Browse files Browse the repository at this point in the history
  • Loading branch information
emilschn committed Jan 28, 2025
1 parent 2eb47e8 commit 042a987
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
19 changes: 0 additions & 19 deletions src/Command/ImportSignalementCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
namespace App\Command;

use App\Entity\Territory;
use App\EventListener\ActivityListener;
use App\Service\Import\CsvParser;
use App\Service\Import\Signalement\SignalementImportLoader;
use App\Service\UploadHandlerService;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\ORM\NonUniqueResultException;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
Expand Down Expand Up @@ -57,8 +55,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

$this->removeEventListener();

$fromFile = 'csv/signalement_'.$territoryZip.'.csv';
$toFile = $this->parameterBag->get('uploads_tmp_dir').'signalement.csv';
if (!$this->fileStorage->fileExists($fromFile)) {
Expand Down Expand Up @@ -107,19 +103,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Command::SUCCESS;
}

private function removeEventListener(): void
{
$eventManager = $this->entityManager->getEventManager();

$eventsToCheck = [Events::onFlush, Events::preRemove];

foreach ($eventsToCheck as $event) {
foreach ($eventManager->getListeners($event) as $listener) {
if ($listener instanceof ActivityListener) {
$eventManager->removeEventListener([$event], $listener);
}
}
}
}
}
9 changes: 1 addition & 8 deletions src/Service/NotificationAndMailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Entity\Affectation;
use App\Entity\Enum\AffectationStatus;
use App\Entity\Notification;
use App\Entity\Partner;
use App\Entity\Signalement;
use App\Entity\Suivi;
Expand All @@ -23,7 +22,6 @@

class NotificationAndMailSender
{
private $unitOfWork;
private Signalement $signalement;
private ?Suivi $suivi;
private ?Affectation $affectation;
Expand All @@ -37,7 +35,6 @@ public function __construct(
private readonly ParameterBagInterface $parameterBag,
private readonly Security $security,
) {
$this->unitOfWork = $this->entityManager->getUnitOfWork();
$this->suivi = null;
}

Expand Down Expand Up @@ -66,7 +63,7 @@ public function sendNewSuiviToAdminsAndPartners(Suivi $suivi): void
$this->signalement = $suivi->getSignalement();
$territory = $this->signalement->getTerritory();
$recipients = $this->getRecipientsAdmin($territory);

foreach ($this->signalement->getAffectations() as $affectation) {
if (AffectationStatus::STATUS_WAIT->value === $affectation->getStatut()
|| AffectationStatus::STATUS_ACCEPTED->value === $affectation->getStatut()) {
Expand Down Expand Up @@ -127,10 +124,6 @@ private function createInAppNotification($user): void

$notification = $this->notificationFactory->createInstanceFrom($user, $this->suivi);
$this->entityManager->persist($notification);
$this->unitOfWork->computeChangeSet(
$this->entityManager->getClassMetadata(Notification::class),
$notification
);
}

private function sendMail(ArrayCollection $recipients, NotificationMailerType $mailType): void
Expand Down
4 changes: 4 additions & 0 deletions tests/Functional/Manager/SuiviManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\User\UserInterface;
Expand All @@ -22,6 +23,7 @@ class SuiviManagerTest extends KernelTestCase
private const REF_SIGNALEMENT = '2022-8';
private ManagerRegistry $managerRegistry;
private SignalementUpdatedListener $signalementUpdatedListener;
private EventDispatcherInterface $eventDispatcherInterface;
private Security $security;
private UrlGeneratorInterface $urlGenerator;
private DesordreCritereRepository $desordreCritereRepository;
Expand All @@ -33,6 +35,7 @@ protected function setUp(): void
self::bootKernel();
$this->managerRegistry = self::getContainer()->get(ManagerRegistry::class);
$this->signalementUpdatedListener = static::getContainer()->get(SignalementUpdatedListener::class);
$this->eventDispatcherInterface = static::getContainer()->get(EventDispatcherInterface::class);
$this->security = static::getContainer()->get(Security::class);
$this->urlGenerator = static::getContainer()->get(UrlGeneratorInterface::class);
$this->desordreCritereRepository = static::getContainer()->get(DesordreCritereRepository::class);
Expand All @@ -41,6 +44,7 @@ protected function setUp(): void
$this->managerRegistry,
$this->urlGenerator,
$this->signalementUpdatedListener,
$this->eventDispatcherInterface,
$this->security,
$this->desordreCritereRepository,
$this->htmlSanitizerInterface,
Expand Down

0 comments on commit 042a987

Please sign in to comment.