Passed
Push — master ( e2c630...542b60 )
by
unknown
14:48 queued 06:55
created

Version20250709201100   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A down() 0 10 1
A up() 0 54 3
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 Version20250709201100 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Insert or update the platform setting for hosting_limit_identical_email.';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $setting = [
22
            'variable' => 'hosting_limit_identical_email',
23
            'selected_value' => '0',
24
            'title' => 'Limit identical email usage',
25
            'comment' => 'Maximum number of accounts allowed to share the same e-mail address. Set to 0 to disable this limit.',
26
            'category' => 'platform',
27
        ];
28
29
        $sqlCheck = sprintf(
30
            "SELECT COUNT(*) as count
31
             FROM settings
32
             WHERE variable = '%s'
33
               AND subkey IS NULL
34
               AND access_url = 1",
35
            addslashes($setting['variable'])
36
        );
37
38
        $stmt = $this->connection->executeQuery($sqlCheck);
39
        $result = $stmt->fetchAssociative();
40
41
        if ($result && (int)$result['count'] > 0) {
42
            // UPDATE existing setting
43
            $this->addSql(sprintf(
44
                "UPDATE settings
45
                 SET selected_value = '%s',
46
                     title = '%s',
47
                     comment = '%s',
48
                     category = '%s'
49
                 WHERE variable = '%s'
50
                   AND subkey IS NULL
51
                   AND access_url = 1",
52
                addslashes($setting['selected_value']),
53
                addslashes($setting['title']),
54
                addslashes($setting['comment']),
55
                addslashes($setting['category']),
56
                addslashes($setting['variable'])
57
            ));
58
            $this->write(sprintf("Updated setting: %s", $setting['variable']));
59
        } else {
60
            // INSERT new setting
61
            $this->addSql(sprintf(
62
                "INSERT INTO settings
63
                    (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url)
64
                 VALUES
65
                    ('%s', NULL, NULL, '%s', '%s', '%s', '%s', 1, 0, 1)",
66
                addslashes($setting['variable']),
67
                addslashes($setting['category']),
68
                addslashes($setting['selected_value']),
69
                addslashes($setting['title']),
70
                addslashes($setting['comment'])
71
            ));
72
            $this->write(sprintf("Inserted setting: %s", $setting['variable']));
73
        }
74
    }
75
76
    public function down(Schema $schema): void
77
    {
78
        $this->addSql("
79
            DELETE FROM settings
80
             WHERE variable = 'hosting_limit_identical_email'
81
               AND subkey IS NULL
82
               AND access_url = 1
83
        ");
84
85
        $this->write("Removed setting: hosting_limit_identical_email.");
86
    }
87
}
88