feat(main): Made group and blocks translatable.

Still need to do slide and FAQ entities
This commit is contained in:
2026-09-09 11:56:18 +02:00
parent 85b56f1a13
commit 7cafc376b7
23 changed files with 451 additions and 82 deletions
+102
View File
@@ -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`'
);
}