[-] Installer : Fix warning during upgrade when issues with shops tables
This commit is contained in:
@@ -41,7 +41,7 @@ function add_default_restrictions_modules_groups()
|
||||
FROM `'._DB_PREFIX_.'shop`');
|
||||
foreach ($groups as $group)
|
||||
{
|
||||
if (!is_array($modules))
|
||||
if (!is_array($modules) || !is_array($shops))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
@@ -49,10 +49,10 @@ function add_default_restrictions_modules_groups()
|
||||
foreach ($modules as $mod)
|
||||
foreach ($shops as $s)
|
||||
$sql .= '("'.(int)$mod['id_module'].'", "'.(int)$s.'", "'.(int)$group['id_group'].'"),';
|
||||
// removing last comma to avoid SQL error
|
||||
$sql = substr($sql, 0, strlen($sql) - 1);
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
// removing last comma to avoid SQL error
|
||||
$sql = substr($sql, 0, strlen($sql) - 1);
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -54,29 +54,35 @@ function generate_root_category_for_multishop()
|
||||
');
|
||||
|
||||
$data = array();
|
||||
foreach ($langs as $lang)
|
||||
foreach ($shops as $shop)
|
||||
$data[] = array(
|
||||
'id_lang' => $lang['id_lang'],
|
||||
'id_shop' => $shop['id_shop'],
|
||||
'id_category' => $id,
|
||||
'name' => 'Root',
|
||||
'link_rewrite' => '',
|
||||
);
|
||||
Db::getInstance()->insert('category_lang', $data);
|
||||
if(is_array($shops) && is_array($langs))
|
||||
{
|
||||
foreach ($langs as $lang)
|
||||
foreach ($shops as $shop)
|
||||
$data[] = array(
|
||||
'id_lang' => $lang['id_lang'],
|
||||
'id_shop' => $shop['id_shop'],
|
||||
'id_category' => $id,
|
||||
'name' => 'Root',
|
||||
'link_rewrite' => '',
|
||||
);
|
||||
Db::getInstance()->insert('category_lang', $data);
|
||||
}
|
||||
|
||||
$categories = Db::getInstance()->executeS('
|
||||
SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category`
|
||||
');
|
||||
$data = array();
|
||||
foreach ($categories as $category)
|
||||
foreach ($shops as $shop)
|
||||
$data[] = array(
|
||||
'id_category' => $category['id_category'],
|
||||
'id_shop' => $shop['id_shop']
|
||||
);
|
||||
Db::getInstance()->insert('category_shop', $data);
|
||||
if(is_array($shops) && is_array($categories))
|
||||
{
|
||||
foreach ($categories as $category)
|
||||
foreach ($shops as $shop)
|
||||
$data[] = array(
|
||||
'id_category' => $category['id_category'],
|
||||
'id_shop' => $shop['id_shop']
|
||||
);
|
||||
Db::getInstance()->insert('category_shop', $data);
|
||||
}
|
||||
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'category`
|
||||
@@ -90,4 +96,4 @@ function generate_root_category_for_multishop()
|
||||
');
|
||||
|
||||
generate_ntree();
|
||||
}
|
||||
}
|
||||
@@ -160,22 +160,24 @@ function p15012_add_missing_columns()
|
||||
if (empty($table))
|
||||
continue;
|
||||
$list_fields = $db->executeS('SHOW FIELDS FROM `'._DB_PREFIX_.$table.'`');
|
||||
foreach($list_fields as $k => $field)
|
||||
$list_fields[$k] = $field['Field'];
|
||||
foreach ($cols as $col => $q)
|
||||
{
|
||||
// do only if column exists
|
||||
if (in_array($col, $list_fields))
|
||||
$do = 'mod';
|
||||
else
|
||||
$do = 'add';
|
||||
|
||||
if (!empty($q[$do]))
|
||||
if (is_array($list_fields))
|
||||
foreach($list_fields as $k => $field)
|
||||
$list_fields[$k] = $field['Field'];
|
||||
if (is_array($cols))
|
||||
foreach ($cols as $col => $q)
|
||||
{
|
||||
if (!$db->execute($q[$do]))
|
||||
$errors[] = '<subquery><query>'.$q[$do].'</query><error>'.$db->getMsgError().'</error></subquery>';
|
||||
// do only if column exists
|
||||
if (is_array($list_fields) && in_array($col, $list_fields))
|
||||
$do = 'mod';
|
||||
else
|
||||
$do = 'add';
|
||||
|
||||
if (!empty($q[$do]))
|
||||
{
|
||||
if (!$db->execute($q[$do]))
|
||||
$errors[] = '<subquery><query>'.$q[$do].'</query><error>'.$db->getMsgError().'</error></subquery>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof($errors) > 0)
|
||||
@@ -185,5 +187,4 @@ function p15012_add_missing_columns()
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user