migrations/Version20260416162618.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20260416162618 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Convert phone numbers from format (0xxxxx/+xxxxx) to international format (0033xxxx/00xxxx)';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         foreach (['contact''shop''company'] as $table) {
  15.             $this->addSql("UPDATE $table SET phone = CONCAT('0033', SUBSTRING(phone, 2)) WHERE phone LIKE '0%' AND phone NOT LIKE '0033%'");
  16.             $this->addSql("UPDATE $table SET phone = CONCAT('00', SUBSTRING(phone, 2)) WHERE phone LIKE '+%'");
  17.         }
  18.     }
  19.     public function down(Schema $schema): void
  20.     {
  21.         foreach (['contact''shop''company'] as $table) {
  22.             $this->addSql("UPDATE $table SET phone = CONCAT('+', SUBSTRING(phone, 3)) WHERE phone LIKE '0%' AND phone NOT LIKE '0033%'");
  23.             $this->addSql("UPDATE $table SET phone = CONCAT('0', SUBSTRING(phone, 5)) WHERE phone LIKE '0033%'");
  24.         }
  25.     }
  26. }