Passed
Push — master ( 475d69...7337d9 )
by Yannick
15:00 queued 06:46
created

Version20251006172700::up()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 19
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 30
rs 9.6333
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 Version20251006172700 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return "Add survey setting: show_pending_survey_in_menu=false";
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $variable = 'show_pending_survey_in_menu';
22
        $title = addslashes('Show "Pending surveys" in menu');
23
        $comment = addslashes('Display a menu item that lets users access their pending surveys.');
24
        $category = 'survey';
25
        $default = 'false';
26
27
        $sqlCheck = "SELECT COUNT(*) AS c FROM settings WHERE variable = '$variable'";
28
        $result = $this->connection->executeQuery($sqlCheck)->fetchAssociative();
29
30
        if ($result && (int)$result['c'] > 0) {
31
            $this->addSql("
32
                UPDATE settings
33
                SET title = '$title',
34
                    comment = '$comment',
35
                    category = '$category',
36
                    type = COALESCE(type, 'radio'),
37
                    selected_value = COALESCE(selected_value, '$default')
38
                WHERE variable = '$variable'
39
            ");
40
            $this->write("Updated setting: $variable");
41
        } else {
42
            $this->addSql("
43
                INSERT INTO settings
44
                    (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url)
45
                VALUES
46
                    ('$variable', NULL, 'radio', '$category', '$default', '$title', '$comment', 1, 0, 1)
47
            ");
48
            $this->write("Inserted setting: $variable ($default)");
49
        }
50
    }
51
52
    public function down(Schema $schema): void
53
    {
54
        $this->addSql("
55
            DELETE FROM settings
56
            WHERE variable = 'show_pending_survey_in_menu'
57
              AND subkey IS NULL
58
              AND access_url = 1
59
        ");
60
        $this->write("Removed setting: show_pending_survey_in_menu");
61
    }
62
}
63