The requirement is that I want to execute a script upon the installation of my extension. But I want to make sure that it runs only once and then never again.

I tried doing this via Setup Resources. But apparently, it runs not only when the user installs the extension but also when the clears the cache and other actions etc.


class My_Module_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
    function __construct($arg)
        # Code that I want to run only once

Is there a specific way to achieve this without having to write stuff to the database?


Don't use the constructor for that.
Using the constructor will make it run every time you instantiate the class and that happens each time the module is checked to see if an upgrade is needed.

Let's say your module declared version in config.xml is 1.0.0.
You need to create the file sql/[module]_setup/install-1.0.0.php where you can run your script.
This is procedural coding so you don't need to create classes. But $this still references the class My_Module_Model_Resource_Setup.

  • Well, I changed the name of the function to new_name and then called it inside my sql/[module]_setup/install-1.0.0.php file. Its not getting executed anymore. Any ideas? – satnam Aug 1 '17 at 20:44
  • Actually never mind, I think I figured it out. Thx :) – satnam Aug 1 '17 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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