0

When I write a module and refresh Magento it begins to install it. What happens if I refresh Magento before installation is over? Does it start the installation process again while the other one continues?

I'm asking because when adding a large data set of attributes after refreshing the Magento page I realised that the values are duplicated in the table. Like if Magento ignored the install in progress and went ahead and started another one (without aborting the first one.)

3 Answers 3

2

You can use transactions functionality

try {
    $installer->getConnection()->beginTransaction();
    $installer->run("
        your sql code here
    ");
    $installer->getConnection()->commit();
} catch (Exception $e) {
    $installer->getConnection()->rollback();
    throw $e;
}
2
  • I'm using $installer->addAttribute(...) method to add a new attribute to the product entity. Can I still use the beginTransaction and commit like above and just substitute the $installer->run line? Commented May 7, 2015 at 15:17
  • yes, it can be used. you can check app\code\core\Mage\Sales\sql\sales_setup\mysql4-upgrade-1.3.99-1.4.0.0.php for an example. just run a search for beginTransaction Commented May 7, 2015 at 15:44
1

Yes, it does. Even if someone other than you refreshes any page while your script is working, it will run duplicate installation.

Better way is to check whether your attribute (or whatever entity you create) was already created in database and act accordingly. It will serve you in future, not only in case you suddenly restart or initialize duplicate installing process.

1
  • Thanks, clears it up :) Had a nightmare last night where I refreshed a couple of times and the upgrade lasted ages! Will start checking to make sure the attribute hasn't been created, hopefully won't happen again :) Commented May 7, 2015 at 15:55
0

The best practice is to upload the modules xml file found in /app/etc/modules/ at the end when all other files are successfully uploaded. you will never get module installation errors.

Your Answer

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

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