Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I found an interesting behavior today: I accidently named a data upgrade script data-upgrade-0.1.20-0.1.20.php where it should have been data-upgrade-0.1.19-0.1.20.php, and it actually has been applied.

And as I cannot find a question here that can be used as a reference for the setup script version logic (correct me if I'm wrong), let's use this one.

By which logic does Magento execute the install and upgrade scripts?

Especially interesting edge case: When and why are scripts like upgrade-1.0.0-1.0.0.php executed, where the "from" version number is equal to the "to" version number?

share|improve this question
    
wow thats weird. Data upgrades are only executed if the version_compare returns 1. Equal should return 0. –  Sander Mangel yesterday
    
That's what I would expect. But the current version was 0.1.19, so it makes sense that the version_compare check returned 1. –  fschmengler yesterday

1 Answer 1

The method that calls the upgrades (at least one in the chain) is this in Mage_Core_Model_Resource_Setup

public function applyDataUpdates()
{
    $dataVer= $this->_getResource()->getDataVersion($this->_resourceName);
    $configVer = (string)$this->_moduleConfig->version;
    if ($dataVer !== false) {
         $status = version_compare($configVer, $dataVer);
         if ($status == self::VERSION_COMPARE_GREATER) {
             $this->_upgradeData($dataVer, $configVer);
         }
    } elseif ($configVer) {
        $this->_installData($configVer);
    }
    return $this;
}

Your module had the version ($configVer) 0.1.19, so magento reads all the available scripts in the sql folder and the file 0.1.20-0.1.20 matched the condition if ($status == self::VERSION_COMPARE_GREATER) { because the $configVer variable is not incremented after each script executes.
So it always compares to 0.1.19 until the upgrade finishes.

Side note: this is a crazy one indeed.

share|improve this answer
1  
nice one! But yeah, kinda weird it doesn't update the from during upgrade –  Sander Mangel yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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