我的 Magento 扩展安装脚本无法运行 [英] My Magento Extension Install Script Will Not Run

查看:26
本文介绍了我的 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 文件中的内容.这是放在 global -> 资源路径中:

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 扩展安装脚本无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