Magento无法运行SQL安装/更新脚本。

5
我有一个问题,与配置或其他事情有关,那就是magento从未运行我的模块的SQL安装/更新脚本! 我使用的是magento-1.4.1.0版本。 以下是我的文件夹和文件结构:
\app\code\local\RN\ShortUrl
\app\code\local\RN\ShortUrl\Block\ShortUrl.php

\app\code\local\RN\ShortUrl\controllers\IndexController.php
\app\code\local\RN\ShortUrl\controllers\UController.php

\app\code\local\RN\ShortUrl\etc\config.xml

\app\code\local\RN\ShortUrl\Helper\Url.php

\app\code\local\RN\ShortUrl\Model\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl\Collection.php

\app\code\local\RN\ShortUrl\Model
\app\code\local\RN\ShortUrl\Model\Mysql4
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl

\app\code\local\RN\ShortUrl\sql\rn_shorturl_setup\mysql4-install-0.1.0.php

以下是\app\etc\modules\RN_ShortUrl.xml的内容:
<?xml version="1.0" encoding="UTF-8"?>    
<config>
    <modules>
        <RN_ShortUrl>
            <active>true</active>
            <codePool>local</codePool>
        </RN_ShortUrl>
    </modules>
</config>

以下是\app\code\local\RN\ShortUrl\etc\config.xml的内容:
<?xml version="1.0"?>
<config>
<modules>
    <RN_ShortUrl>
        <version>0.1.0</version>
    </RN_ShortUrl>
</modules>
<frontend>
    <routers>
        <shorturl>
            <use>standard</use>
            <args>
                <module>RN_ShortUrl</module>
                <frontName>shorturl</frontName>
            </args>
        </shorturl>
    </routers>
    <layout>
        <updates>
            <shorturl>
                <file>shorturl.xml</file>
            </shorturl>
        </updates>
    </layout>
</frontend>
<global>
    <blocks>
        <rn_shorturl>
            <class>RN_ShortUrl_Block</class>
        </rn_shorturl>
    </blocks>
    <rewrite>
        <rn_shorturl>
            <from>#^/u/(.*)#</from>
            <to>/shorturl/u/redirect/key/$1</to>
        </rn_shorturl>
    </rewrite>

    <models>
        <shorturl>
            <class>RN_ShortUrl_Model</class>
            <resourceModel>shorturl_mysql4</resourceModel>
        </shorturl>
        <shorturl_mysql4>
            <class>RN_ShortUrl_Model_Mysql4</class>
            <entities>
                <shorturl>
                    <table>shorturl</table>
                </shorturl>
            </entities>
        </shorturl_mysql4>
    </models>
    <resources>
        <shorturl_setup>
            <setup>
                <module>RN_ShortUrl</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </shorturl_setup>
        <shorturl_write>
            <connection>
                <use>core_write</use>
            </connection>
        </shorturl_write>
        <shorturl_read>
            <connection>
                <use>core_read</use>
            </connection>
        </shorturl_read>
    </resources>
    <helpers>
        <shorturl>
            <class>RN_ShortUrl_Helper</class>
        </shorturl>
    </helpers>
</global>

这是我的安装 SQL 脚本:
<?php
    $installer = $this;
    $installer->startSetup();

    $installer->run("
            DROP TABLE IF EXISTS {$this->getTable('shorturl')};
            CREATE TABLE {$this->getTable('shorturl')} (
            `shorturl_id` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
            `shorted_key` VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '',
            `long_url` VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '',
            PRIMARY KEY (`shorturl_id`),
            INDEX (shorted_key),
            INDEX (long_url)
            )ENGINE=InnoDB CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';"
    );

    /* right before this */
    $installer->endSetup();

我已经尝试更改我的模块版本并创建了升级脚本“mysql4-upgrade-1.0-1.1.php”,但仍然无法正常工作,但我可以运行我的模块。

http://magento.test/shorturl/index/generate/?url=http://realestate.cambodiachic.com/property-detail-hotel-restaurant-on-kampot-river-93.html

除了我提出的问题之外,这个程序运行正常。谢谢你的帮助。
提前感激,
Rithy

1
提示:如果您想得到问题的答案,请不要在标题中使用“紧急”等词汇。 - NullUserException
2个回答

4
我注意到你在更改版本号时,创建了一个1.0-1.1的升级程序,但实际上你的版本是0.1.0。这可能解释了为什么它没有“升级”。你可以考虑从核心资源中完全删除该行,并让它在下一次页面加载时“重新安装”自己。
或者,修改你的脚本,使其标记为从0.1.0-0.1.1的升级版本。

如何从核心资源中完全删除行? 我的数据库在vm ware中,目前我不知道如何访问查看数据库... - Rithy
你需要确保你的当前版本也是正确的。如果你之前从0.1.0升级到了0.1.1,那么当前版本可能是0.1.1,这种情况下你的脚本应该被命名为mysql4-upgrade-0.1.1-0.2.1.php。如果你的版本号不对,无论是新的还是旧的,脚本都无法运行。 - Joe Mastey
好的,我尝试了很多次,但脚本仍然无法运行 :( 不管怎样,感谢您的帮助! - Rithy
好的,那么您应该找到数据库的凭证并从 core_resources 表中删除该行。在下一次页面加载时,Magento 将完全重新安装插件。 - Joe Mastey
好的,现在我可以解决这个问题了!
  1. 在我的模型中,我尝试创建一个函数来删除core_resources表中的记录。
  2. 将文件夹\app\code\local\RN\ShortUrl\sql\rn_shorturl_setup更改为\app\code\local\RN\ShortUrl\sql\shorturl_setup。
最终我解决了它!欢呼!
- Rithy
显示剩余3条评论

3

好的,现在我可以解决这个问题了!

  1. 在我的模型中,我尝试创建一个函数来删除core_resources表中的记录,我们可以从我们的helper中使用/调用它。

\app\code\local\RN\ShortUrl\Model\ShortUrl.php

    public function removeShortedUrlModule()
    {
        $sql = "DELETE FROM `core_resource`
        WHERE `code`='shorturl_setup';";
        $connection = Mage::getSingleton('core/resource')->getConnection('core_write');     
        try {
            $connection->query($sql);
            die('deleted module in core_resource!');
        } catch (Exception $e){
            echo $e->getMessage();
        }
    }

2. 修改文件夹名称 \app\code\local\RN\ShortUrl\sql\rn_shorturl_setup\

改为 \app\code\local\RN\ShortUrl\sql\shorturl_setup\

最终问题解决!加油!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接