feat(main): Made group and blocks translatable.
Still need to do slide and FAQ entities
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function upgrade_module_1_20_0($module)
|
||||
{
|
||||
if (!createGroupLangTable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!migrateGroupTitlesToLangTable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dropGroupTitleColumn();
|
||||
}
|
||||
|
||||
function createGroupLangTable(): bool
|
||||
{
|
||||
return Db::getInstance()->execute(
|
||||
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_group_lang` (
|
||||
`id_ws_customhtml_group` INT(11) NOT NULL,
|
||||
`id_lang` INT(11) NOT NULL,
|
||||
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
|
||||
PRIMARY KEY (`id_ws_customhtml_group`, `id_lang`)
|
||||
);'
|
||||
);
|
||||
}
|
||||
|
||||
function migrateGroupTitlesToLangTable(): bool
|
||||
{
|
||||
$groupColumns = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` LIKE \'title\''
|
||||
);
|
||||
|
||||
if (empty($groupColumns)) {
|
||||
// Already migrated in a previous run of this upgrade.
|
||||
return true;
|
||||
}
|
||||
|
||||
$groups = Db::getInstance()->executeS(
|
||||
'SELECT `id_ws_customhtml_group`, `title` FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`'
|
||||
);
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
foreach ($groups as $group) {
|
||||
foreach ($languages as $language) {
|
||||
$existing = Db::getInstance()->executeS(
|
||||
'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_group_lang`
|
||||
WHERE `id_ws_customhtml_group` = ' . (int) $group['id_ws_customhtml_group'] . '
|
||||
AND `id_lang` = ' . (int) $language['id_lang']
|
||||
);
|
||||
|
||||
if (!empty($existing)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = Db::getInstance()->insert('ws_customhtml_group_lang', [
|
||||
'id_ws_customhtml_group' => (int) $group['id_ws_customhtml_group'],
|
||||
'id_lang' => (int) $language['id_lang'],
|
||||
'title' => pSQL($group['title']),
|
||||
]);
|
||||
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function dropGroupTitleColumn(): bool
|
||||
{
|
||||
$groupColumns = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` LIKE \'title\''
|
||||
);
|
||||
|
||||
if (empty($groupColumns)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Db::getInstance()->execute(
|
||||
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_group` DROP COLUMN `title`'
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function upgrade_module_1_21_0($module)
|
||||
{
|
||||
if (!createBlockLangTable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!migrateBlockFieldsToLangTable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dropBlockLangColumns();
|
||||
}
|
||||
|
||||
function createBlockLangTable(): bool
|
||||
{
|
||||
return Db::getInstance()->execute(
|
||||
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_lang` (
|
||||
`id_ws_customhtml` INT(11) NOT NULL,
|
||||
`id_lang` INT(11) NOT NULL,
|
||||
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
|
||||
`content` LONGTEXT,
|
||||
`description` TEXT,
|
||||
`extra_description` TEXT,
|
||||
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
|
||||
PRIMARY KEY (`id_ws_customhtml`, `id_lang`)
|
||||
);'
|
||||
);
|
||||
}
|
||||
|
||||
function migrateBlockFieldsToLangTable(): bool
|
||||
{
|
||||
$columns = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'title\''
|
||||
);
|
||||
|
||||
if (empty($columns)) {
|
||||
// Already migrated in a previous run of this upgrade.
|
||||
return true;
|
||||
}
|
||||
|
||||
$blocks = Db::getInstance()->executeS(
|
||||
'SELECT `id_ws_customhtml`, `title`, `content`, `description`, `extra_description`, `link_text`
|
||||
FROM `' . _DB_PREFIX_ . 'ws_customhtml`'
|
||||
);
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
foreach ($languages as $language) {
|
||||
$existing = Db::getInstance()->executeS(
|
||||
'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_lang`
|
||||
WHERE `id_ws_customhtml` = ' . (int) $block['id_ws_customhtml'] . '
|
||||
AND `id_lang` = ' . (int) $language['id_lang']
|
||||
);
|
||||
|
||||
if (!empty($existing)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = Db::getInstance()->insert('ws_customhtml_lang', [
|
||||
'id_ws_customhtml' => (int) $block['id_ws_customhtml'],
|
||||
'id_lang' => (int) $language['id_lang'],
|
||||
'title' => pSQL($block['title']),
|
||||
'content' => pSQL($block['content'], true),
|
||||
'description' => pSQL($block['description']),
|
||||
'extra_description' => pSQL($block['extra_description']),
|
||||
'link_text' => pSQL($block['link_text']),
|
||||
]);
|
||||
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function dropBlockLangColumns(): bool
|
||||
{
|
||||
$columns = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'title\''
|
||||
);
|
||||
|
||||
if (empty($columns)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Db::getInstance()->execute(
|
||||
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml`
|
||||
DROP COLUMN `title`,
|
||||
DROP COLUMN `content`,
|
||||
DROP COLUMN `description`,
|
||||
DROP COLUMN `extra_description`,
|
||||
DROP COLUMN `link_text`'
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function upgrade_module_1_22_0($module)
|
||||
{
|
||||
if (!addLinkColumnToLangTable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!migrateBlockLinkToLangTable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dropBlockLinkColumn();
|
||||
}
|
||||
|
||||
function addLinkColumnToLangTable(): bool
|
||||
{
|
||||
$existing = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_lang` LIKE \'link\''
|
||||
);
|
||||
|
||||
if (!empty($existing)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Db::getInstance()->execute(
|
||||
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_lang`
|
||||
ADD COLUMN `link` VARCHAR(512) NOT NULL DEFAULT \'\' AFTER `extra_description`'
|
||||
);
|
||||
}
|
||||
|
||||
function migrateBlockLinkToLangTable(): bool
|
||||
{
|
||||
$columns = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'link\''
|
||||
);
|
||||
|
||||
if (empty($columns)) {
|
||||
// Already migrated in a previous run of this upgrade.
|
||||
return true;
|
||||
}
|
||||
|
||||
$blocks = Db::getInstance()->executeS(
|
||||
'SELECT `id_ws_customhtml`, `link` FROM `' . _DB_PREFIX_ . 'ws_customhtml`'
|
||||
);
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
$result = Db::getInstance()->update(
|
||||
'ws_customhtml_lang',
|
||||
['link' => pSQL($block['link'])],
|
||||
'`id_ws_customhtml` = ' . (int) $block['id_ws_customhtml']
|
||||
);
|
||||
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function dropBlockLinkColumn(): bool
|
||||
{
|
||||
$columns = Db::getInstance()->executeS(
|
||||
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'link\''
|
||||
);
|
||||
|
||||
if (empty($columns)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Db::getInstance()->execute(
|
||||
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml` DROP COLUMN `link`'
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user