30

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?

3
  • Please post the location of your install script
    – Joe Mastey
    Jan 17, 2011 at 23:04
  • /app/code/local/Nie/Nie/sql/nie_setup/mysql4-install-0.0.1.php Jan 17, 2011 at 23:26
  • 2
    Make sure the case of your module name inside <modules> has the same case as your <module> in your resources config. I just ran into this issue myself. Jul 16, 2015 at 16:04

8 Answers 8

73
+50

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.

7
  • 5
    Your debugging methods told me that I had my script in the wrong directory. Thank you so much! I get to continue being employed for one more day! Jan 24, 2011 at 13:41
  • 2
    Great answer, Alan. Don't you think that there should be like a strict mode where you can tell Magento to complain at you if you attempt to set something up and it isn't setup right? Upgrade scripts, routes, themes, there are all sorts of things that are tough to setup your first time around and it would be great to be able to get Magento to just complain at you about specifically what the problem is. I think a module that did this would be awesome. Aug 29, 2012 at 0:23
  • 2
    I would agree with sparcksoft about Magento failing such silently, even an entry to a log file would be worth the effort. I still don't like how Magento will blindly install anything that matches without some sort of checksum. Also just a tip most don't realize you can use .sql instead of .php for your install files if your just doing raw SQL on updates/installs.
    – B00MER
    Aug 29, 2012 at 23:17
  • 2
    Don't forget to clear the Magento cache.. Even if we know we should, it is usual to forget it! Jan 15, 2013 at 15:36
  • 2
    @PratikCJoshi This article has information on how to trace the full path in more modern versions of Magento. vinaikopp.com/2014/11/03/magento-setup-scripts Jul 17, 2015 at 14:42
16

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

1
  • spot on mateyyy
    – tread
    Oct 4, 2016 at 14:24
15

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.

1
  • Should be noted that live debugging is not possible if the code-base is using the rubbish IonCube zend module (that many poorly designed third party modules require). Dec 7, 2015 at 14:45
3

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.

0
3

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.

2

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

2
  • I tried changing the version number and that did not run the script. It just changed the version number in the core_resources table. Jan 17, 2011 at 22:36
  • Some more obvious questions: is your upgrade script inside sql/nie_setup dir? is your module dir is app/code/local/Nie/Nie? Jan 17, 2011 at 22:46
1

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!

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.