Installer and Setup Scripts
Warning
If possible use a data patch instead.
Creating Setup Scripts¶
There are four types of setup scripts, stored in the module's Setup folder:
- InstallSchema: Setup of database table structure, or other entities. Run once when a new module is installed
- InstallData: Populating any new data. Run once when a new module is installed
- UpgradeSchema: Setup of database table structure, or other entities. Run whenever the version in the module.xmlis greater than the value in thesetup_moduletable
- UpgradeData: Populating any new data. Run whenever the version in the module.xmlis greater than the value in thesetup_moduletable
- Recurring: Run every time setup:upgradeis run, regardless of versions
More detail at http://inchoo.net/magento-2/setup-scripts-magento-2/
Debugging Setup Scripts¶
Check if a script should run¶
- If you're using an Install script, check the setup_moduletable. If an entry exists for your module, the Install script will not run
- If you're using an Upgrade script, check the setup_moduletable. If the entry version is equal to or greater than the version in yourmodule.xml, the Upgrade script will not run
Checking if Magento is attempting to run your script¶
- Try setting an xdebug breakpoint at the start of the install/upgradefunction
- Try adding an xdebug_break()call
- Try adding a die()statement
- Make the PHP file invalid, which should make the setup:upgradecommand fail to complete
- Xdebug (Magento Root)/setup/src/Magento/Setup/Model/Installer.php'sgetSchemaDataHandler()function, which attempts to find your install/upgrade script