My Magento Extension Install Script Will Not Run(我的 Magento 扩展安装脚本将无法运行)
问题描述
我正在尝试为我的扩展程序创建一个安装脚本,但由于某种原因它不会是安装脚本.扩展将显示在 core_resource 表中,但我尝试创建的属性不会创建.
I am trying to create an install script for my extension and for some reason it will not the install script. The extension will show up in the core_resource table, but the attributes I am trying to create will not create.
我很确定脚本甚至没有被调用,因为我在开头放了一个 exit() 并且网站运行得很好.
I am pretty sure that the script is not even being called because I put an exit() at the beginning and the site ran just fine.
这是我的配置 XML 文件中的内容.这被放置在全局 -> 资源路径中:
Here is what I have in my config XML file. This is placed inside global -> resources path:
<nie_setup>
<setup>
<module>Nie_Nie</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</nie_setup>
我的安装脚本如下:
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$setup->addAttribute('customer', 'nie_admin', array(
'input' => 'text',
'type' => 'text',
'backend' => '',
'visible' => 0,
'required' => 0,
'user_defined' => 1,
));
$installer->endSetup();
我在这里遗漏了什么明显的东西是脚本无法运行的原因吗?
Is there something obvious I am missing here that would be the reason the script will not run?
推荐答案
通过这篇文章来制作确保您对设置资源的作用、它们的工作方式以及如何解决它们没有任何误解.
Work your way through this article to make sure you don't have any misunderstanding of what the setup resources do, how they work, and how you can troubleshoot them.
一旦你这样做了,从你在这个问题线程上所说的一切来看,听起来你正在安装"你的资源,但你的安装脚本永远不会运行.我的猜测是您在
Once you've done that, from everything you've said on this question thread it sounds like you're getting your resource "installed", but that your install script never runs. My guess is that the version number you used in
//0.0.1 is your version number
mysql4-install-0.0.1.php
与您的模块版本不匹配
<modules>
<Nie_Nie>
<version>?.?.?</version>
</Nie_Nie>
</modules>
这些应该匹配脚本才能运行.我认为 Magento 足够聪明,可以在找到以前的版本时运行它们,但是设置资源中的代码很难理解,所以我总是确保它们匹配.
Those should match for the script to run. I think Magento is smart enough to run previous versions if it finds them, but the code in the setup resources is the kind that's hard to follow, so I always make sure they match.
无论如何,您可以通过以下方式查看 magento 在运行您的设置资源时尝试运行的文件.从 core_resource
中删除与您的模块相关的所有条目.清除缓存.然后在setup类中找到如下位置
Regardless, here's how you can see which file(s) magento is trying to run when it runs your setup resource. Delete any entries from core_resource
related to your module. Clear your cache. Then find the following locations in the setup class
app/code/core/Mage/Core/Model/Resource/Setup.php:
protected function _modifyResourceDb($actionType, $fromVersion, $toVersion)
{
...
$sqlFilesDir = Mage::getModuleDir('sql', $modName).DS.$this->_resourceName;
if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) {
return false;
}
...
$sqlDir->close();
if (empty($arrAvailableFiles)) {
return false;
}
...
$arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
if (empty($arrModifyFiles)) {
return false;
}
然后修改它们,添加一些临时调试异常
and then modify them to add some temporary debugging exceptions
if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) {
throw new Exception("$sqlFilesDir not found");
return false;
}
...
if (empty($arrAvailableFiles)) {
throw new Exception("No files found to run");
return false;
}
...
$arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
if (empty($arrModifyFiles)) {
throw new Exception("No valid upgrade files found to run for ");
return false;
}
throw new Exception("If you're getting here, we have a file. Remove your exceptions here and place one in your installer to make sure it's the one you think it is.");
重新加载页面,您将收到异常文本,抱怨 Magento 找不到的任何内容.这应该足以帮助您跟踪 Magento 正在尝试运行但未能找到的安装程序脚本.请记住删除 core_resource
中的模块行并清除缓存.(Magento 缓存哪些模块需要检查安装/升级)
Reload the page and you'll get exception text complaining about whatever Magento can't find. That should be enough to help you track down which installer script Magento is trying to run, but failing to find. Just remember to delete your module's row in core_resource
and to clear your cache. (Magento caches which modules need to check for an install/upgrade)
如果这不起作用,请开始深入研究 applyAllDataUpdates
的逻辑并找出该类不包含您的安装程序文件的原因.
If that doesn't work, start digging into the logic of applyAllDataUpdates
and figure out why the class isn't including your installer file.
这篇关于我的 Magento 扩展安装脚本将无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我的 Magento 扩展安装脚本将无法运行
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01