-
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.
- Loading branch information
Showing
9 changed files
with
148 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241004142515 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add unique index on created_from_id column in signalement table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$queryDuplicates = ' | ||
SELECT id, created_from_id, statut | ||
FROM signalement | ||
WHERE created_from_id IN ( | ||
SELECT created_from_id | ||
FROM signalement | ||
GROUP BY created_from_id | ||
HAVING COUNT(*) > 1 | ||
) | ||
ORDER BY created_from_id ASC, statut desc | ||
'; | ||
$list = $this->connection->fetchAllAssociative($queryDuplicates); | ||
$createdFrom = 0; | ||
$lastId = 0; | ||
foreach ($list as $item) { | ||
// lorsqu'on a parcouru tous les doublons pour un même draft on garde uniquement le dernier de la liste (correspondant au statut le plus bas) | ||
if ($createdFrom !== $item['created_from_id']) { | ||
$this->keepSingleSignalementWithCreatedFrom($createdFrom, $lastId); | ||
$createdFrom = $item['created_from_id']; | ||
} | ||
$lastId = $item['id']; | ||
} | ||
$this->keepSingleSignalementWithCreatedFrom($createdFrom, $lastId); | ||
$this->addSql('ALTER TABLE signalement DROP INDEX IDX_F4B551143EA4CB4D, ADD UNIQUE INDEX UNIQ_F4B551143EA4CB4D (created_from_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE signalement DROP INDEX UNIQ_F4B551143EA4CB4D, ADD INDEX IDX_F4B551143EA4CB4D (created_from_id)'); | ||
} | ||
|
||
private function keepSingleSignalementWithCreatedFrom(int $createdFrom, int $lastId): void | ||
{ | ||
$this->addSql('UPDATE signalement SET created_from_id = NULL WHERE created_from_id = :created_from_id AND id != :id', [ | ||
'created_from_id' => $createdFrom, | ||
'id' => $lastId, | ||
]); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ signalements_draft: | |
profile_declarant: 'LOCATAIRE' | ||
email_declarant: '[email protected]' | ||
payload: 'locataire_all_in.json' | ||
status: 'EN_SIGNALEMENT' | ||
- | ||
uuid: '00000000-0000-0000-2023-bailleuroc01' | ||
profile_declarant: 'BAILLEUR_OCCUPANT' | ||
|
@@ -79,3 +80,15 @@ signalements_draft: | |
email_declarant: '[email protected]' | ||
payload: 'step/validation_signalement/service_secours.json' | ||
created_at_period: '-7 months' | ||
- | ||
uuid: '00000000-0000-0000-2024-bailleuroc01' | ||
profile_declarant: 'BAILLEUR_OCCUPANT' | ||
email_declarant: '[email protected]' | ||
payload: 'bailleur_occupant.json' | ||
status: 'EN_SIGNALEMENT' | ||
- | ||
uuid: '00000000-0000-0000-2024-bailleuroc02' | ||
profile_declarant: 'BAILLEUR_OCCUPANT' | ||
email_declarant: '[email protected]' | ||
payload: 'bailleur_occupant.json' | ||
status: 'EN_SIGNALEMENT' |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
use App\Factory\SignalementDraftFactory; | ||
use App\Manager\SignalementDraftManager; | ||
use App\Repository\SignalementDraftRepository; | ||
use App\Repository\SignalementRepository; | ||
use App\Serializer\SignalementDraftRequestSerializer; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
@@ -27,6 +28,7 @@ class SignalementDraftManagerTest extends WebTestCase | |
private UrlGeneratorInterface $urlGenerator; | ||
private SignalementDraftRequestSerializer $signalementDraftRequestSerializer; | ||
private SignalementDraftRepository $signalementDraftRepository; | ||
private SignalementRepository $signalementRepository; | ||
|
||
protected function setUp(): void | ||
{ | ||
|
@@ -38,6 +40,7 @@ protected function setUp(): void | |
$this->urlGenerator = static::getContainer()->get(UrlGeneratorInterface::class); | ||
$this->signalementDraftRequestSerializer = static::getContainer()->get(SignalementDraftRequestSerializer::class); | ||
$this->signalementDraftRepository = static::getContainer()->get(SignalementDraftRepository::class); | ||
$this->signalementRepository = static::getContainer()->get(SignalementRepository::class); | ||
|
||
$this->signalementDraftManager = new SignalementDraftManager( | ||
$this->signalementDraftFactory, | ||
|
@@ -46,6 +49,7 @@ protected function setUp(): void | |
$this->urlGenerator, | ||
$this->signalementDraftRequestSerializer, | ||
$this->signalementDraftRepository, | ||
$this->signalementRepository, | ||
); | ||
|
||
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => '[email protected]']); | ||
|