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 Version20241214083500 extends AbstractMigrationChamilo |
13
|
|
|
{ |
14
|
|
|
public function getDescription(): string |
15
|
|
|
{ |
16
|
|
|
return 'Add access_url_id field to resource_file table'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function up(Schema $schema): void |
20
|
|
|
{ |
21
|
|
|
if ($schema->hasTable('resource_file')) { |
22
|
|
|
$this->addSql( |
23
|
|
|
'ALTER TABLE resource_file ADD access_url_id INT DEFAULT NULL' |
24
|
|
|
); |
25
|
|
|
$this->addSql( |
26
|
|
|
'ALTER TABLE resource_file ADD CONSTRAINT FK_RESOURCE_FILE_ACCESS_URL FOREIGN KEY (access_url_id) REFERENCES access_url (id) ON DELETE SET NULL' |
27
|
|
|
); |
28
|
|
|
$this->addSql( |
29
|
|
|
'CREATE INDEX IDX_RESOURCE_FILE_ACCESS_URL ON resource_file (access_url_id)' |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$result = $this->connection |
34
|
|
|
->executeQuery( |
35
|
|
|
"SELECT COUNT(1) FROM settings WHERE variable = 'access_url_specific_files' AND category = 'course'" |
36
|
|
|
) |
37
|
|
|
; |
38
|
|
|
$count = $result->fetchNumeric()[0]; |
39
|
|
|
if (empty($count)) { |
40
|
|
|
$this->addSql( |
41
|
|
|
"INSERT INTO settings (variable, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('access_url_specific_files','course','false','Access Url Specific Files','','',NULL, 1)" |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function down(Schema $schema): void |
47
|
|
|
{ |
48
|
|
|
if ($schema->hasTable('resource_file')) { |
49
|
|
|
$this->addSql( |
50
|
|
|
'ALTER TABLE resource_file DROP FOREIGN KEY FK_RESOURCE_FILE_ACCESS_URL' |
51
|
|
|
); |
52
|
|
|
$this->addSql( |
53
|
|
|
'DROP INDEX IDX_RESOURCE_FILE_ACCESS_URL ON resource_file' |
54
|
|
|
); |
55
|
|
|
$this->addSql( |
56
|
|
|
'ALTER TABLE resource_file DROP COLUMN access_url_id' |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|