SuperSeller3000/migrations/Version20260520010000.php

54 lines
1.5 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Yaml\Yaml;
final class Version20260520010000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Seed translation files (admin domain, en + de) into app.translations';
}
public function up(Schema $schema): void
{
// intentionally empty — data inserted in postUp
}
public function postUp(Schema $schema): void
{
$translationsDir = dirname(__DIR__).'/translations';
foreach (['en', 'de'] as $locale) {
$file = $translationsDir."/admin.{$locale}.yaml";
if (!file_exists($file)) {
continue;
}
$data = Yaml::parseFile($file);
if (!\is_array($data)) {
continue;
}
foreach ($data as $key => $value) {
$this->connection->executeStatement(
'INSERT INTO app.translations (id, locale, domain, translation_key, value)
VALUES (gen_random_uuid(), ?, ?, ?, ?)
ON CONFLICT (locale, domain, translation_key) DO NOTHING',
[$locale, 'admin', (string) $key, (string) $value]
);
}
}
}
public function down(Schema $schema): void
{
$this->addSql("DELETE FROM app.translations WHERE domain = 'admin'");
}
}