aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.304_config_i18n.php
blob: 4d4c291824bfc8f4e5e2d349aea179dd84e13792 (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
<?php
class ConfigI18n extends Migration
{
    public function description()
    {
        return 'Changes config table to allow i18n types';
    }

    public function up()
    {
        $query = "ALTER TABLE `config`
                  CHANGE COLUMN `type` `type` ENUM('boolean','integer','string','array', 'i18n') CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT 'string'";
        DBManager::get()->exec($query);
    }

    public function down()
    {
        $query = "DELETE `i18n`
                  FROM `config`
                  JOIN `i18n`
                    ON `i18n`.`object_id` = CAST(MD5(`config`.`field`) AS CHAR CHARACTER SET latin1)
                        AND `i18n`.`table` = 'config'
                        AND `i18n`.`field` = 'value'
                  WHERE `config`.`type` = 'i18n'";
        DBManager::get()->exec($query);

        $query = "UPDATE `config`
                  SET `type` = 'string'
                  WHERE `type` = 'i18n'";
        DBManager::get()->exec($query);

        $query = "ALTER TABLE `config`
                  CHANGE COLUMN `type` `type` ENUM('boolean','integer','string','array') CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT 'string'";
        DBManager::get()->exec($query);
    }
}