Fix: force the consistency of location in accompanying period

- internally, the entity remove the addressLocation when the
  personLocation is set, and vice-versa;
- this commit add a migration which may solve the case when both case
  happens (priority to personLocation + keep the history)
- add a constraint on the database to avoid such situation
This commit is contained in:
2023-06-29 12:44:28 +02:00
parent 90e8687799
commit 347eda05df
5 changed files with 85 additions and 8 deletions

View File

@@ -786,7 +786,7 @@ class AccompanyingPeriod implements
}
/**
* @return Collection|AccompanyingPeriodLocationHistory[]
* @return Collection<AccompanyingPeriodLocationHistory>
*/
public function getLocationHistories(): Collection
{
@@ -797,6 +797,7 @@ class AccompanyingPeriod implements
* Get where the location is.
*
* @Groups({"read"})
* @return 'person'|'address'|'none'
*/
public function getLocationStatus(): string
{
@@ -1209,6 +1210,7 @@ class AccompanyingPeriod implements
$this->addressLocation = $addressLocation;
if (null !== $addressLocation) {
$this->setPersonLocation(null);
$locationHistory = new AccompanyingPeriodLocationHistory();
$locationHistory
->setStartDate(new DateTimeImmutable('now'))
@@ -1327,6 +1329,7 @@ class AccompanyingPeriod implements
$this->personLocation = $person;
if (null !== $person) {
$this->setAddressLocation(null);
$locationHistory = new AccompanyingPeriodLocationHistory();
$locationHistory
->setStartDate(new DateTimeImmutable('now'))