aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/6.0.37_step_4261.php
blob: 13a7474c860b1b59fb4e7bfb02a78d2a91ca0276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

final class Step4261 extends Migration
{
    public function description()
    {
        return 'Add field to module table to store original language.';
    }

    protected function up()
    {
        $db = DBManager::get();

        // retrieve default language from config
        $config_language = $db->fetchColumn(
            "SELECT `value` FROM `config` WHERE `field` = 'DEFAULT_LANGUAGE'"
        );
        $default_language = $config_language ?? array_keys($GLOBALS['CONTENT_LANGUAGES'])[0] ?? 'de_DE';
        $db->execute(
            'ALTER TABLE `mvv_modul`
            ADD `original_language` VARCHAR(10) NOT NULL DEFAULT ? COLLATE latin1_bin AFTER `verantwortlich`',
            [$default_language]
        );

        // use full language code for file refs
        foreach ($GLOBALS['CONTENT_LANGUAGES'] as $code => $language) {
            $old_code = mb_strtoupper(mb_strstr($code, '_', true));
            $db->execute('UPDATE `mvv_files_filerefs` SET `file_language` = ? WHERE `file_language` = ?',
                [$code, $old_code]);
        }

        $query = "INSERT INTO `config` (`field`, `value`, `type`, `range`, `section`, `mkdate`, `chdate`, `description`)
                  VALUES ('MVV_DEFAULT_LANGUAGE', ?, 'string', 'global', 'mvv', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?)";
        $db->execute($query,
            [
                $default_language,
                'Code der Inhalts-Sprache, die als Original-Sprache der Deskriptoren für Module und Modulteile vorausgewählt ist.',
            ]
        );
    }

    protected function down()
    {
        $db = DBManager::get();

        $db->exec(
            "ALTER TABLE `mvv_modul`
            DROP COLUMN `original_language`"
        );

        // use short language code for file refs
        foreach ($GLOBALS['CONTENT_LANGUAGES'] as $code => $language) {
            $old_code = mb_strtoupper(mb_strstr($code, '_', true));
            $db->execute('UPDATE `mvv_files_filerefs` SET `file_language` = ? WHERE `file_language` = ?',
                [$old_code, $code]);
        }

        $query = "DELETE `config`, `config_values`
                  FROM `config`
                  LEFT JOIN `config_values` USING (`field`)
                  WHERE `field` = 'MVV_DEFAULT_LANGUAGE'";
        $db->exec($query);
    }
}