|
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
|
|
|
class Version20201215072917 extends AbstractMigrationChamilo |
|
13
|
|
|
{ |
|
14
|
|
|
public function getDescription(): string |
|
15
|
|
|
{ |
|
16
|
|
|
return 'Adds allow_careers_in_global_agenda setting and updates c_calendar_event table'; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function up(Schema $schema): void |
|
20
|
|
|
{ |
|
21
|
|
|
$settingExists = $this->connection->fetchOne("SELECT COUNT(*) FROM settings_current WHERE variable = 'allow_careers_in_global_agenda'"); |
|
22
|
|
|
|
|
23
|
|
|
$selectedValue = $this->getConfigurationSelectedValue(); |
|
24
|
|
|
|
|
25
|
|
|
if ($settingExists == 0) { |
|
26
|
|
|
$this->addSql( |
|
27
|
|
|
"INSERT INTO settings_current (access_url, variable, category, selected_value, title, access_url_changeable, access_url_locked) VALUES (1, 'allow_careers_in_global_agenda', 'agenda', '$selectedValue', 'Allow careers and promotions in global agenda', 1, 0)" |
|
28
|
|
|
); |
|
29
|
|
|
} else { |
|
30
|
|
|
$this->addSql( |
|
31
|
|
|
"UPDATE settings_current SET selected_value = '$selectedValue' WHERE variable = 'allow_careers_in_global_agenda'" |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Update c_calendar_event table |
|
36
|
|
|
if (!$schema->getTable('c_calendar_event')->hasColumn('career_id')) { |
|
37
|
|
|
$this->addSql('ALTER TABLE c_calendar_event ADD career_id INT DEFAULT NULL'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if (!$schema->getTable('c_calendar_event')->hasColumn('promotion_id')) { |
|
41
|
|
|
$this->addSql('ALTER TABLE c_calendar_event ADD promotion_id INT DEFAULT NULL'); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function getConfigurationSelectedValue(): string |
|
46
|
|
|
{ |
|
47
|
|
|
global $_configuration; |
|
48
|
|
|
$rootPath = $this->getContainer()->getParameter('kernel.project_dir'); |
|
49
|
|
|
$oldConfigPath = $rootPath . '/app/config/configuration.php'; |
|
50
|
|
|
if (!in_array($oldConfigPath, get_included_files(), true)) { |
|
51
|
|
|
include_once $oldConfigPath; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$value = $_configuration['allow_careers_in_global_agenda'] ?? false; |
|
55
|
|
|
if (is_bool($value)) { |
|
56
|
|
|
return $value ? 'true' : 'false'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return (string)$value; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function down(Schema $schema): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->addSql("DELETE FROM settings_current WHERE variable = 'allow_careers_in_global_agenda'"); |
|
65
|
|
|
|
|
66
|
|
|
if ($schema->getTable('c_calendar_event')->hasColumn('career_id')) { |
|
67
|
|
|
$this->addSql('ALTER TABLE c_calendar_event DROP COLUMN career_id'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($schema->getTable('c_calendar_event')->hasColumn('promotion_id')) { |
|
71
|
|
|
$this->addSql('ALTER TABLE c_calendar_event DROP COLUMN promotion_id'); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|