php - 如何在 Prestahop 模块上重新安装数据库?
问题描述
我正在尝试自定义 Prestashop 模块,我需要在表中添加两个新的冒号。
问题是数据库已经创建,我猜它是在模块初始化时创建的。因此,如果我现在更改代码,则不会出现更改,并且我不断收到此错误:
在配置中没有办法做到这一点,我想如果我删除模块,我的代码将会消失。
我能怎么做 ?
也许在一个通用方法中询问 delete 和 create 方法(仅一次)。
我是 Smarty 和 PHP 的新手,我发现这不是创建表的常用方法。
你可以帮帮我吗 ?
我是 Smarty 的新手,我该怎么做?看起来这不是创建表的方法。
$sql = array();
$sql[] =
'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'opartdevis` (
`id_opartdevis` int(10) NOT NULL AUTO_INCREMENT,
`id_shop` int(10) NOT NULL,
`id_cart` int(10) NOT NULL,
`id_customer` int(10) NOT NULL,
`name` varchar(128),
`message_visible` TEXT,
`id_customer_thread` int(10),
`date_add` DATETIME NOT NULL,
`status` int(2) DEFAULT 0,
`id_order` int(10) NULL,
`id_ordered_cart` int(10) NULL,
`remise` int(10),
`delivery` int(10),
PRIMARY KEY (`id_opartdevis`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';
//1.6.1.0 specific price bug fix
if (version_compare(_PS_VERSION_, '1.6.1.0', '=')) {
$sql[] = "ALTER TABLE "._DB_PREFIX_."specific_price DROP INDEX id_product_2";
$sql[] = "ALTER TABLE "._DB_PREFIX_."specific_price ADD INDEX id_product_2 (id_product,id_shop,id_shop_group,id_currency,id_country,id_group,id_customer,id_product_attribute,from_quantity,id_specific_price_rule,id_cart,`from`,`to`)";
}
foreach ($sql as $s) {
if (!Db::getInstance()->execute($s)) {
return false;
}
}
提前致谢
马拉里
解决方案
卸载模块时需要还原所有数据库更改。
uninstall()
在基本模块文件中定义(或附加到现有)函数并DROP TABLE
在创建的表上运行查询。例子:
public function uninstall() {
if (!parent::uninstall()) {
return false;
}
$sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'opartdevis`';
if (!Db::getInstance()->execute($sql)) {
return false;
}
return true;
}
这样,当您卸载模块时,该表将被删除(并在您再次安装时重新创建)。
推荐阅读
- reactjs - 使用 React 测试库测试 Stripe
- yq - 如何使用 yq 搜索 yml 文件中的键中是否存在特定单词
- android - 尝试在空对象引用上调用虚拟方法 'void com.android.server.am.TaskRecord.setIntent(com.android.server.am.ActivityRecord)'
- amazon-web-services - 为什么缩减保护不适用于实例
- scala - 如何从 Scala 中的 Kafka 主题中读取数据
- python - 使用 Pyvmomi 为访客定义 Pvlan ID
- html - 放大此图像但仍使其居中?
- python - 如何通过比较不同数据框中的列来创建虚拟变量?
- scikit-learn - 我们可以改装或适应零件聚类算法吗?
- excel - VBA运行时错误9:下标超出范围