This commit is contained in:
2022-03-02 14:11:47 +01:00
parent f4f488dad1
commit e9ffdb1f03
8 changed files with 192 additions and 175 deletions

View File

@@ -28,13 +28,10 @@ use Chill\PersonBundle\Form\Type\GenderType;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
use Chill\PersonBundle\Form\Type\PersonPhoneType;
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberType as LibphonenumberPhoneNumberType;
use libphonenumber\PhoneNumberUtil;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
@@ -153,7 +150,7 @@ class PersonType extends AbstractType
'format' => PhoneNumberFormat::NATIONAL,
'required' => false,
'attr' => [
'placeholder' => PhoneNumberUtil::getInstance()->format($examplePhoneNumber, PhoneNumberFormat::NATIONAL)
'placeholder' => PhoneNumberUtil::getInstance()->format($examplePhoneNumber, PhoneNumberFormat::NATIONAL),
],
]
);
@@ -175,7 +172,7 @@ class PersonType extends AbstractType
'format' => PhoneNumberFormat::NATIONAL,
'required' => false,
'attr' => [
'placeholder' => PhoneNumberUtil::getInstance()->format($examplePhoneNumber, PhoneNumberFormat::NATIONAL)
'placeholder' => PhoneNumberUtil::getInstance()->format($examplePhoneNumber, PhoneNumberFormat::NATIONAL),
],
]
)

View File

@@ -1,5 +1,14 @@
<?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\PersonBundle\Validator\Constraints\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod;

View File

@@ -1,22 +1,75 @@
<?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\Person;
use Chill\Migrations\Main\MigrationPhonenumberHelper;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Exception;
use libphonenumber\PhoneNumberUtil;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use function Chill\MainBundle\migrations\buildMigrationPhonenumberClause;
final class Version20220215135509 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function down(Schema $schema): void
{
throw new Exception('You should not do that.');
}
public function getDescription(): string
{
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');
$this->addSql('COMMENT ON COLUMN chill_person_person.phonenumber IS 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('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')
);
}
private function buildMigrationPhoneNumberClause(string $defaultCarriercode, string $field): string
{
$util = PhoneNumberUtil::getInstance();
@@ -30,49 +83,4 @@ final class Version20220215135509 extends AbstractMigration implements Container
ELSE replace(replace(%s, \'(0)\', \'\'),\' \', \'\')
END', $field, $field, $countryCode, $field, $field);
}
public function getDescription(): string
{
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');
$this->addSql('COMMENT ON COLUMN chill_person_person.phonenumber IS 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('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
{
throw new Exception('You should not do that.');
}
}