migrations/Version20240212155557.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. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240212155557 extends AbstractMigration
  10. {
  11.     private $settingsPath;
  12.     private $filesToSymlinks;
  13.     private function initializePaths(): void
  14.     {
  15.         // Initialize $settingsPath here
  16.         $this->settingsPath realpath(__DIR__ '/..') . '/public/settings';
  17.         // Initialize $filesToSymlinks here, now that $settingsPath is set
  18.         $this->filesToSymlinks = [
  19.             $this->settingsPath "/tos_en_sample.pdf" => $this->settingsPath "/tos_en.pdf",
  20.             $this->settingsPath "/gdpr_en_sample.pdf" => $this->settingsPath "/gdpr_en.pdf",
  21.             $this->settingsPath "/tos_ro_sample.pdf" => $this->settingsPath "/tos_ro.pdf",
  22.             $this->settingsPath "/gdpr_ro_sample.pdf" => $this->settingsPath "/gdpr_ro.pdf",
  23.         ];
  24.     }
  25.     public function getDescription(): string
  26.     {
  27.         return '';
  28.     }
  29.     public function up(Schema $schema): void
  30.     {
  31.         // this up() migration is auto-generated, please modify it to your needs
  32.         $this->addSql('CREATE TABLE settings (id INT AUTO_INCREMENT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, name VARCHAR(128) NOT NULL, lang VARCHAR(3) DEFAULT \'zxx\' NOT NULL, type ENUM(\'FILE\', \'STRING\') NOT NULL COMMENT \'(DC2Type:setting_type_enum_type)\', value VARCHAR(1024) NOT NULL, UNIQUE INDEX name_lang_unique (name, lang), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  33.         $this->initializePaths();
  34.         $utcTimestamp = (new \DateTime("now", new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
  35.         // Insert values using the calculated UTC timestamp
  36.         $this->addSql("INSERT INTO settings (created_at, updated_at, name, lang, type, value) VALUES 
  37.             ('$utcTimestamp', '$utcTimestamp', 'tos', 'en', 'FILE', 'tos_en_sample.pdf'),
  38.             ('$utcTimestamp', '$utcTimestamp', 'gdpr', 'en', 'FILE', 'gdpr_en_sample.pdf'),
  39.             ('$utcTimestamp', '$utcTimestamp', 'tos', 'ro', 'FILE', 'tos_ro_sample.pdf'),
  40.             ('$utcTimestamp', '$utcTimestamp', 'gdpr', 'ro', 'FILE', 'gdpr_ro_sample.pdf')
  41.         ");
  42.         foreach ($this->filesToSymlinks as $file => $symlink) {
  43.             if (file_exists($symlink)) {
  44.                 unlink($symlink);
  45.             }
  46.             symlink($file$symlink);
  47.         }
  48.     }
  49.     public function down(Schema $schema): void
  50.     {
  51.         // this down() migration is auto-generated, please modify it to your needs
  52.         $this->addSql('DROP TABLE settings');
  53.         $this->initializePaths();
  54.         foreach ($this->filesToSymlinks as $file => $symlink) {
  55.             if (file_exists($symlink)) {
  56.                 unlink($symlink);
  57.             }
  58.         }
  59.     }
  60. }