mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
add trigger for canonicalization and anonymouse flag on 3party
This commit is contained in:
parent
ca3ced0308
commit
2820ad83de
@ -164,6 +164,12 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
*/
|
*/
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
* @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default":false})
|
||||||
|
*/
|
||||||
|
private bool $contactDataAnonymous = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Address|null
|
* @var Address|null
|
||||||
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
|
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
|
||||||
@ -471,9 +477,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @param string $nameCompany
|
* @param string $nameCompany
|
||||||
* @return ThirdParty
|
* @return ThirdParty
|
||||||
*/
|
*/
|
||||||
public function setNameCompany(string $nameCompany): ThirdParty
|
public function setNameCompany(?string $nameCompany): ThirdParty
|
||||||
{
|
{
|
||||||
$this->nameCompany = $nameCompany;
|
$this->nameCompany = (string) $nameCompany;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,18 +613,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ThirdPartyCivility|null
|
* @return Civility|null
|
||||||
*/
|
*/
|
||||||
public function getCivility(): ?ThirdPartyCivility
|
public function getCivility(): ?Civility
|
||||||
{
|
{
|
||||||
return $this->civility;
|
return $this->civility;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ThirdPartyCivility $civility
|
* @param Civility $civility
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setCivility(ThirdPartyCivility $civility): ThirdParty
|
public function setCivility(Civility $civility): ThirdParty
|
||||||
{
|
{
|
||||||
$this->civility = $civility;
|
$this->civility = $civility;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
namespace Chill\ThirdPartyBundle\Form;
|
namespace Chill\ThirdPartyBundle\Form;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use Chill\MainBundle\Entity\Civility;
|
||||||
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
||||||
use Chill\MainBundle\Form\Type\PickCenterType;
|
use Chill\MainBundle\Form\Type\PickCenterType;
|
||||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
|
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility;
|
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession;
|
use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
@ -114,8 +114,8 @@ class ThirdPartyType extends AbstractType
|
|||||||
$builder
|
$builder
|
||||||
->add('civility', EntityType::class, [
|
->add('civility', EntityType::class, [
|
||||||
'label' => 'thirdparty.Civility',
|
'label' => 'thirdparty.Civility',
|
||||||
'class' => ThirdPartyCivility::class,
|
'class' => Civility::class,
|
||||||
'choice_label' => function (ThirdPartyCivility $civility): string {
|
'choice_label' => function (Civility $civility): string {
|
||||||
return $this->translatableStringHelper->localize($civility->getName());
|
return $this->translatableStringHelper->localize($civility->getName());
|
||||||
},
|
},
|
||||||
'query_builder' => function (EntityRepository $er): QueryBuilder {
|
'query_builder' => function (EntityRepository $er): QueryBuilder {
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\ThirdParty;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create trigger for canonicalisation on 3party + indexes
|
||||||
|
*/
|
||||||
|
final class Version20211007165001 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Create trigger for canonicalisation on 3party + indexes';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql("
|
||||||
|
UPDATE chill_3party.third_party
|
||||||
|
SET canonicalized =
|
||||||
|
COALESCE(
|
||||||
|
UNACCENT(
|
||||||
|
LOWER(
|
||||||
|
name ||
|
||||||
|
CASE WHEN name <> '' THEN ' ' ELSE '' END ||
|
||||||
|
name_company ||
|
||||||
|
CASE WHEN name_company <> '' THEN ' ' ELSE '' END ||
|
||||||
|
acronym ||
|
||||||
|
CASE WHEN acronym <> '' THEN ' ' ELSE '' END
|
||||||
|
)
|
||||||
|
),
|
||||||
|
''
|
||||||
|
)
|
||||||
|
");
|
||||||
|
$this->addSql("
|
||||||
|
CREATE OR REPLACE FUNCTION chill_3party.canonicalize() RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
NEW.canonicalized = UNACCENT(LOWER(
|
||||||
|
NEW.name ||
|
||||||
|
CASE WHEN NEW.name <> '' THEN ' ' ELSE '' END ||
|
||||||
|
NEW.name_company ||
|
||||||
|
CASE WHEN NEW.name_company <> '' THEN ' ' ELSE '' END ||
|
||||||
|
NEW.acronym ||
|
||||||
|
CASE WHEN NEW.acronym <> '' THEN ' ' ELSE '' END
|
||||||
|
));
|
||||||
|
|
||||||
|
return NEW;
|
||||||
|
END
|
||||||
|
$$
|
||||||
|
");
|
||||||
|
$this->addSql("
|
||||||
|
CREATE TRIGGER canonicalize_fullname_on_insert
|
||||||
|
BEFORE INSERT
|
||||||
|
ON chill_3party.third_party
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE procedure chill_3party.canonicalize();
|
||||||
|
");
|
||||||
|
$this->addSql("
|
||||||
|
CREATE TRIGGER canonicalize_fullname_on_update
|
||||||
|
BEFORE UPDATE
|
||||||
|
ON chill_3party.third_party
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE procedure chill_3party.canonicalize();
|
||||||
|
");
|
||||||
|
$this->addSql("
|
||||||
|
CREATE INDEX chill_custom_canonicalized_trgm_idx_gist
|
||||||
|
ON chill_3party.third_party USING GIST (canonicalized gist_trgm_ops)
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP TRIGGER canonicalize_fullname_on_update ON chill_3party.third_party');
|
||||||
|
$this->addSql('DROP TRIGGER canonicalize_fullname_on_insert ON chill_3party.third_party');
|
||||||
|
$this->addSql('DROP FUNCTION chill_3party.canonicalize()');
|
||||||
|
$this->addSql("
|
||||||
|
DROP INDEX chill_3party.chill_custom_canonicalized_trgm_idx_gist
|
||||||
|
");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\ThirdParty;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add anonymous flag for contacts
|
||||||
|
*/
|
||||||
|
final class Version20211007194942 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add anonymous flag for contacts';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_3party.third_party ADD contact_data_anonymous BOOLEAN DEFAULT \'false\' NOT NULL;');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_3party.third_party DROP contact_data_anonymous');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user