<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240212155557 extends AbstractMigration
{
private $settingsPath;
private $filesToSymlinks;
private function initializePaths(): void
{
// Initialize $settingsPath here
$this->settingsPath = realpath(__DIR__ . '/..') . '/public/settings';
// Initialize $filesToSymlinks here, now that $settingsPath is set
$this->filesToSymlinks = [
$this->settingsPath . "/tos_en_sample.pdf" => $this->settingsPath . "/tos_en.pdf",
$this->settingsPath . "/gdpr_en_sample.pdf" => $this->settingsPath . "/gdpr_en.pdf",
$this->settingsPath . "/tos_ro_sample.pdf" => $this->settingsPath . "/tos_ro.pdf",
$this->settingsPath . "/gdpr_ro_sample.pdf" => $this->settingsPath . "/gdpr_ro.pdf",
];
}
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$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');
$this->initializePaths();
$utcTimestamp = (new \DateTime("now", new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
// Insert values using the calculated UTC timestamp
$this->addSql("INSERT INTO settings (created_at, updated_at, name, lang, type, value) VALUES
('$utcTimestamp', '$utcTimestamp', 'tos', 'en', 'FILE', 'tos_en_sample.pdf'),
('$utcTimestamp', '$utcTimestamp', 'gdpr', 'en', 'FILE', 'gdpr_en_sample.pdf'),
('$utcTimestamp', '$utcTimestamp', 'tos', 'ro', 'FILE', 'tos_ro_sample.pdf'),
('$utcTimestamp', '$utcTimestamp', 'gdpr', 'ro', 'FILE', 'gdpr_ro_sample.pdf')
");
foreach ($this->filesToSymlinks as $file => $symlink) {
if (file_exists($symlink)) {
unlink($symlink);
}
symlink($file, $symlink);
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE settings');
$this->initializePaths();
foreach ($this->filesToSymlinks as $file => $symlink) {
if (file_exists($symlink)) {
unlink($symlink);
}
}
}
}