Skip to content

Commit a036884

Browse files
committed
make sure the value of MEDIADOWNLOAD old config is reflected into the new config,
This PR fixes elan-ev#1146. During the migration we capture the current value of old config and map it into the new config value. Since the old one is boolean we consider only 'never' and 'allow' values for the new one!
1 parent bb9f46f commit a036884

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

migrations/062_add_config_custom_download.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ public function up()
1515
ADD COLUMN `allow_download` boolean DEFAULT NULL");
1616
$db->exec("ALTER TABLE `oc_video`
1717
ADD COLUMN `allow_download` boolean DEFAULT NULL");
18+
19+
// Get the current value of the config and map to new config value.
20+
$current_media_download_config = (bool) Config::get()->OPENCAST_ALLOW_MEDIADOWNLOAD ?? null;
21+
$new_config_value = $current_media_download_config === true ? 'allow' : 'never';
22+
1823
$db->exec("DELETE FROM `config` WHERE `field`='OPENCAST_ALLOW_MEDIADOWNLOAD'");
19-
24+
2025
$stmt = $db->prepare('INSERT IGNORE INTO config (field, value, section, type, `range`, mkdate, chdate, description)
2126
VALUES (:name, :value, :section, :type, :range, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)');
2227
$stmt->execute([
@@ -25,7 +30,7 @@ public function up()
2530
'description' => 'Erlaubnis für Mediendownloads verwalten.',
2631
'range' => 'global',
2732
'type' => 'string',
28-
'value' => 'never'
33+
'value' => $new_config_value
2934
]);
3035

3136
SimpleOrMap::expireTableScheme();
@@ -35,6 +40,10 @@ public function down()
3540
{
3641
$db = DBManager::get();
3742

43+
// Revert the config value with mapping to the old config.
44+
$new_media_download_config = (string) Config::get()->OPENCAST_MEDIADOWNLOAD ?? 'never';
45+
$old_config_value = $new_media_download_config !== 'allow' ? true : false;
46+
3847
$db->exec("DELETE FROM config WHERE field = 'OPENCAST_MEDIADOWNLOAD'");
3948
$db->exec("ALTER TABLE `oc_playlist` DROP COLUMN `allow_download`");
4049
$db->exec("ALTER TABLE `oc_video` DROP COLUMN `allow_download`");
@@ -47,7 +56,7 @@ public function down()
4756
'description' => 'Wird Nutzern angeboten, Aufzeichnungen herunterzuladen?',
4857
'range' => 'global',
4958
'type' => 'boolean',
50-
'value' => true
59+
'value' => $old_config_value
5160
]);
5261

5362
SimpleOrMap::expireTableScheme();

0 commit comments

Comments
 (0)