Passed
Push — master ( 50933b...355f71 )
by
unknown
11:10 queued 13s
created

Version20250616220500::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
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
final class Version20250616220500 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Migrate timezone from extra_field_values to user.timezone and remove the extra_field.';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        // 1. Copy values only when user.timezone is empty
22
        $this->addSql("
23
            UPDATE user u
24
            JOIN extra_field f
25
              ON f.variable = 'timezone'
26
             AND f.item_type = 1
27
            JOIN extra_field_values v
28
              ON v.field_id = f.id
29
             AND v.item_id = u.id
30
            SET u.timezone = v.field_value
31
            WHERE v.field_value IS NOT NULL
32
              AND v.field_value <> ''
33
              AND (u.timezone IS NULL OR u.timezone = '')
34
        ");
35
36
        // 2. Remove values from the extra_field
37
        $this->addSql("
38
            DELETE v FROM extra_field_values v
39
            JOIN extra_field f
40
              ON f.id = v.field_id
41
            WHERE f.variable = 'timezone'
42
              AND f.item_type = 1
43
        ");
44
45
        // 3. Remove the extra_field definition itself
46
        $this->addSql("
47
            DELETE FROM extra_field
48
            WHERE variable = 'timezone'
49
              AND item_type = 1
50
        ");
51
    }
52
53
    public function down(Schema $schema): void
54
    {
55
        // No rollback: the legacy extra_field will not be recreated
56
    }
57
}
58