Passed
Push — master ( f6bccc...e2c630 )
by Yannick
15:06 queued 06:52
created

Version20250624012300::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
}
47