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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4717535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 14:07:33  来源:igfitidea点击:

My Magento Extension Install Script Will Not Run

phpmagentoattributesinstallationinstall

提问by Josh Pennington

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.

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

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.

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

Here is what I have in my config XML file. This is placed inside global -> resources path:

这是我的配置 XML 文件中的内容。这放置在 global -> resources 路径中:

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

是否有明显我在这里遗漏的东西是脚本无法运行的原因?

回答by Alan Storm

Work your way through this articleto 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 thinkMagento 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 足够聪明,如果它找到它们就可以运行以前的版本,但是设置资源中的代码很难理解,所以我总是确保它们匹配。

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_resourcerelated to your module. Clear your cache. Then find the following locations in the setup class

无论如何,以下是您如何查看 magento 在运行您的安装资源时尝试运行的文件。删除core_resource与您的模块相关的任何条目。清除缓存。然后在setup类中找到以下位置

app/code/core/Mage/Core/Model/Resource/Setup.php:

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_resourceand to clear your cache. (Magento caches which modules need to check for an install/upgrade)

重新加载页面,您将收到异常文本,抱怨 Magento 找不到的任何内容。这应该足以帮助您追踪 Magento 试图运行的安装程序脚本,但未能找到。请记住删除模块所在的行core_resource并清除缓存。(Magento 缓存哪些模块需要检查安装/升级)

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

如果这不起作用,请开始深入研究 的逻辑applyAllDataUpdates并弄清楚为什么该类不包含您的安装程序文件。

回答by Bj?rn Tantau

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

当我遇到这个问题时,我不得不禁用缓存。无论出于何种原因,仅仅冲洗它都无济于事。

回答by Jonathan Day

The easiest and most informative way to track down this error is to setup your IDE to debug Magentoand 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.

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

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.

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

回答by Arvind Bhardwaj

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

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

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

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

    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.

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

回答by clockworkgeek

As per Magento Knowledgebaseyou 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 $setupmanually.

根据Magento 知识库,您可以尝试<class><setup>. 通过这种方式,您可以确保使用正确的安装模型,并且(如果它达到了那个程度)将模型传递给您的安装脚本,从而无需$setup手动创建。

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

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

回答by Eugene Tulika

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_resourcestable upgrade script will not execute. And the version should match the name of your upgrade script

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

回答by Etienne Renaud

We had the same problem for our store http://www.looxis.deTo 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.

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

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.

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

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.

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

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

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

回答by Coolster

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.

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