migrations/Version20220526142439.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. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. /**
  9.  * Auto-generated Migration: Please modify to your needs!
  10.  */
  11. final class Version20220526142439 extends AbstractMigration implements ContainerAwareInterface
  12. {
  13.     /** @var ContainerInterface */
  14.     private $container;
  15.     /**
  16.      * @param ContainerInterface|null $container
  17.      */
  18.     public function setContainer(ContainerInterface $container null)
  19.     {
  20.         $this->container $container;
  21.     }
  22.     public function getDescription(): string
  23.     {
  24.         return '';
  25.     }
  26.     public function up(Schema $schema): void
  27.     {
  28.         // this up() migration is auto-generated, please modify it to your needs
  29.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  30.         /** @var string $s3BaseUrl */
  31.         $s3BaseUrl $this->container->getParameter('s3BaseUrl');
  32.         foreach ($this->getData() as $table => $field) {
  33.             $this->addSql(sprintf(
  34.                 'UPDATE %s SET %s = REPLACE(%s, \'/uploads/\', \'%s/\')',
  35.                 $table,
  36.                 $field,
  37.                 $field,
  38.                 $s3BaseUrl
  39.             ));
  40.         }
  41.     }
  42.     public function down(Schema $schema): void
  43.     {
  44.         // this down() migration is auto-generated, please modify it to your needs
  45.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  46.         /** @var string $s3BaseUrl */
  47.         $s3BaseUrl $this->container->getParameter('s3BaseUrl');
  48.         foreach ($this->getData() as $table => $field) {
  49.             $this->addSql(sprintf(
  50.                 'UPDATE %s SET %s = REPLACE(%s, \'%s/\', \'/uploads/\')',
  51.                 $table,
  52.                 $field,
  53.                 $field,
  54.                 $s3BaseUrl
  55.             ));
  56.         }
  57.     }
  58.     /**
  59.      * @return array
  60.      */
  61.     private function getData(): array
  62.     {
  63.         return [
  64.             'config_pdf_form' => 'file',
  65.             'customer_file' => 'file',
  66.             'issue' => 'signature_file',
  67.             'user' => 'photo',
  68.         ];
  69.     }
  70. }