-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3345 from MTES-MCT/feature/3322-command-init-ban-id
[Signalement] Enregistrement de l'identifiant BAN
- Loading branch information
Showing
18 changed files
with
214 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241125151642 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'add ban_id_occupant to signalement table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE signalement ADD ban_id_occupant VARCHAR(50) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE signalement DROP ban_id_occupant'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Entity\Signalement; | ||
use App\Manager\HistoryEntryManager; | ||
use App\Manager\SignalementManager; | ||
use App\Repository\SignalementRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
#[AsCommand( | ||
name: 'app:init-id-ban', | ||
description: 'Search BAN ID when missing in Adresse Occupant of Signalement', | ||
)] | ||
class InitIdBanCommand extends Command | ||
{ | ||
private const int BATCH_SIZE = 20; | ||
|
||
public function __construct( | ||
private readonly SignalementManager $signalementManager, | ||
private readonly SignalementRepository $signalementRepository, | ||
private readonly EntityManagerInterface $entityManager, | ||
private readonly HistoryEntryManager $historyEntryManager, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->historyEntryManager->removeEntityListeners(); | ||
|
||
$io = new SymfonyStyle($input, $output); | ||
|
||
$signalementIdsWithouBanId = $this->signalementRepository->findNullBanId(); | ||
$nbSignalementWithoutBanId = \count($signalementIdsWithouBanId); | ||
|
||
$nb = 0; | ||
$progressBar = new ProgressBar($output, $nbSignalementWithoutBanId); | ||
$progressBar->start(); | ||
|
||
$nbBatch = ceil($nbSignalementWithoutBanId / self::BATCH_SIZE); | ||
for ($i = 0; $i < $nbBatch; ++$i) { | ||
$signalementsBatch = array_splice($signalementIdsWithouBanId, 0, self::BATCH_SIZE); | ||
$signalementsIdsBatch = []; | ||
foreach ($signalementsBatch as $signalementBatch) { | ||
$signalementsIdsBatch[] = $signalementBatch['id']; | ||
} | ||
$listSignalementBanIdNull = $this->signalementRepository->findBy(['id' => $signalementsIdsBatch]); | ||
|
||
/** @var Signalement $signalement */ | ||
foreach ($listSignalementBanIdNull as $signalement) { | ||
$this->signalementManager->updateAddressOccupantFromBanData( | ||
signalement: $signalement, | ||
updateGeoloc: false, | ||
); | ||
if (!empty($signalement->getBanIdOccupant())) { | ||
++$nb; | ||
} | ||
$progressBar->advance(); | ||
} | ||
$this->entityManager->flush(); | ||
} | ||
|
||
$progressBar->finish(); | ||
$nbSignalementWithoutBanId = $this->signalementRepository->count(['banIdOccupant' => '0']); | ||
$io->success(\sprintf( | ||
'%s BAN IDs have been initialized, but %s signalements remain with no BAN ID', | ||
$nb, | ||
$nbSignalementWithoutBanId | ||
)); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.