Passed
Pull Request — master (#6811)
by
unknown
10:13
created

Version20250926070900::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
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 Version20250926070900 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Purge orphan user extra fields (values + tags) where user no longer exists.';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $this->addSql("
22
            DELETE v FROM extra_field_values v
23
            INNER JOIN extra_field f ON f.id = v.field_id
24
            LEFT JOIN `user` u ON u.id = v.item_id
25
            WHERE f.item_type = 1 AND u.id IS NULL
26
        ");
27
28
        $this->addSql("
29
            DELETE r FROM extra_field_rel_tag r
30
            INNER JOIN extra_field f ON f.id = r.field_id
31
            LEFT JOIN `user` u ON u.id = r.item_id
32
            WHERE f.item_type = 1  AND u.id IS NULL
33
        ");
34
    }
35
36
    public function down(Schema $schema): void
37
    {
38
        // No-op (data purge).
39
    }
40
}
41