execute( 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_faq_lang` ( `id_ws_customhtml_faq` INT(11) NOT NULL, `id_lang` INT(11) NOT NULL, `question` VARCHAR(512) NOT NULL DEFAULT \'\', `answer` TEXT, PRIMARY KEY (`id_ws_customhtml_faq`, `id_lang`) );' ); } function migrateFaqFieldsToLangTable(): bool { $columns = Db::getInstance()->executeS( 'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq` LIKE \'question\'' ); if (empty($columns)) { // Already migrated in a previous run of this upgrade. return true; } $faqs = Db::getInstance()->executeS( 'SELECT `id_ws_customhtml_faq`, `question`, `answer` FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq`' ); $languages = Language::getLanguages(false); foreach ($faqs as $faq) { foreach ($languages as $language) { $existing = Db::getInstance()->executeS( 'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq_lang` WHERE `id_ws_customhtml_faq` = ' . (int) $faq['id_ws_customhtml_faq'] . ' AND `id_lang` = ' . (int) $language['id_lang'] ); if (!empty($existing)) { continue; } $result = Db::getInstance()->insert('ws_customhtml_faq_lang', [ 'id_ws_customhtml_faq' => (int) $faq['id_ws_customhtml_faq'], 'id_lang' => (int) $language['id_lang'], 'question' => pSQL($faq['question']), 'answer' => pSQL($faq['answer'], true), ]); if (!$result) { return false; } } } return true; } function dropFaqLangColumns(): bool { $columns = Db::getInstance()->executeS( 'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq` LIKE \'question\'' ); if (empty($columns)) { return true; } return Db::getInstance()->execute( 'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_faq` DROP COLUMN `question`, DROP COLUMN `answer`' ); }