Jos*_*ton 30 php installation attributes install magento
我正在尝试为我的扩展创建一个安装脚本,由于某种原因它不会安装脚本.扩展将显示在core_resource表中,但我尝试创建的属性将不会创建.
我很确定脚本甚至没有被调用,因为我在开头放了一个exit()并且网站运行得很好.
这是我在配置XML文件中的内容.这位于global - > resources路径中:
<nie_setup>
<setup>
<module>Nie_Nie</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</nie_setup>
Run Code Online (Sandbox Code Playgroud)
我的安装脚本如下:
$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();
Run Code Online (Sandbox Code Playgroud)
有没有明显的东西我在这里失踪,这将是脚本无法运行的原因?
Ala*_*orm 73
按照本文的说明进行操作,以确保您不会对设置资源的作用,工作方式以及如何对其进行故障排除有任何误解.
一旦你完成了这一切,从你在这个问题线程中所说的一切,听起来你正在"安装"你的资源,但你的安装脚本永远不会运行.我的猜测是你使用的版本号
//0.0.1 is your version number
mysql4-install-0.0.1.php
Run Code Online (Sandbox Code Playgroud)
与您的模块版本不匹配
<modules>
<Nie_Nie>
<version>?.?.?</version>
</Nie_Nie>
</modules>
Run Code Online (Sandbox Code Playgroud)
那些应匹配脚本运行.我认为 Magento足够智能,如果找到它们就可以运行以前的版本,但是设置资源中的代码是那种难以理解的,所以我总是确保它们匹配.
无论如何,这里是你如何看到magento运行你的设置资源时试图运行的文件.删除core_resource与模块相关的所有条目.清除缓存.然后在安装程序类中找到以下位置
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;
}
Run Code Online (Sandbox Code Playgroud)
然后修改它们以添加一些临时调试异常
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.");
Run Code Online (Sandbox Code Playgroud)
重新加载页面,你会得到异常文本抱怨Magento无法找到的任何内容.这应该足以帮助您跟踪Magento尝试运行的安装程序脚本,但无法找到.只需记住删除模块的行core_resource并清除缓存.(Magento缓存哪些模块需要检查安装/升级)
如果这不起作用,请开始深入了解逻辑applyAllDataUpdates并找出该类不包含安装程序文件的原因.
Jon*_*Day 14
追踪此错误的最简单,最有用的方法是设置IDE以调试Magento并在您的设置中设置断点mysql4-install-0.0.1.php.如果断点没有被击中,那么您就知道问题是否在您的XML配置中.如果断点确实被击中,您可以跟踪代码以找到错误的来源.
设置可能需要半天时间,但Magento的实时调试是学习和理解代码的最佳方式.帮自己一个忙,立即投资.