1) Can there be multiple install scripts in the custom module? For example:
- data-install-1.0.0.php
- data-install-1.0.1.php
2) Assuming I have the following scripts inside app/code/local/Company/Helloworld/data/helloworld_setup:
- data-install-1.0.0.php
- data-install-1.0.1.php
- data-install-1.0.2.php
- data-install-2.0.0.php
- data-upgrade-1.0.0-1.0.1.php
- data-upgrade-1.0.1-1.0.2.php
- data-upgrade-1.0.2-2.0.0.php
- data-upgrade-2.0.0-2.0.1.php
Questions:
2.1) I already have version 1.0.0 of this module installed in my Magento:
<config>
<modules>
<Company_Helloworld>
<version>1.0.0</version>
</Company_Helloworld>
</modules>
...
</config>
What will be the order of execution of these scripts when:
2.1.a) I install version 1.0.2
2.1.b) I install version 2.0.0
2.2) I don't have any version of this module installed yet.
What will be the order of execution of these scripts when:
2.2.a) I install version 1.0.0
2.2.b) I install version 2.0.0
2.2.c) I install version 3.0.0
3) I've seen in Magento core modules, the sql install scripts are named in two ways:
- mysql4-install-1.0.0.php
- install-1.0.0.php
When is mysql4- required in the script name? When can I remove mysql4- from the name? Does it depend on Magento version?
Best Answer
install
will not be executed. So in the example you gave onlydata-upgrade-1.0.0-1.0.1.php
,data-upgrade-1.0.1-1.0.2.php
anddata-upgrade-1.0.2-2.0.0.php
will be executed.(b) the
mysql4-
prefix was required in versions prior to 1.6 (not including 1.6). From 1.6 and later the scripts should run even if they have or they don't havemysql4-
prefix.And an addition to 2a. If you don't have any version of the module installed and you install it directly with version
2.0.0
then onlydata-install-2.0.0.php
will be executed. If you install it at version3.0.0
again onlydata-install-2.0.0.php
will be executed. So when installing a module at a certain version only the install script with a number lower (the closest) or equal to the version is executed.[EDIT]
2.1.a You have 1.0.0 installed and get the 1.0.2 version. Executed scripts:
2.1.b You have 1.0.0 installed and get the 2.0.0 version. Executed scripts:
2.2.a Nothing installed and get version 1.0.0. Executed scripts
2.2.b Nothing installed and get version 2.0.0. Executed scripts
2.2.c Nothing installed and get version 3.0.0. Executed scripts
You can test this by creating a dummy extension where all the files contain only this:
Then test your version combinations and look in
var/log/install-scripts.log
to see the order