Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BO - signalement] Erreur sur l'attribution de désordres liés à la composition du logement #2316

Merged
Show file tree
Hide file tree
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
105 changes: 105 additions & 0 deletions src/Command/UpdateSignalementDesordresCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Command;

use App\Entity\DesordrePrecision;
use App\Entity\Signalement;
use App\Manager\SignalementManager;
use App\Repository\DesordrePrecisionRepository;
use App\Service\Signalement\DesordreTraitement\DesordreCompositionLogementLoader;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'app:update-signalement-desordres',
description: 'Recompute composition desordres for signalement',
)]
class UpdateSignalementDesordresCommand extends Command
{
public function __construct(
private SignalementManager $signalementManager,
private DesordrePrecisionRepository $desordrePrecisionRepository,
private DesordreCompositionLogementLoader $desordreCompositionLogementLoader,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$slugsPrecisions = [
'desordres_type_composition_logement_piece_unique_superficie',
'desordres_type_composition_logement_plusieurs_pieces_aucune_piece_9',
'desordres_type_composition_logement_piece_unique_hauteur',
'desordres_type_composition_logement_plusieurs_pieces_hauteur',
'desordres_type_composition_logement_cuisine_collective_oui',
'desordres_type_composition_logement_cuisine_collective_non',
'desordres_type_composition_logement_douche_collective_oui',
'desordres_type_composition_logement_douche_collective_non',
'desordres_type_composition_logement_wc_collectif_oui',
'desordres_type_composition_logement_wc_collectif_non',
'desordres_type_composition_logement_wc_cuisine_ensemble',
];
$signalements = [];
foreach ($slugsPrecisions as $slugPrecision) {
$signalements = array_merge($signalements, $this->addSignalementsByDesordrePrecisionSlug($slugPrecision));
}

if (empty($signalements)) {
$io->warning('No signalement with one of this desordrePrecision ');

return Command::SUCCESS;
}
$signalements = array_unique($signalements);
hmeneuvrier marked this conversation as resolved.
Show resolved Hide resolved
$io->info(\count($signalements).' signalements with one of this desordrePrecision');

/** @var Signalement $signalement */
foreach ($signalements as $signalement) {
if (null === $signalement->getCreatedFrom()) {
foreach ($signalement->getDesordreCategories() as $desordreCategorie) {
$signalement->removeDesordreCategory($desordreCategorie);
}
foreach ($signalement->getDesordreCriteres() as $desordreCritere) {
$signalement->removeDesordreCritere($desordreCritere);
}
foreach ($signalement->getDesordrePrecisions() as $desordrePrecision) {
$signalement->removeDesordrePrecision($desordrePrecision);
}
} else {
$this->desordreCompositionLogementLoader->load(
$signalement,
$signalement->getTypeCompositionLogement()
);
}

$this->signalementManager->persist($signalement);

$io->success(sprintf(
'Signalement %s updated.%sNb desordrePrecisions : %sNb desordreCriteres: %sNb desordreCategories: %s',
$signalement->getUuid(),
\PHP_EOL,
\count($signalement->getDesordrePrecisions()).\PHP_EOL,
\count($signalement->getDesordreCriteres()).\PHP_EOL,
\count($signalement->getDesordreCategories()).\PHP_EOL,
));
}

$this->signalementManager->flush();

return Command::SUCCESS;
}

private function addSignalementsByDesordrePrecisionSlug(string $desordrePrecisionSlug): array
{
/** @var DesordrePrecision $desordrePrecision */
$desordrePrecision = $this->desordrePrecisionRepository->findOneBy(
['desordrePrecisionSlug' => $desordrePrecisionSlug]
);

return $desordrePrecision->getSignalement()->toArray();
}
}
2 changes: 1 addition & 1 deletion src/Entity/Signalement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,7 @@ public function removeDesordrePrecision(DesordrePrecision $desordrePrecision): s

public function __toString(): string
{
return $this->reference;
return $this->reference.' : '.$this->uuid;
}

public function hasQualificaton(Qualification $qualification): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public function load(
TypeCompositionLogement $typeCompositionLogement,
): void {
$this->signalement = $signalement;
if (null === $this->signalement->getCreatedFrom()) {
return;
}
if ('oui' === $typeCompositionLogement->getTypeLogementSousCombleSansFenetre()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_sous_combles',
Expand Down Expand Up @@ -61,7 +64,7 @@ public function load(
'desordres_type_composition_logement_piece_unique_superficie'
);
}
if ('oui' !== $typeCompositionLogement->getCompositionLogementHauteur()) {
if ('non' === $typeCompositionLogement->getCompositionLogementHauteur()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_piece_unique',
'desordres_type_composition_logement_piece_unique_hauteur'
Expand All @@ -73,7 +76,7 @@ public function load(
);
}
} else {
if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesPieceAVivre9m()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesPieceAVivre9m()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_plusieurs_pieces',
'desordres_type_composition_logement_plusieurs_pieces_aucune_piece_9'
Expand All @@ -84,7 +87,7 @@ public function load(
'desordres_type_composition_logement_plusieurs_pieces_aucune_piece_9'
);
}
if ('oui' !== $typeCompositionLogement->getCompositionLogementHauteur()) {
if ('non' === $typeCompositionLogement->getCompositionLogementHauteur()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_plusieurs_pieces',
'desordres_type_composition_logement_plusieurs_pieces_hauteur'
Expand All @@ -97,8 +100,8 @@ public function load(
}
}

if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesCuisine()) {
if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesCuisineCollective()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesCuisine()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesCuisineCollective()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_cuisine',
'desordres_type_composition_logement_cuisine_collective_non'
Expand All @@ -120,8 +123,8 @@ public function load(
);
}

if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesSalleDeBain()) {
if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesSalleDeBainCollective()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesSalleDeBain()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesSalleDeBainCollective()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_douche',
'desordres_type_composition_logement_douche_collective_non'
Expand All @@ -143,8 +146,8 @@ public function load(
);
}

if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesWc()) {
if ('oui' !== $typeCompositionLogement->getTypeLogementCommoditesWcCollective()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesWc()) {
if ('non' === $typeCompositionLogement->getTypeLogementCommoditesWcCollective()) {
$this->addDesordreCriterePrecisionBySlugs(
'desordres_type_composition_logement_wc',
'desordres_type_composition_logement_wc_collectif_non'
Expand Down
Loading