我正在尝试为我的扩展创建一个安装脚本,但出于某种原因,它不是安装脚本。扩展将显示在 core_resource 表中,但我尝试创建的属性不会创建。
我很确定脚本甚至没有被调用,因为我在开头放置了一个 exit() 并且站点运行正常。
这是我的配置 XML 文件中的内容。这放在全局 -> 资源路径中:
<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();
我在这里明显遗漏了什么是脚本无法运行的原因吗?
最佳答案
努力完成 this article以确保您对设置资源的作用、它们的工作方式以及如何解决它们没有任何误解。
完成此操作后,从您在此问题线程中所说的一切来看,听起来您正在“安装”您的资源,但您的安装脚本永远不会运行。我的猜测是您在
中使用的版本号//0.0.1 is your version number
mysql4-install-0.0.1.php
与你的模块版本不匹配
<modules>
<Nie_Nie>
<version>?.?.?</version>
</Nie_Nie>
</modules>
那些应该与要运行的脚本匹配。我认为Magento 足够聪明,可以在找到它们时运行以前的版本,但设置资源中的代码是那种难以遵循的代码,因此我始终确保它们匹配。
无论如何,您可以通过以下方式查看 magento 在运行您的设置资源时尝试运行的文件。从 core_resource
中删除与您的模块相关的任何条目。清除缓存。然后在setup类中找到如下位置
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;
}
然后修改它们以添加一些临时调试异常
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 缓存哪些模块需要检查安装/升级)
如果这不起作用,请开始深入研究 applyAllDataUpdates
的逻辑并弄清楚为什么该类不包含您的安装程序文件。
关于php - 我的 Magento 扩展安装脚本将无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4717535/