Skip to content

Commit

Permalink
update OK !
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestaSafe committed Sep 6, 2023
1 parent 608766d commit 58cbe04
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions classes/PrettyBlocksMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ public static function migrateSettings()

$theme_name = Context::getContext()->shop->theme_name;
$can_delete_settings = false;
if (!self::tableExists('prettyblocks_settings')) {
$prettyblocks = \Module::getInstanceByName('prettyblocks');
$prettyblocks->makeSettingsTable();
}
// if (!self::tableExists('prettyblocks_settings')) {
// $prettyblocks = \Module::getInstanceByName('prettyblocks');
// $prettyblocks->makeSettingsTable();
// }

foreach (Shop::getShops() as $shop) {
$id_shop = (int) $shop['id_shop'];

// get settings from database
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'pretty_blocks_settings WHERE theme_name = "' . pSQL($theme_name) . '" AND id_shop = ' . (int) $id_shop;
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'prettyblocks_settings WHERE theme_name = "' . pSQL($theme_name) . '" AND id_shop = ' . (int) $id_shop;
$row = Db::getInstance()->getRow($sql);

if ($row) {
// if settings exists, update
$sql = 'UPDATE ' . _DB_PREFIX_ . 'pretty_blocks_settings SET settings = "' . pSQL(json_encode($res, true)) . '", profile = "Theme ' . pSQL($theme_name) . '" WHERE theme_name = "' . pSQL($theme_name) . '" AND id_shop = ' . (int) $id_shop;
$sql = 'UPDATE ' . _DB_PREFIX_ . 'prettyblocks_settings SET settings = "' . pSQL(json_encode($res, true)) . '", profile = "Theme ' . pSQL($theme_name) . '" WHERE theme_name = "' . pSQL($theme_name) . '" AND id_shop = ' . (int) $id_shop;
$result = Db::getInstance()->execute($sql);
} else {
// if settings not exists, create
Expand All @@ -204,7 +204,7 @@ public static function migrateSettings()
'id_shop' => (int) $id_shop,
'profile' => 'Theme ' . pSQL($theme_name),
];
$result = Db::getInstance()->insert('pretty_blocks_settings', $data);
$result = Db::getInstance()->insert('prettyblocks_settings', $data);
}

if ($result) {
Expand Down
6 changes: 1 addition & 5 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public function isUsingNewTranslationSystem()
return true;
}

public function upgrade_3_0_0()
{
return \PrettyBlocksMigrate::migrateLangTable() && \PrettyBlocksMigrate::migrateSettings();
}

/**
* create tables on install.
*
Expand Down Expand Up @@ -142,6 +137,7 @@ private function removeDb()
$db = [];
$db[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'prettyblocks`';
$db[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'prettyblocks_lang`';
$db[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'prettyblocks_settings`';

$isOk = true;
foreach ($db as $sql) {
Expand Down
8 changes: 7 additions & 1 deletion upgrade/upgrade-3.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@
*/
function upgrade_module_3_0_0($module)
{
return $module->upgrade_3_0_0();
if (!\PrettyBlocksMigrate::tableExists('prettyblocks_settings')) {
$module->makeSettingsTable();
}
\PrettyBlocksMigrate::migrateLangTable();
\PrettyBlocksMigrate::migrateSettings();

return true;
}

0 comments on commit 58cbe04

Please sign in to comment.