diff --git a/install/migrations/core.php b/install/migrations/core.php index 69b65f84..6a4c6c0b 100644 --- a/install/migrations/core.php +++ b/install/migrations/core.php @@ -231,5 +231,8 @@ function getAllMigrations() { 173 => new UpdateMigration('3.3.1', '3.3.0', 173), // 2018.1.0 174 => new UpdateMigration('2018.1.0', '3.3.1', 174), + // 2018.1.1 + 175 => new \vv201811\MigrateServiceMessageLanguages(175), + 176 => new UpdateMigration('2018.1.1', '2018.1.0', 176), ); } \ No newline at end of file diff --git a/install/migrations/vv201811/MigrateServiceMessageLanguages.php b/install/migrations/vv201811/MigrateServiceMessageLanguages.php new file mode 100644 index 00000000..563c9d3e --- /dev/null +++ b/install/migrations/vv201811/MigrateServiceMessageLanguages.php @@ -0,0 +1,49 @@ + $info) { + $languageMap[$name] = $info['folder']; + } + } + + $mfh_language = $languageMap[$row['language']]; + + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` + SET `mfh_language` = '" . hesk_dbEscape($mfh_language) . "' WHERE `id` = " . intval($row['id'])); + } + } + + function innerDown($hesk_settings) { + // Get all service messages with non-null language (only HESK will populate this; MFH won't) + $rs = hesk_dbQuery("SELECT `id`, `mfh_language` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages`"); + + $language_map = []; + while ($row = hesk_dbFetchAssoc($rs)) { + // Get the language + if (count($language_map) === 0) { + // Initialize the map for the first run + foreach($hesk_settings['languages'] as $name => $info) { + $language_map[$info['folder']] = $name; + } + } + + $language = $row['mfh_language'] === 'ALL' ? 'NULL' : "'" . hesk_dbEscape($language_map[$row['mfh_language']]) . "'"; + + hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` + SET `language` = {$language} WHERE `id` = " . intval($row['id'])); + } + } +} \ No newline at end of file