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

  1. 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:

  1. .sql file – That got run directly into your database using magento core connection
  2. .php – That file got included (either install or upgrade script)

 

 

 

Hopefully you will get your setup resource working . Best of luck.

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...