Magento: why resource script doesn't install? - magento

I took an example from here.
My folder structure is:
- Avq
- - Import
- - - ...
- - - etc
- - - - config.xml
- - - sql
- - - - avq_import_setup
- - - - - mysql4-install-0.1.0.php
My config.xml is:
<?xml version="1.0"?>
<config>
<modules>
<Avq_Import>
<version>1.0.0.1</version>
</Avq_Import>
</modules>
<global>
<resources>
<avq_import_setup>
<setup>
<module>Avq_Import</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</avq_import_setup>
<avq_import_write>
<connection>
<use>core_write</use>
</connection>
</avq_import_write>
<avq_import_read>
<connection>
<use>core_read</use>
</connection>
</avq_import_read>
</resources>
</global>
</config>
and mysql4-install-0.1.0.php code inside:
<?php
die("!");
$installer = $this;
//....
And I cannot even get "!".
Where is error could be here?
Is there any methods to debug xml config?
PS: I turned off cache, tured on my module and avq_import_setup is absent in the core_resource table.

You need 2 things to magento execute your setup, first inside one folder with the same name of the node in your case is avq_import_setup, so its be avq_import_setup/mysql4-install-x.x.x.php, look i put x.x.x on the file name, you must change it by the version of your module, in your case its 1.0.0.1, and your file is 0.1.0, its the second thing.
And to finish, this execute just 1 time, when magento record on database your module info its done no more then 1 time.
So, if you try install your module and dont run the setup file, probably the magento already register your module on db, and dont run anymore your setup. In this case you must go to 'core_resource' table, and find your module and remove it. Now you can try install again.

Related

Cron Schedule not working for custom module

I have a custom module which have two cron schedule. below is the code of module's config.xml
<?xml version="1.0"?>
<config>
<modules>
<Inchoo_Test>
<version>0.1.0</version>
</Inchoo_Test>
</modules>
<blocks>
<test>
<rewrite>
<test>Inchoo_Test_Block_List</test>
</rewrite>
</test>
</blocks>
<global>
<helpers>
<test>
<class>Inchoo_Test_Helper</class>
</test>
</helpers>
<models>
<test>
<class>Inchoo_Test_Model</class>
</test>
</models>
<resources>
<test_setup>
<setup>
<module>Inchoo_Test</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</test_setup>
<test_write>
<connection>
<use>core_write</use>
</connection>
</test_write>
<test_read>
<connection>
<use>core_read</use>
</connection>
</test_read>
</resources>
</global>
<crontab>
<jobs>
<test>
<schedule><cron_expr>10 00 * * *</cron_expr></schedule>
<run><model>test/cron::hello</model></run>
</test>
<productremove>
<schedule><cron_expr>50 23 * * *</cron_expr></schedule>
<run><model>test/cron::bye</model></run>
</productremove>
</jobs>
</crontab>
</config>
and i have setup cron.sh every day at 7:00 PM. cron.php i used log inside both methods. hello creates log whereas bye didn't create log. I have run that cron mannual from aoe_scheduler and productremove works fine from admin. can someone tell me the possible causes why productremove is getting skipped.
I am little bit confused in cron working too. If i setup cron at the time of 7:00pm every day so whether it will work before 7:00 Pm or it will work for all scheduler after 7:00 PM at same day. or it will work for both before and after 7:00 PM
the reason is a wrong cron configuration. Default magento cron.sh use to run every 5 minutes to catch up with scheduled tasks. Aoe scheduler even suggests to run itself every minute.
Take a look at Schedule->List View to see what happens with your cronjobs. If you run cron.sh only once per day you will see many tasks being "skipped"

Magento module not added to core_resource table

I am trying to write a script which has to execute when a module is updated. I wanted to check the version in db table core_resource, but i see now that the module is not added there. Am i looking in the wrong place, or is there something wrong with my code? This is the relevant part of the config file:
<?xml version="1.0"?>
<config>
<modules>
<mymodule>
<version>1.0.0.0</version>
</mymodule>
</modules>
<global>
<resources>
<update_myscript>
<setup>
<module>mymodule</module>
</setup>
</update_myscript>
</resources>
</global>
</config>
And i created an update file: /updateMyscript/upgrade-1.0.0.0-1.0.0.1.php
If your module has been registered on core_resource, you need to delete from that, for the setup execute again.
And if you want update the module setup, you need to create that upgrade file (upgrade-1.0.0.0-1.0.0.1.php) and alter the version on config.xml
Like this:
<mymodule>
<version>1.0.0.1</version>
</mymodule>
After this you need clear cache from Magento.

magento install script 1.8.1

