Skip to content

Commit e2c6301

Browse files
authored
Merge pull request #6380 from christianbeeznest/GH-6356
Internal: Decode HTML entities in language.original_name during migration - refs #6356
2 parents f6bccc0 + fd9d5e7 commit e2c6301

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/* For licensing terms, see /license.txt */
4+
5+
declare(strict_types=1);
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10+
use Doctrine\DBAL\Schema\Schema;
11+
12+
class Version20250624012300 extends AbstractMigrationChamilo
13+
{
14+
public function getDescription(): string
15+
{
16+
return 'Decode HTML entities in language.original_name to UTF-8';
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
// Retrieve all language entries where original_name contains HTML entities
22+
$languages = $this->connection->fetchAllAssociative(
23+
"SELECT id, original_name FROM language WHERE original_name LIKE '%&%;%'"
24+
);
25+
26+
foreach ($languages as $lang) {
27+
$decoded = html_entity_decode((string) $lang['original_name'], ENT_QUOTES | ENT_HTML5, 'UTF-8');
28+
29+
// Only update if the decoded value is different
30+
if ($decoded !== $lang['original_name']) {
31+
$this->addSql(
32+
"UPDATE language SET original_name = :decoded WHERE id = :id",
33+
[
34+
'decoded' => $decoded,
35+
'id' => $lang['id'],
36+
]
37+
);
38+
}
39+
}
40+
}
41+
42+
public function down(Schema $schema): void
43+
{
44+
// This migration is not reversible, as the original entity-encoded values are lost
45+
}
46+
}

0 commit comments

Comments
 (0)