Book: "Getting Started with Magento Extension Development", sql migration script not executed - magento

I have followed the same steps as mentioned in the Book, the key steps are:
create the resources setup configuration at <Module Directory>/etc/config.xml as follow:
<?xml version="1.0"?>
<config>
<global>
<modules>
<Foggyline_HappyHour>
<version>1.0.0.0</version>
</Foggyline_HappyHour>
</modules>
<!-- Some Other Configuration (Doesn't matter) -->
<resources>
<foggyline_happyhour_setup>
<setup>
<model>Foggyline_HappyHour</model>
</setup>
</foggyline_happyhour_setup>
</resources>
<!-- Some Other Configuration (Doesn't matter) -->
</global>
</config>
Create a the migration script at <Module Directory>/sql/foggyline_happyhour_setup/install-1.0.0.0.php with the following script:
<?php
// Just checking if the script is executed
echo 'Thank you for your help :)';
Load any pages and check if the page print the message.
Nope, it didn't print anything. The script didn't run at all.
How can we fix this?

:( Apparently there was a typo in the books ):
According to the official docs, the setup definition should be <module> instead of <model>. Thus:
<?xml version="1.0"?>
<config>
<global>
<!-- Some Other Configuration (Doesn't matter) -->
<resources>
<foggyline_happyhour_setup>
<setup>
<module>Foggyline_HappyHour</module>
</setup>
</foggyline_happyhour_setup>
</resources>
<!-- Some Other Configuration (Doesn't matter) -->
</global>
</config>
Now I can see the script executed. :)

Related

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 custom language file not being used

I have created a custom language file for a feature that I have built into our Magento website. The language variables work fine on my local machine (of course), however on our staging environment it doesn't. My local machine is Windows and staging server is Linux, so obvious answer would be an issue with filename casing, but imho these are right.
I have my own block that overwrites the Mage_Catalog, called Feno_Catalog which works fine. To that config.xml file I've appended some code to load the Feno_Catalog.csv;
/local/Feno/Catalog/etc/config.xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<config>
<modules>
<Feno_Catalog>
<version>0.1.0</version>
</Feno_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<class>Feno_Catalog_Block</class>
</rewrite>
</catalog>
</blocks>
<helpers>
<catalog>
<rewrite>
<class>Feno_Catalog_Helper</class>
</rewrite>
</catalog>
</helpers>
</global>
<frontend>
<translate>
<modules>
<Feno_Catalog>
<files>
<default>Feno_Catalog.csv</default>
</files>
</Feno_Catalog>
</modules>
</translate>
</frontend>
<adminhtml>
<translate>
<modules>
<Feno_Catalog>
<files>
<default>Feno_Catalog.csv</default>
</files>
</Feno_Catalog>
</modules>
</translate>
</adminhtml>
</config>
The CSV file has been put into 2 folders: /app/locale/[de_DE|en_US]/ with matching casing.
As I mentioned it works fine on my local machine, but not on the staging server. What could cause this? I've searched for quite a bit and cleared cache (although cache is turned off), switched languages (both languages don't work - The language keys are like "poll_question_a1").
When I move the translations to Mage_Catalog.csv everything also works fine (but of course that is not what I want).
So how to fix? Is there any way to find the cause of this?
Perhaps since you're rewriting the catalog module, you need your translates to look like this:
<translate>
<modules>
<Mage_Catalog>
<files>
<feno>Feno_Catalog.csv</feno> <!-- name it something other than default, to avoid conflict with Mage_Catalog -->
</files>
</Mage_Catalog>
</modules>
</translate>
Also, you can try looking in app/code/core/Mage/Core/Model/Translate.php around line 131-134. That is where it is loading your module translations. Try doing some Mage::log() calls in and around there to see if your CSV files are actually getting loaded.

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.

My custom CMS Layout Template in Magento is not loaded

I have created custom CMS layout for Magento according this tutorial. On my localhost(XAMPP on Win7) it is working, but when I have uploaded all 3 files to my web:
app/code/local/Lorinc/cmsLayout/etc/config.xml
app/design/frontend/sportsfans01/default/template/page/cmsLayout.phtml
app/etc/modules/Lorinc_cmsLayout.xml
And it is not working there.
Here is the code of config.xml
<?xml version="1.0"?>
<config>
<modules>
<Lorinc_cmsLayout>
<version>0.1.0</version>
</Lorinc_cmsLayout>
</modules>
<global>
<page>
<layouts>
<cmsLayout translate="label">
<label>cmsLayout</label>
<template>page/cmsLayout.phtml</template>
<layout_handle>cmsLayout</layout_handle>
</cmsLayout>
<!-- add more layouts here -->
</layouts>
</page>
</global>
</config>
And here is Lorinc_cmsLayout.xml
<?xml version="1.0"?>
<config>
<modules>
<Lorinc_cmsLayout>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</Lorinc_cmsLayout>
</modules>
</config>
I have tried everything. I have changed files and folder permissions (files 0644, folders 0755), i have used magento-cleanup.php, my cache is disabled, I have tried to logout and login again and nothing works. Any ideas what is wrong there?
just looked at your question and the first thing I saw is that you have a wrong folder structure:
The path app/design/frontend/sportsfans01/default/template/page/cmsLayout.phtml
has to be changed to
app/design/frontend/default/sportsfans01/template/page/cmsLayout.phtml
Don't know if its just a typo of yours!
Furthermore you could check the logs of magento:
var/log/exception.log
var/log/system.log
Hope this will help
Regards
Vince
Please try this. I found it in App/code/core/Mage/Page/etc/config.xml for the 1column.phtml layout
<global>
<page>
<layouts>
<cmsLayout module="page" translate="label">
<label>cmsLayout</label>
<template>page/cmsLayout.phtml</template>
<layout_handle>page_cmsLayout</layout_handle>
</cmsLayout>
<!-- add more layouts here -->
</layouts>
</page>
</global>
If this won't help please try with changing different theme folder.Be sure to avoid typo mistake.
Problem finally solved. I already had one custom layout (called HomeLayout) on that page so I just merged that 2 layouts. Here is the code of app/code/local/Lorinc/HomeLayout/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Lorinc_HomeLayout>
<version>0.1.0</version>
</Lorinc_HomeLayout>
</modules>
<global>
<page>
<layouts>
<Lorinc_HomeLayout translate="label">
<label>HomeLayout</label>
<template>page/HomeLayout.phtml</template>
<layout_handle>HomeLayout</layout_handle>
</Lorinc_HomeLayout>
<Lorinc_cmsLayout translate="label">
<label>cmsLayout</label>
<template>page/cmsLayout.phtml</template>
<layout_handle>cmsLayout</layout_handle>
</Lorinc_cmsLayout>
<!-- add more layouts here -->
</layouts>
</page>
</global>
</config>
And it works perfect.

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