From d780d951577cb6c92f5106d869586049b295ddbd Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 15 Feb 2022 13:55:21 +0100 Subject: [PATCH] work in progress --- .../DependencyInjection/Configuration.php | 17 ++++---- .../Phonenumber/PhonenumberHelper.php | 2 +- .../Phonenumber/Templating.php | 2 +- .../Validation/Validator/ValidPhonenumber.php | 2 + .../ChillMainBundle/config/services.yaml | 1 + .../config/services/phonenumber.yaml | 2 + .../ChillPersonBundle/Entity/Person.php | 6 +-- .../migrations/Version20220215135508.php | 41 +++++++++++++++++++ 8 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20220215135508.php diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 9236c8a50..942ea60f1 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -89,13 +89,16 @@ class Configuration implements ConfigurationInterface ->end() ->end() // end of notifications ->arrayNode('phone_helper') - ->canBeUnset() - ->children() - ->scalarNode('twilio_sid') - ->defaultNull() - ->end() - ->scalarNode('twilio_secret') - ->defaultNull() + ->canBeUnset() + ->children() + ->scalarNode('twilio_sid') + ->defaultNull() + ->end() + ->scalarNode('twilio_secret') + ->defaultNull() + ->end() + ->scalarNode('default_carrier_code') + ->defaultNull() ->end() ->end() ->end() diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php index 781f3ec06..0018e979b 100644 --- a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php +++ b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php @@ -139,7 +139,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface } /** - * REturn true if the phoennumber is a mobile phone. Return always true + * REturn true if the phonenumber is a mobile phone. Return always true * if the validation is not configured. * * @param string $phonenumber diff --git a/src/Bundle/ChillMainBundle/Phonenumber/Templating.php b/src/Bundle/ChillMainBundle/Phonenumber/Templating.php index 6aa0ad88e..b2fffd9b3 100644 --- a/src/Bundle/ChillMainBundle/Phonenumber/Templating.php +++ b/src/Bundle/ChillMainBundle/Phonenumber/Templating.php @@ -25,7 +25,7 @@ final class Templating extends AbstractExtension public function formatPhonenumber(string $phonenumber): string { - return $this->phonenumberHelper->format($phonenumber) ?? $phonenumber; + return $this->phonenumberHelper->format($phonenumber); } public function getFilters() diff --git a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php index 6bccff1f2..f04b8cc52 100644 --- a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php +++ b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php @@ -37,6 +37,8 @@ final class ValidPhonenumber extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + dump($value); + if (false === $this->phonenumberHelper->isPhonenumberValidationConfigured()) { $this->logger->debug('[phonenumber] skipping validation due to not configured helper'); diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index dd2407d2b..d370979b8 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -85,3 +85,4 @@ services: - "@security.token_storage" Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface: '@Chill\MainBundle\Security\Resolver\CenterResolverDispatcher' + diff --git a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml index 905c08a81..0482da320 100644 --- a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml +++ b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml @@ -3,6 +3,8 @@ services: autowire: true autoconfigure: true + Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface: '@Chill\MainBundle\Phonenumber\PhonenumberHelper' + Chill\MainBundle\Phonenumber\PhonenumberHelper: ~ Chill\MainBundle\Phonenumber\Templating: diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 49f7ae297..ce906ed64 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -429,7 +429,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The person's phonenumber. * - * @ORM\Column(type="text") + * @ORM\Column(type="text", nullable=true) * @Assert\Regex( * pattern="/^([\+{1}])([0-9\s*]{4,20})$/", * ) @@ -437,7 +437,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * type="landline", * ) */ - private string $phonenumber = ''; + private ?string $phonenumber = null; /** * The person's place of birth. @@ -1298,7 +1298,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * Get phonenumber. */ - public function getPhonenumber(): string + public function getPhonenumber(): ?string { return $this->phonenumber; } diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20220215135508.php b/src/Bundle/ChillPersonBundle/migrations/Version20220215135508.php new file mode 100644 index 000000000..9f423005e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20220215135508.php @@ -0,0 +1,41 @@ +addSql('DROP INDEX phonenumber_trgm_idx'); + $this->addSql('DROP INDEX mobilenumber_trgm_idx'); + $this->addSql('ALTER TABLE chill_person_person ALTER phonenumber TYPE TEXT'); + $this->addSql('ALTER TABLE chill_person_person ALTER phonenumber DROP DEFAULT'); + $this->addSql('ALTER TABLE chill_person_person ALTER phonenumber DROP NOT NULL'); + $this->addSql('ALTER TABLE chill_person_person ALTER mobilenumber TYPE TEXT'); + $this->addSql('ALTER TABLE chill_person_person ALTER mobilenumber DROP DEFAULT'); + $this->addSql('COMMENT ON COLUMN chill_person_person.phonenumber IS NULL'); + $this->addSql('COMMENT ON COLUMN chill_person_person.mobilenumber IS NULL'); + $this->addSql('ALTER TABLE chill_person_phone ALTER phonenumber TYPE TEXT'); + $this->addSql('ALTER TABLE chill_person_phone ALTER phonenumber DROP DEFAULT'); + $this->addSql('COMMENT ON COLUMN chill_person_phone.phonenumber IS NULL'); + } + + public function down(Schema $schema): void + { + throw new Exception('You should not do that.'); + } +}