Passed
Pull Request — master (#6468)
by
unknown
08:13
created

Version20250714184000::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
final class Version20250714184000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Add setting registration.hide_legal_accept_checkbox';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $variable = 'hide_legal_accept_checkbox';
22
        $category = 'registration';
23
        $selectedValue = 'false';
24
        $title = 'Hide legal accept checkbox in Terms and Conditions page';
25
        $comment = 'If set to true, removes the "I have read and accept" checkbox in the Terms and Conditions page flow.';
26
27
        $sqlCheck = sprintf(
28
            "SELECT COUNT(*) as count
29
             FROM settings
30
             WHERE variable = '%s'
31
               AND subkey IS NULL
32
               AND access_url = 1",
33
            addslashes($variable)
34
        );
35
36
        $stmt = $this->connection->executeQuery($sqlCheck);
37
        $result = $stmt->fetchAssociative();
38
39
        if ($result && (int) $result['count'] > 0) {
40
            $this->addSql(sprintf(
41
                "UPDATE settings
42
                 SET selected_value = '%s',
43
                     title = '%s',
44
                     comment = '%s',
45
                     category = '%s'
46
                 WHERE variable = '%s'
47
                   AND subkey IS NULL
48
                   AND access_url = 1",
49
                addslashes($selectedValue),
50
                addslashes($title),
51
                addslashes($comment),
52
                addslashes($category),
53
                addslashes($variable)
54
            ));
55
            $this->write(sprintf('Updated setting: %s', $variable));
56
        } else {
57
            $this->addSql(sprintf(
58
                "INSERT INTO settings
59
                    (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url)
60
                 VALUES
61
                    ('%s', NULL, NULL, '%s', '%s', '%s', '%s', 1, 0, 1)",
62
                addslashes($variable),
63
                addslashes($category),
64
                addslashes($selectedValue),
65
                addslashes($title),
66
                addslashes($comment)
67
            ));
68
            $this->write(sprintf('Inserted setting: %s', $variable));
69
        }
70
    }
71
72
    public function down(Schema $schema): void
73
    {
74
        $variable = 'hide_legal_accept_checkbox';
75
76
        $this->addSql(sprintf(
77
            "DELETE FROM settings
78
             WHERE variable = '%s'
79
               AND subkey IS NULL
80
               AND access_url = 1",
81
            addslashes($variable)
82
        ));
83
        $this->write(sprintf('Removed setting: %s.', $variable));
84
    }
85
}
86