我的 Magento 扩展安装脚本将无法运行

发布于 2024-10-12 08:03:38 字数 916 浏览 4 评论 0原文

我正在尝试为我的扩展创建安装脚本,但由于某种原因它不会是安装脚本。该扩展将显示在 core_resource 表中,但我尝试创建的属性不会创建。

我非常确定该脚本甚至没有被调用,因为我在开头放置了 exit() 并且站点运行得很好。

这是我的配置 XML 文件中的内容。这被放置在 global -> 里面资源路径:

<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();

我在这里是否遗漏了一些明显的东西,这将是脚本无法运行的原因?

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.

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.

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>

My install script is as follows:

$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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

七七 2024-10-19 08:03:38

仔细阅读本文,确保您对设置资源的用途和作用没有任何误解工作,以及如何解决这些问题。

完成此操作后,从您在此问题线程中所说的所有内容来看,听起来您正在“安装”资源,但您的安装脚本从未运行。我的猜测是您使用的版本号

//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 的逻辑并找出该类不包含安装程序文件的原因。

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

didn't match up with the version of your module

<modules>
    <Nie_Nie>
        <version>?.?.?</version>
    </Nie_Nie>
</modules>

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.

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.");

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)

If that doesn't work, start digging into the logic of applyAllDataUpdates and figure out why the class isn't including your installer file.

无戏配角 2024-10-19 08:03:38

当我遇到这个问题时,我实际上不得不禁用缓存。无论出于何种原因,仅仅冲洗它都没有帮助。

When I encountered this problem I acually had to disable the cache. Merely flushing it did not help for whatever reason.

岁吢 2024-10-19 08:03:38

追踪此错误的最简单且信息最丰富的方法是 设置您的 IDE 来调试 Magento 并在 mysql4-install-0.0.1.php 中设置断点。如果没有命中断点,那么您就知道问题是否出在您的 XML 配置中。如果断点确实被击中,您可以跟踪代码以查找错误源。

设置可能需要半天时间,但 Magento 的实时调试是迄今为止学习和理解代码的最佳方式。帮自己一个忙,现在就进行投资。

The easiest and most informative way to track down this error is to setup your IDE to debug Magento and set a breakpoint in your mysql4-install-0.0.1.php. If the breakpoint doesn't get hit, then you know if the issue is in your XML config. If the breakpoint does get hit, you can trace through the code to find the source of the error.

It may take you half a day to setup, but live debugging of Magento is by far the best way to learn and understand the code. Do yourself a favour, make the investment now.

提笔书几行 2024-10-19 08:03:38

根据 Magento 知识库 您可以尝试在 中包含 标记。通过这种方式,您可以确保使用正确的安装模型,并且(如果能做到这一点)将模型传递到您的安装脚本,从而无需手动创建 $setup

检查安装脚本的文件权限及其所在目录。有时我发现从 core_resources 中删除记录也有助于启动该过程。

As per Magento Knowledgebase you could try including a <class> tag in your <setup>. This way you can ensure the correct setup model is used and (if it gets that far) passes the model to your install script negating the need to create a $setup manually.

Check the file permissions of the install script and the directory it is in. I sometimes find deleting the record from core_resources helps kick start the process too.

梦行七里 2024-10-19 08:03:38

您可以在 Magento 中检查加载了哪些模块以及加载了哪个版本的模块:

  1. 转到 app/code/core/Mage/Core/Model/Resource/Setup.php
  2. 转到函数 __construct()
  3. 在函数末尾写入:

    法师::log($modName);
    Mage::log($this->_moduleConfig);

它将记录使用该版本号加载的所有模块。在这里您可以检查您的模块是否已加载。

You can check in Magento whcih modules are loaded and which version of that module is loaded:

  1. Go to app/code/core/Mage/Core/Model/Resource/Setup.php
  2. Go to function __construct()
  3. At the end of function write:

    Mage::log($modName);
    Mage::log($this->_moduleConfig);

It will log all the modules loaded with there version number. Here you can check if your module is loaded or not.

并安 2024-10-19 08:03:38

您应该将模块的版本向上更改一点,以使更新脚本得以执行。

<modules>
    <Nie_Nie>
        <version>1.5.0.0</version>
    </Nie_Nie>
</modules>

如果此版本等于 core_resources 表中的资源版本,则升级脚本将不会执行。并且版本应该与您的升级脚本的名称匹配

You should change the version of your module one point up, to make your update script execute.

<modules>
    <Nie_Nie>
        <version>1.5.0.0</version>
    </Nie_Nie>
</modules>

If this version is equals to the resource version from core_resources table upgrade script will not execute. And the version should match the name of your upgrade script

神爱温柔 2024-10-19 08:03:38

我们的商店 http://www.looxis.de 也遇到了同样的问题
为了更新我们正在使用的扩展,我们通过 FTP 传输了所有文件,但数据库在清除缓存后不会自行更新。所以更新后的扩展无法运行,我们无法登录后端。

在寻找解决方案时,我们找到了此页面。

问题是,我们在几周前安装了该模块的较新版本,由于与其他模块发生冲突,这也产生了错误,因此我们从数据库备份中部分转回了一些表,并且还放回了旧文件。一切又恢复正常,

当我们尝试新更新模块时,该模块现在与其他扩展兼容(冲突已删除),sql 更新脚本将无法运行。

这是由于表“core_resources”造成的。在那里,模块版本号被设置为我们几周前安装的最新版本 - 所以magento不会识别出再次执行了新的更新,它假设最新版本已经存在。

我们手动将版本号更改为较低版本,然后,升级脚本启动,一切正常!

We had the same problem for our store http://www.looxis.de
To update an extension that we have in use we transfered all files via FTP, but the database wouldn't update itself after clearing the cache. So the updated extension failed to run, we couldn't login into the backend.

Searching for a solution we found this page.

The problem was, that we installed a newer version of the module a few weeks before, which also produced errors due to a conflict with other modules, so we transferred back partially from our database backup some tables and we also put back the old files. everything was working again,

when we tried to newly update the module, which was now compatible with the other extension (conflict was removed) the sql update script wouldn't run.

This was due to the table "core_resources." in there, the module version number was set to the newest version that we had installed weeks before - so magento wouldn't recognise that a new update had been performed again, it assumed the newest version was already there.

We manually changed the version number to a lower version, and boom, the upgrade script initiated and everything was working fine!

隐诗 2024-10-19 08:03:38

请务必检查您的 app/etc/modules 文件,确保模块名称准确并且代码池指定准确。

Make sure to check your app/etc/modules file, make sure the name of your module is accurate and that the codepool is accurately specified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文