Resource Setup implementation in magento
How does Resource Setup Works internally on magento 1.7:
If you are creating a resource setup under your new magento extension and you have followed everything from your side. If you want you can check below URL
Still you are getting that your database operations are not being performed as expected then its time to debug your setup resource. Initially you should validate if you have everything available on right place?
5 Common mistakes for setup resource creation in magento. So make sure you have done everything right with below TODOs checker.
Make sure your modules configuration with below checks
- Version no. must be present under etc/config.xml under app\code\community\NAMESPACE\MODULENAME\etc like
<modules> <NAMESPACE_MODULENAME> <version>2.0.1</version> </ NAMESPACE_MODULENAME> </modules>
2. Resources tag must be available under config.xml
<resources> <namespace_modulename_setup> <setup> <module>namespace_modulename</module> <class>namespace_modulename_Model_Resource_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </ namespace_modulename_setup> </resources>
- 3. “namespace_modulename_setup” folder must be available under app\code\community\NAMESPACE\MODULENAME\sql folder that contain install or upgrade.php file.
- 4. Install or upgrade file name should contain same version number as written into config.xml file under version like
code\community\NAMESPACE\MODULENAME\sql\ncr_promoengine_setup\mysql4-install-2.0.1.php
5. Make sure class namespace_modulename_Model_Resource_Mysql4_Setup should be available under
code\community\NAMESPACE\MODULENAME\Model\Resource\Mysql4\Setup.php
Done everything but still not working? If you have done all of your efforts and its not working then I think its time to make your hand black with magento core machinery in order to find out where is the mistake.
Core Magento debugging techniques with actual files
How does magento load all modules setup resource:
File Path: app\code\core\Mage\Core\Model\Config.php
Function name: getModuleConfig ( This function load config file of each module)
This function has been called from another file. File details are as below
File Path: app\code\core\Mage\Core\Model\Resource\Setup.php
Function name: __construct (constructor gets calls as soon as we open any magento page )
Function name: applyDataUpdates (This function compare file version under config.xml file and data version available under core_resource table. Based on this comparison it decides if we need to run setup installer or upgrade script written in setup folder of magento)
Function name: _getAvailableDbFiles
What this function does : This function checks under sql folder if any script file available or not. This is done through regular expression match with available file name under that folder. If It found any install or upgrade file based on above comparison it starts processing that document.
Function name: _ applyDataUpdates
What this function does : This function calls _installData or _upgradeData .
Function name: _modifyResourceDb
What this function does : This function checks if resource type is data or db . Accordingly it send files for comparison with below function . This is the final function that does actual process for below items:
- .sql file – That got run directly into your database using magento core connection
- .php – That file got included (either install or upgrade script)
Hopefully you will get your setup resource working . Best of luck.
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments