Passed
Push — master ( 98981a...d408cf )
by Angel Fernando Quiroz
08:51 queued 14s
created

Version20250402110000   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
B up() 0 25 7
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
final class Version20250402110000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Fix default values for profile changeable_options and visible_options';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $defaultValues = 'name,officialcode,email,picture,login,password,language,phone,theme';
22
23
        $allChangeableOptions = $this
24
            ->connection
25
            ->executeQuery("SELECT id, selected_value FROM settings WHERE variable = 'changeable_options'")
26
            ->fetchAllAssociative()
27
        ;
28
29
        foreach ($allChangeableOptions as $changeableOptions) {
30
            if ($changeableOptions && empty($changeableOptions['selected_value'])) {
31
                $this->addSql("UPDATE settings SET selected_value = '$defaultValues' WHERE id = {$changeableOptions['id']}");
32
            }
33
        }
34
35
        $allVisibleOptions = $this
36
            ->connection
37
            ->executeQuery("SELECT id, selected_value FROM settings WHERE variable = 'visible_options'")
38
            ->fetchAllAssociative()
39
        ;
40
41
        foreach ($allVisibleOptions as $visibleOptions) {
42
            if ($visibleOptions && empty($visibleOptions['selected_value'])) {
43
                $this->addSql("UPDATE settings SET selected_value = '$defaultValues' WHERE id = {$visibleOptions['id']}");
44
            }
45
        }
46
    }
47
}
48