mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: add columns into Address to track the matching with AddressReference
This commit is contained in:
parent
efa475df0f
commit
8e0d144dd1
@ -12,6 +12,10 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
@ -28,8 +32,28 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
* @ORM\Table(name="chill_main_address")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class Address
|
||||
class Address implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
use TrackCreationTrait;
|
||||
use TrackUpdateTrait;
|
||||
|
||||
/**
|
||||
* When an Address does match with the AddressReference
|
||||
*/
|
||||
public const ADDR_REFERENCE_STATUS_MATCH = 'match';
|
||||
|
||||
/**
|
||||
* When an Address does not match with the AddressReference, and
|
||||
* is pending for a review
|
||||
*/
|
||||
public const ADDR_REFERENCE_STATUS_TO_REVIEW = 'to_review';
|
||||
|
||||
/**
|
||||
* When an Address does not match with the AddressReference, but
|
||||
* is reviewed
|
||||
*/
|
||||
public const ADDR_REFERENCE_STATUS_REVIEWED = 'reviewed';
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=AddressReference::class)
|
||||
* @Groups({"write"})
|
||||
@ -42,7 +66,7 @@ class Address
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $buildingName;
|
||||
private string $buildingName = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
@ -165,6 +189,17 @@ class Address
|
||||
*/
|
||||
private ?PostalCode $postcode = null;
|
||||
|
||||
/**
|
||||
* @var self::ADDR_REFERENCE_STATUS_*
|
||||
* @ORM\Column(type="text", nullable=false, options={"default": self::ADDR_REFERENCE_STATUS_MATCH})
|
||||
*/
|
||||
private string $refStatus = self::ADDR_REFERENCE_STATUS_MATCH;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime_immutable", nullable=false, options={"default": "CURRENT_TIMESTAMP"})
|
||||
*/
|
||||
private \DateTimeImmutable $refStatusLastUpdate;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*
|
||||
@ -210,6 +245,7 @@ class Address
|
||||
public function __construct()
|
||||
{
|
||||
$this->validFrom = new DateTime();
|
||||
$this->refStatusLastUpdate = new \DateTimeImmutable('now');
|
||||
$this->geographicalUnits = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20230306142148 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add columns refStatus and refStatusLastUpdate to Address';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD refStatus TEXT DEFAULT \'match\' NOT NULL');
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD refStatusLastUpdate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL');
|
||||
|
||||
// we must set the last status update to the address reference date to avoid inconsistencies
|
||||
$this->addSql('UPDATE chill_main_address a SET refStatusLastUpdate = COALESCE(r.updatedat, r.createdat, \'1970-01-01\'::timestamp) FROM chill_main_address_reference r WHERE a.addressreference_id = r.id');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address DROP refStatus');
|
||||
$this->addSql('ALTER TABLE chill_main_address DROP refStatusLastUpdate');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user