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 Version20250924220200 extends AbstractMigrationChamilo |
13
|
|
|
{ |
14
|
|
|
public function getDescription(): string |
15
|
|
|
{ |
16
|
|
|
return 'Ensure default platform settings for global chat: allow_global_chat=false, hide_chat_video=true.'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function up(Schema $schema): void |
20
|
|
|
{ |
21
|
|
|
$settings = [ |
22
|
|
|
[ |
23
|
|
|
'name' => 'allow_global_chat', |
24
|
|
|
'title' => 'Allow global chat', |
25
|
|
|
'comment' => 'Users can chat with each other', |
26
|
|
|
'category' => 'chat', |
27
|
|
|
'default' => 'false', |
28
|
|
|
], |
29
|
|
|
[ |
30
|
|
|
'name' => 'hide_chat_video', |
31
|
|
|
'title' => 'Hide videochat option in global chat', |
32
|
|
|
'comment' => '', |
33
|
|
|
'category' => 'chat', |
34
|
|
|
'default' => 'true', |
35
|
|
|
], |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
foreach ($settings as $setting) { |
39
|
|
|
$variable = addslashes($setting['name']); |
40
|
|
|
$title = addslashes($setting['title']); |
41
|
|
|
$comment = addslashes($setting['comment']); |
42
|
|
|
$category = addslashes($setting['category']); |
43
|
|
|
$default = addslashes($setting['default']); |
44
|
|
|
|
45
|
|
|
$sqlCheck = \sprintf( |
46
|
|
|
"SELECT COUNT(*) AS count |
47
|
|
|
FROM settings |
48
|
|
|
WHERE variable = '%s'", |
49
|
|
|
$variable |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$stmt = $this->connection->executeQuery($sqlCheck); |
53
|
|
|
$result = $stmt->fetchAssociative(); |
54
|
|
|
|
55
|
|
|
if ($result && (int) $result['count'] > 0) { |
56
|
|
|
$this->addSql(\sprintf( |
57
|
|
|
"UPDATE settings |
58
|
|
|
SET title = '%s', |
59
|
|
|
comment = '%s', |
60
|
|
|
category = '%s', |
61
|
|
|
type = COALESCE(type, 'radio'), |
62
|
|
|
selected_value = '%s' |
63
|
|
|
WHERE variable = '%s'", |
64
|
|
|
$title, |
65
|
|
|
$comment, |
66
|
|
|
$category, |
67
|
|
|
$default, |
68
|
|
|
$variable |
69
|
|
|
)); |
70
|
|
|
$this->write(\sprintf('Updated setting: %s (selected_value set to %s)', $setting['name'], $setting['default'])); |
71
|
|
|
} else { |
72
|
|
|
$this->addSql(\sprintf( |
73
|
|
|
"INSERT INTO settings |
74
|
|
|
(variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url) |
75
|
|
|
VALUES |
76
|
|
|
('%s', NULL, 'radio', '%s', '%s', '%s', '%s', 1, 0, 1)", |
77
|
|
|
$variable, |
78
|
|
|
$category, |
79
|
|
|
$default, |
80
|
|
|
$title, |
81
|
|
|
$comment |
82
|
|
|
)); |
83
|
|
|
$this->write(\sprintf('Inserted setting: %s (%s)', $setting['name'], $setting['default'])); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function down(Schema $schema): void |
89
|
|
|
{ |
90
|
|
|
$variables = ['allow_global_chat', 'hide_chat_video']; |
91
|
|
|
|
92
|
|
|
foreach ($variables as $variable) { |
93
|
|
|
$this->addSql(\sprintf( |
94
|
|
|
"DELETE FROM settings |
95
|
|
|
WHERE variable = '%s' |
96
|
|
|
AND subkey IS NULL |
97
|
|
|
AND access_url = 1", |
98
|
|
|
addslashes($variable) |
99
|
|
|
)); |
100
|
|
|
$this->write(\sprintf('Removed setting: %s.', $variable)); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|