<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20251216160119 extends AbstractMigration
{
public function getDescription(): string
{
return "Adds missing translations for categories based on the franchise's Locales.";
}
public function up(Schema $schema): void
{
$this->addSql('
INSERT INTO category_translation (
category_id,
locale_id,
name,
description,
created_at,
updated_at
)
SELECT
c.id AS category_id,
fl.locale_id,
CONCAT("cat_", c.id) AS name,
NULL AS description,
c.created_at,
c.updated_at
FROM category c
INNER JOIN shop s ON s.id = c.shop_id
INNER JOIN franchise f ON f.id = s.franchise_id
INNER JOIN franchise_locale fl ON fl.franchise_id = f.id
LEFT JOIN category_translation ct
ON ct.category_id = c.id
WHERE ct.id IS NULL;
');
}
}