mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46:13 +00:00
Merge branch 'issue520_reference_address_update' into 'master'
Add new fields to AddressReference for update procedure See merge request Chill-Projet/chill-bundles!395
This commit is contained in:
commit
66c7504b22
@ -76,7 +76,8 @@ final class AddressReferenceAPIController extends ApiController
|
|||||||
protected function customizeQuery(string $action, Request $request, $qb): void
|
protected function customizeQuery(string $action, Request $request, $qb): void
|
||||||
{
|
{
|
||||||
if ($request->query->has('postal_code')) {
|
if ($request->query->has('postal_code')) {
|
||||||
$qb->where('e.postcode = :postal_code')
|
$qb->where($qb->expr()->isNull('e.deletedAt'))
|
||||||
|
->andWhere('e.postcode = :postal_code')
|
||||||
->setParameter('postal_code', $request->query->get('postal_code'));
|
->setParameter('postal_code', $request->query->get('postal_code'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,14 @@ declare(strict_types=1);
|
|||||||
namespace Chill\MainBundle\Entity;
|
namespace Chill\MainBundle\Entity;
|
||||||
|
|
||||||
use Chill\MainBundle\Doctrine\Model\Point;
|
use Chill\MainBundle\Doctrine\Model\Point;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_main_address_reference", indexes={
|
* @ORM\Table(name="chill_main_address_reference", indexes={
|
||||||
* @ORM\Index(name="address_refid", columns={"refId"}, options={"where": "refid != ''"})
|
* @ORM\Index(name="address_refid", columns={"refId"})
|
||||||
* })
|
* })
|
||||||
* @ORM\HasLifecycleCallbacks
|
* @ORM\HasLifecycleCallbacks
|
||||||
*/
|
*/
|
||||||
@ -33,6 +34,18 @@ class AddressReference
|
|||||||
*/
|
*/
|
||||||
private string $addressCanonical = '';
|
private string $addressCanonical = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime_immutable", nullable=true)
|
||||||
|
* @groups({"read"})
|
||||||
|
*/
|
||||||
|
private ?DateTimeImmutable $createdAt = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime_immutable", nullable=true)
|
||||||
|
* @groups({"read"})
|
||||||
|
*/
|
||||||
|
private ?DateTimeImmutable $deletedAt = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
@ -89,6 +102,22 @@ class AddressReference
|
|||||||
*/
|
*/
|
||||||
private $streetNumber;
|
private $streetNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime_immutable", nullable=true)
|
||||||
|
* @groups({"read"})
|
||||||
|
*/
|
||||||
|
private ?DateTimeImmutable $updatedAt = null;
|
||||||
|
|
||||||
|
public function getCreatedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeletedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->deletedAt;
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -134,6 +163,25 @@ class AddressReference
|
|||||||
return $this->streetNumber;
|
return $this->streetNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt(?DateTimeImmutable $createdAt): self
|
||||||
|
{
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeletedAt(?DateTimeImmutable $deletedAt): self
|
||||||
|
{
|
||||||
|
$this->deletedAt = $deletedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setMunicipalityCode(?string $municipalityCode): self
|
public function setMunicipalityCode(?string $municipalityCode): self
|
||||||
{
|
{
|
||||||
$this->municipalityCode = $municipalityCode;
|
$this->municipalityCode = $municipalityCode;
|
||||||
@ -189,4 +237,11 @@ class AddressReference
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
|
||||||
|
{
|
||||||
|
$this->updatedAt = $updatedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,12 +130,13 @@ final class AddressReferenceRepository implements ObjectRepository
|
|||||||
|
|
||||||
$query
|
$query
|
||||||
->setFromClause('chill_main_address_reference cma')
|
->setFromClause('chill_main_address_reference cma')
|
||||||
->andWhereClause('postcode_id = ?', [$postalCode->getId()]);
|
->andWhereClause('postcode_id = ?', [$postalCode->getId()])
|
||||||
|
->andWhereClause('deletedAt IS NULL', []);
|
||||||
|
|
||||||
$pertinenceClause = ['STRICT_WORD_SIMILARITY(addresscanonical, UNACCENT(?))'];
|
$pertinenceClause = ['STRICT_WORD_SIMILARITY(addresscanonical, UNACCENT(?))'];
|
||||||
$pertinenceArgs = [$pattern];
|
$pertinenceArgs = [$pattern];
|
||||||
$orWhere = ['addresscanonical %>> UNACCENT(?)'];
|
$andWhere = [];
|
||||||
$orWhereArgs = [$pattern];
|
$andWhereArgs = [];
|
||||||
|
|
||||||
foreach (explode(' ', $pattern) as $part) {
|
foreach (explode(' ', $pattern) as $part) {
|
||||||
$part = trim($part);
|
$part = trim($part);
|
||||||
@ -144,8 +145,8 @@ final class AddressReferenceRepository implements ObjectRepository
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$orWhere[] = "addresscanonical LIKE '%' || UNACCENT(LOWER(?)) || '%'";
|
$andWhere[] = "(addresscanonical LIKE '%' || UNACCENT(LOWER(?)) || '%')";
|
||||||
$orWhereArgs[] = $part;
|
$andWhereArgs[] = $part;
|
||||||
$pertinenceClause[] =
|
$pertinenceClause[] =
|
||||||
"(EXISTS (SELECT 1 FROM unnest(string_to_array(addresscanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int";
|
"(EXISTS (SELECT 1 FROM unnest(string_to_array(addresscanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int";
|
||||||
$pertinenceClause[] =
|
$pertinenceClause[] =
|
||||||
@ -154,7 +155,7 @@ final class AddressReferenceRepository implements ObjectRepository
|
|||||||
}
|
}
|
||||||
$query
|
$query
|
||||||
->setSelectPertinence(implode(' + ', $pertinenceClause), $pertinenceArgs)
|
->setSelectPertinence(implode(' + ', $pertinenceClause), $pertinenceArgs)
|
||||||
->andWhereClause(implode(' OR ', $orWhere), $orWhereArgs);
|
->andWhereClause(implode(' AND ', $andWhere), $andWhereArgs);
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add 3 fields on AddressReference.
|
||||||
|
*/
|
||||||
|
final class Version20220325134944 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_main_address_reference DROP createdAt');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_address_reference DROP deletedAt');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_address_reference DROP updatedAt');
|
||||||
|
$this->addSql('DROP INDEX address_refid');
|
||||||
|
$this->addSql('create index address_refid
|
||||||
|
on chill_main_address_reference (refid)
|
||||||
|
where ((refid)::text <> \'\'::text)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add 3 fields on AddressReference';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_main_address_reference ADD createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_address_reference ADD deletedAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_address_reference ADD updatedAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_main_address_reference.createdAt IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_main_address_reference.deletedAt IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_main_address_reference.updatedAt IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('DROP INDEX address_refid');
|
||||||
|
$this->addSql('CREATE INDEX address_refid ON chill_main_address_reference (refId)');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20220506131307 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP INDEX chill_internal_address_reference_canonicalized');
|
||||||
|
$this->addSql('create index chill_internal_address_reference_canonicalized
|
||||||
|
on chill_main_address_reference using gist (postcode_id, addresscanonical gist_trgm_ops);');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Adapt search index on address reference canonicalized';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP INDEX chill_internal_address_reference_canonicalized');
|
||||||
|
$this->addSql('create index chill_internal_address_reference_canonicalized
|
||||||
|
on chill_main_address_reference using gist (postcode_id, addresscanonical gist_trgm_ops) WHERE deletedat IS NULL;');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user