I'm trying to create a symply module for import country region and more in database.It's very simple but the data wasn't import.I can't figure why:
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Province_Italian>
<version>1.0.50</version>
</Province_Italian>
</modules>
<global>
<resources>
<province_italian_setup>
<setup>
<module>Province_Italian</module>
<class>Province_Italian_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</province_italian_setup>
<province_italian_write>
<connection>
<use>core_write</use>
</connection>
</province_italian_write>
<province_italian_read>
<connection>
<use>core_read</use>
</connection>
</province_italian_read>
</resources>
</global>
</config>
basic configuration file
and i had this folder structure with install script
Province/Italian/Model/Resource/Setup.php
data/province_italian_setup/data-install-x.x.x.php
and usually file in etc folder for configurazion config.xml
It' very simple ,the module is added because i've seen this reference in core_resource table, but seem that can't read installation file from data folder.
Where's mistake?
I'm going mad!
Thanks
"because i've seen this reference in core_resource"
Dalete that reference record from core_resource, delete cache, and try again
A couple of suggestions:
Make sure that have your module enabled, by having a file in app/etc/modules/Province_Italian.xml stating the following information:
<?xml version="1.0"?>
<config>
<modules>
<Province_Italian>
<active>true</active>
<codePool>local</codePool>
<depends><!-- Put your Module dependencies here --></depends>
</Province_Italian>
</modules>
</config>
The code of the module can be found in app/code/local/Province_Italian
The first install file matches the version number of the module. In this case that would be 1.0.50. So the filename must be
app/code/local/Province_Italian/data/province_italian_setup/data-install-10.0.50.php
Once the install script has ran, it cannot run again. Make sure that the code province_italian_setup is absent in the database table core_resource. This will trigger Magento to run the setup script.
Have logging (Mage::log(...)) in your datat install script to see it the script runs.
When you have no custom setup functionality, then the Province_Italian_Model_Resource_Setup.
I also noticed that the models is missing in your XML. Probably your need to add it. Based upon your description, you probably need (1) a model to to manipulate a datastore purely through PHP code, and (2) need a resource model to import the data into a custom database table.
<config>
<modules>
<Province_Italian>
<version>1.0.50</version>
</Province_Italian>
</modules>
<global>
<models>
<province_italian>
<class>Province_Italian_Model</class>
<resourceModel>province_italian_resource</resourceModel>
</province_italian>
<province_italian_resource>
<class>Province_Italian_Model_Resource</class>
<entities>
<!-- Put your entities here -->
</entities>
</province_italian_resource>
</models>
<resources>
<province_italian_setup>
<setup>
<module>Province_Italian</module>
<!-- <class>Province_Italian_Model_Resource_Setup</class> -->
</setup>
</province_italian_setup>
<province_italian_write>
<connection>
<use>core_write</use>
</connection>
</province_italian_write>
<province_italian_read>
<connection>
<use>core_read</use>
</connection>
</province_italian_read>
</resources>
</global>
I hope the above will help.

Custom attributes for custom product type

I've created a new product type and need to create and associate some custom attributes with it.
Is there a way it can be done in the setup code?
Update:
When I say setup code I mean in the "module/sql/module_setup/mysql4-install-0.1.0.php" file for when Magento first uses the module.
This helped set me in the right direction, http://www.danneh.org/2010/03/adding-multi-select-attributes-using-an-installer-in-magento/
You also need this in your config.xml
<global>
<resources>
<mymodule_setup>
<setup>
<module>Company_Mymodule</module>
<class>Company_Mymodule_Model_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mymodule_setup>
<resources>
</global>

Rewrite sql module

Hi I'm trying to rewrite or extend all database update sql's files from core to local without success, until now I have:
CORE:
+core
+Mage
+Mymodule
+...
+etc
-config.xml
+sql
+mymodule_setup
-mysql4-install-0.1.0.php
-mysql4-install-0.1.0-0.1.1.php
-...
LOCAL:
+local
+Mage
+Mynamespace
+Mymodule
+...
+etc
-config.xml
+sql
+mymodule_setup
-mysql4-install-0.1.0.php
-mysql4-install-0.1.0-0.1.1.php
-...
So my question is to avoid problems when upgrading Magento how show I configure the config.xml in core and local, rewrite Block, Model, I did with success, but not for sql, until now I have:
LOCAL
<?xml version="1.0"?>
<config>
<modules>
<Mage_Mymodule>
<version>0.1.1</version>
</Mage_Mymodule>
</modules>
<global>
<resources>
<mynamespace_mymodule_setup>
<setup>
<module>Mynamespace_Mymodule</module>
<class>Mage_Mymodule_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mynamespace_mymodule_setup>
</resources>
<models>
<Mymodule>
<rewrite>
<abc>Mynamespace_Mymodule_Model_Abc</abc>
</rewrite>
</Mymodule>
</models>
</global>
</config>
Thanks in advance for any help.
There's no way to override install/update scripts.
You have to:
1. Set dependency for your module, it must be installed last.
2. In your install script you may use anything.
You'd better use Varien_Db_Adapter_Pdo_Mysql methods.
I think the problem is that you've changed the class in the resource setup to a class that probably doesn't exist. Try :
<setup>
<module>Mynamespace_Mymodule</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
You could make some hack, like in your setup class overwrite the protected method _getAvailableDbFiles and rewriting it using dirname(FILE) instead of Mage::getModuleDir (Mage_Core_Model_Resource_Setup~480)

Resources