5

I have problem with configuration or something else that magento never run my module's sql install/update script!

I use magento-1.4.1.0

Here is my structure folders and files:

\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

Here are the contents of \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>

Here are the contents of \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>

Here is my install SQL script:

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

I have tried to change my module's version and created the upgrade script "mysql4-upgrade-1.0-1.1.php" but still not working, but I could run my module.

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

It's working except the problem I am asking.

Thanks in advance,

Rithy

1
  • 1
    Tip: if you want to get questions answered, do not put words like "Urgent" in the title Commented Sep 1, 2010 at 3:17

2 Answers 2

4

I noticed that when you changed your version number you created an upgrade for 1.0-1.1, but your version is actually 0.1.0. That may explain why it didn't "upgrade". You may want to delete the row entirely from core resource and let it "reinstall" itself on the next page load.

Or, amend your script so that it is tagged as an upgrade from 0.1.0-0.1.1.

Sign up to request clarification or add additional context in comments.

8 Comments

how to delete the row entirely from the core resource? My database is in vm ware and currently I don't know how to access to see the database...
If you don't have database access, fixing your upgrade script to use the correct versions will be the easiest route.
Could you provide me some concept of naming the upgrade script file? currently my module's version in 0.2.1 and I created a file name mysql4-upgrade-0.2.0-0.2.1.php but it's still not run.
You need to make sure that you have the current version correct as well. If you previously had moved from 0.1.0 to 0.1.1 the current version is probably 0.1.1, in which case your script should be called mysql4-upgrade-0.1.1-0.2.1.php. If you have the wrong version for either the new or the old one, the script won't run.
OK, thanks I got it, I'm checking what is my current version in database by creating backup database in backend and check. Then what I shoud do is to set in the module's version is the next version I want, and the script file should be name "mysql4-upgrade-[current_version in database]-[next_version in the config].php" right?
|
3

OK, Now I can solve this problem!

  1. In my model, I've tried to create a function to delete the record in the core_resources table which we could use/call from our 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 . Change folder name \app\code\local\RN\ShortUrl\sql\ rn_shorturl_setup\

To \app\code\local\RN\ShortUrl\sql\ shorturl_setup\

Finally I soved it! CHEER!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.