Passed
Push — master ( 001dd0...9cbe97 )
by
unknown
19:30 queued 09:20
created

Version20251229112200::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 Version20251229112200 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Add chat setting to control mirroring private conversations into documents.';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $setting = [
22
            'variable' => 'save_private_conversations_in_documents',
23
            'selected_value' => 'false',
24
            'title' => 'Save private conversations in documents',
25
            'comment' => 'If enabled, 1:1 private chat messages will be mirrored in the course chat history documents. Recommended to keep disabled for privacy.',
26
            'category' => 'chat',
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
        $exists = $result && (int) ($result['count'] ?? 0) > 0;
41
42
        if ($exists) {
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
            $this->addSql(\sprintf(
61
                "INSERT INTO settings
62
                    (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url)
63
                 VALUES
64
                    ('%s', NULL, NULL, '%s', '%s', '%s', '%s', 1, 0, 1)",
65
                addslashes($setting['variable']),
66
                addslashes($setting['category']),
67
                addslashes($setting['selected_value']),
68
                addslashes($setting['title']),
69
                addslashes($setting['comment'])
70
            ));
71
            $this->write(\sprintf('Inserted setting: %s', $setting['variable']));
72
        }
73
    }
74
75
    public function down(Schema $schema): void
76
    {
77
        $this->addSql("
78
            DELETE FROM settings
79
             WHERE variable = 'save_private_conversations_in_documents'
80
               AND subkey IS NULL
81
               AND access_url = 1
82
        ");
83
84
        $this->write('Removed setting: save_private_conversations_in_documents');
85
    }
86
}
87