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 Version20250905073102 extends AbstractMigrationChamilo |
13
|
|
|
{ |
14
|
|
|
public function getDescription(): string |
15
|
|
|
{ |
16
|
|
|
return 'Insert or update platform setting title/comment for disclose_ai_assistance.'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function up(Schema $schema): void |
20
|
|
|
{ |
21
|
|
|
$settings = [ |
22
|
|
|
[ |
23
|
|
|
'name' => 'disclose_ai_assistance', |
24
|
|
|
'title' => 'Disclose AI assistance', |
25
|
|
|
'comment' => 'Show a tag on any content or feedback that has been generated or co-generated by any AI system, evidencing to the user that the content was built with the help of some AI system. Details about which AI system was used in which case are kept inside the database for audit, but are not directly accessible by the final user.', |
26
|
|
|
], |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
foreach ($settings as $setting) { |
30
|
|
|
$variable = addslashes($setting['name']); |
31
|
|
|
$title = addslashes($setting['title']); |
32
|
|
|
$comment = addslashes($setting['comment']); |
33
|
|
|
|
34
|
|
|
$sqlCheck = \sprintf( |
35
|
|
|
"SELECT COUNT(*) AS count |
36
|
|
|
FROM settings |
37
|
|
|
WHERE variable = '%s' |
38
|
|
|
AND subkey IS NULL |
39
|
|
|
AND access_url = 1", |
40
|
|
|
$variable |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$stmt = $this->connection->executeQuery($sqlCheck); |
44
|
|
|
$result = $stmt->fetchAssociative(); |
45
|
|
|
|
46
|
|
|
if ($result && (int) $result['count'] > 0) { |
47
|
|
|
$this->addSql(\sprintf( |
48
|
|
|
"UPDATE settings |
49
|
|
|
SET title = '%s', |
50
|
|
|
comment = '%s', |
51
|
|
|
category = 'ai_helpers' |
52
|
|
|
WHERE variable = '%s' |
53
|
|
|
AND subkey IS NULL |
54
|
|
|
AND access_url = 1", |
55
|
|
|
$title, |
56
|
|
|
$comment, |
57
|
|
|
$variable |
58
|
|
|
)); |
59
|
|
|
$this->write(\sprintf('Updated setting: %s', $setting['name'])); |
60
|
|
|
} else { |
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, 'ai_helpers', 'true', '%s', '%s', 1, 0, 1)", |
66
|
|
|
$variable, |
67
|
|
|
$title, |
68
|
|
|
$comment |
69
|
|
|
)); |
70
|
|
|
$this->write(\sprintf('Inserted setting: %s', $setting['name'])); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function down(Schema $schema): void |
76
|
|
|
{ |
77
|
|
|
// Rollback: remove the setting entry (keeps system functional; defaults can apply) |
78
|
|
|
$variables = [ |
79
|
|
|
'disclose_ai_assistance', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
foreach ($variables as $variable) { |
83
|
|
|
$this->addSql(\sprintf( |
84
|
|
|
"DELETE FROM settings |
85
|
|
|
WHERE variable = '%s' |
86
|
|
|
AND subkey IS NULL |
87
|
|
|
AND access_url = 1", |
88
|
|
|
addslashes($variable) |
89
|
|
|
)); |
90
|
|
|
$this->write(\sprintf('Removed setting: %s.', $variable)); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|