Skip to content

Internal: Decode HTML entities in language.original_name during migration - refs #6356 #6380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20250624012300.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/* For licensing terms, see /license.txt */

declare(strict_types=1);

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;

class Version20250624012300 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Decode HTML entities in language.original_name to UTF-8';
}

public function up(Schema $schema): void
{
// Retrieve all language entries where original_name contains HTML entities
$languages = $this->connection->fetchAllAssociative(
"SELECT id, original_name FROM language WHERE original_name LIKE '%&%;%'"
);

foreach ($languages as $lang) {
$decoded = html_entity_decode((string) $lang['original_name'], ENT_QUOTES | ENT_HTML5, 'UTF-8');

// Only update if the decoded value is different
if ($decoded !== $lang['original_name']) {
$this->addSql(
"UPDATE language SET original_name = :decoded WHERE id = :id",
[
'decoded' => $decoded,
'id' => $lang['id'],
]
);
}
}
}

public function down(Schema $schema): void
{
// This migration is not reversible, as the original entity-encoded values are lost
}
}
Loading