80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?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`'
|
|
);
|
|
}
|