mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
set carrier code parameter and lint existing phonenmubers
This commit is contained in:
parent
9f90cc8fe1
commit
ed4cf67e79
@ -29,6 +29,7 @@ variables:
|
||||
REDIS_URL: redis://redis:6379
|
||||
# change vendor dir to make the app install into tests/apps
|
||||
COMPOSER_VENDOR_DIR: tests/app/vendor
|
||||
DEFAULT_CARRIER_CODE: BE
|
||||
|
||||
stages:
|
||||
- Composer install
|
||||
|
@ -4,22 +4,47 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Chill\Migrations\Main\MigrationPhonenumberHelper;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Exception;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use function Chill\MainBundle\migrations\buildMigrationPhonenumberClause;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20220215135509 extends AbstractMigration
|
||||
final class Version20220215135509 extends AbstractMigration implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
private function buildMigrationPhoneNumberClause(string $defaultCarriercode, string $field): string
|
||||
{
|
||||
$util = PhoneNumberUtil::getInstance();
|
||||
|
||||
$countryCode = $util->getCountryCodeForRegion($defaultCarriercode);
|
||||
|
||||
return sprintf('%s=CASE WHEN
|
||||
LEFT(%s, 1) = \'0\'
|
||||
THEN
|
||||
\'%s\' || replace(replace(substr(%s, 2), \'(0)\', \'\'), \' \', \'\')
|
||||
ELSE replace(replace(%s, \'(0)\', \'\'),\' \', \'\')
|
||||
END', $field, $field, $countryCode, $field, $field);
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Update phone numbers';
|
||||
return 'Update phone numbers for person';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$carrier_code = $this->container
|
||||
->getParameter('chill_main')['phone_helper']['default_carrier_code'];
|
||||
|
||||
if (null === $carrier_code) {
|
||||
throw new \RuntimeException("no carrier code");
|
||||
}
|
||||
|
||||
$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');
|
||||
@ -30,10 +55,20 @@ final class Version20220215135509 extends AbstractMigration
|
||||
$this->addSql('ALTER TABLE chill_person_person ALTER mobilenumber DROP NOT NULL');
|
||||
$this->addSql('COMMENT ON COLUMN chill_person_person.mobilenumber IS NULL');
|
||||
|
||||
$this->addSql('UPDATE chill_person_person SET '.
|
||||
$this->buildMigrationPhonenumberClause($carrier_code, 'phonenumber').
|
||||
', '.
|
||||
$this->buildMigrationPhoneNumberClause($carrier_code, 'mobilenumber')
|
||||
);
|
||||
|
||||
$this->addSql('ALTER TABLE chill_person_phone ALTER phonenumber TYPE TEXT');
|
||||
$this->addSql('ALTER TABLE chill_person_phone ALTER phonenumber DROP DEFAULT');
|
||||
$this->addSql('ALTER TABLE chill_person_phone ALTER phonenumber DROP NOT NULL');
|
||||
$this->addSql('COMMENT ON COLUMN chill_person_phone.phonenumber IS NULL');
|
||||
|
||||
$this->addSql('UPDATE chill_person_phone SET '.
|
||||
$this->buildMigrationPhoneNumberClause($carrier_code, 'phonenumber')
|
||||
);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 8d4a020ba2b824ac94fee53cf9df3935d9f449bf
|
||||
Subproject commit f252a9f354e98938932b1d74477e1749e02bfc1d
|
Loading…
x
Reference in New Issue
Block a user