<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220526142439 extends AbstractMigration implements ContainerAwareInterface
{
/** @var ContainerInterface */
private $container;
/**
* @param ContainerInterface|null $container
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
/** @var string $s3BaseUrl */
$s3BaseUrl = $this->container->getParameter('s3BaseUrl');
foreach ($this->getData() as $table => $field) {
$this->addSql(sprintf(
'UPDATE %s SET %s = REPLACE(%s, \'/uploads/\', \'%s/\')',
$table,
$field,
$field,
$s3BaseUrl
));
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
/** @var string $s3BaseUrl */
$s3BaseUrl = $this->container->getParameter('s3BaseUrl');
foreach ($this->getData() as $table => $field) {
$this->addSql(sprintf(
'UPDATE %s SET %s = REPLACE(%s, \'%s/\', \'/uploads/\')',
$table,
$field,
$field,
$s3BaseUrl
));
}
}
/**
* @return array
*/
private function getData(): array
{
return [
'config_pdf_form' => 'file',
'customer_file' => 'file',
'issue' => 'signature_file',
'user' => 'photo',
];
}
}