Rewrite sql module - magento

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)

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

Magento extend cms block class

I'm trying to extend the magento class Mage_Cms_Block_Block. I've got my module active. I think the reason why its failing is to do with the config.xml.
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<VisibleBlocks_ShowBlocks>
<!-- The version of our module, starting at 0.0.1 -->
<version>0.0.1</version>
</VisibleBlocks_ShowBlocks>
</modules>
<global>
<blocks>
<mage_cms>
<rewrite>
<cms_blocks>VisibleBlocks_ShowBlocks_Block_Border</cms_blocks>
</rewrite>
</mage_cms>
</blocks>
</global>
</config>
Can someone explain to me what the tags inside the global tags mean? Can the tags inside rewrite be called anything?
OK seems that asking the questions made it clearer to me. Hope this hasn't a waste of time for anyone. 'mage_cms' should be 'cms' as that is the module i'm extending and 'cms_blocks' should be 'block'.
i have explain the details,please check
<global>
<blocks>
<cms><!--module name of rewrite class mage_cms -->
<rewrite>
<!-- file path of Block of app/code/core/mage/cms/block.php -->
<blocks>VisibleBlocks_ShowBlocks_Block_Border</blocks>
</rewrite>
</cms>
</blocks>
</global>
<config>
<global>
<blocks>
<cms>
<rewrite>
<block>VisibleBlocks_ShowBlocks_Block_Cms_Block</block>
</rewrite>
</cms>
</blocks>
</global>
</config>
With these tags, we say we will configure a block of Magento’s core called cms and we will rewrite () the « block » block of this module
Also make sure your module is active & being displayed in system/config/Advanced

Extending Mage Core Files Without Loosing Namespace

I would like to introduce my own entities into particular Magento module namespaces for example I might want to be able to call
Mage::getModel('catalog/brand')->load(1);
Brand is not currently a model included in the catalog module. I don't want to modify core files nor do I want to hack the core by just adding a Mage folder to the local directory.
I was thinking perhaps syntax inside of my namespaces config file similar to this:
<models>
<catalog>
<args>
<modules>
<AJW_Catalog before="Mage_Catalog">AJW_Catalog</AJW_Catalog>
</modules>
</args>
</catalog>
<ajw_catalog>
<class>AJW_Catalog_Model</class>
</ajw_catalog>
</models>
but it does not seem to work.
Does anyone know how this can be accomplished?
Maybe possible with some trickery, but not officially supported, and generally a bad idea. The before= syntax you've used only works for the routers node. There's no framework code to let you do what you're trying to do. Also, there's a strong bias in the Magento framework code towards individual modules "owning" their namespace/package name. Defining new models in an existing namespace (catalog) introduces the theoretical possibility that your code may conflicts with a future version of Magento's code.
This may be a possible fix (brain fart)
Create a module named Customnamespace_Catalog and then just rewrite the catalog module with a node that doesnt exist in the default mage module:
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<version>0.1.0</version>
</Namespace_Catalog>
</modules>
<global>
<models>
<catalog>
<rewrite>
<brand>Namespace_Brand_Model_Brand</brand>
</rewrite>
</catalog>
</models>
</global>
</config>
Followed by an additional module:
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Brand>
<version>0.1.0</version>
</Namespace_Brand>
</modules>
<global>
<models>
<brand>
<class>Namespace_Brand_Model</class>
</brand>
</models>
</global>
</config>
This will allow you to call Mage::getModel('catalog/brand')
echo get_class(Mage::getModel('catalog/brand'); // Namespace_Brand_Model_Brand

Magento finds module XML in one install, and not another

I've been working on a plugin for Magento, and I have one global block with no xml tags outside of it in my layout/name.xml file as such:
<block name="one.two.three" template="project/button.phtml" />
The idea is to be able to call getBlockHtml("one.two.three") anywhere and be able to see the beta.phtml. I got this working no problem.
To test through my plugin's installation process, I tried installing another magento from scratch. I installed my plugin into the same directories as the first and copied/pasted the getBlockHtml from my older install, and nothing appears (not even the template hint)! Adding default references didn't help.
It's obviously not detecting my xml files, though the adminhtml menu and the mysql install script both work. Any idea why this would be? And yes, I have cleared cache countless times.
Edit:
Both installations are version 1.7.0.2
Both of these installations are on the same computer, so their filesystems and casing are presumably identical. Is it ever the case when two on the same computer could differ in case sensitivity?
Installing plugin: We have a script that copies files into the Magento installation, which has been working so far with the first installation, and is what I have been doing with the second ins. To confirm, the entries and tables in the magento database are added when the files are copied over.
My layout is stored in a general layout folder: app/design/layout/projectEmbeds.xml. I realize this is not common convention but it was like this before I got to this project, and it was working so I didn't mess with it. I assume this decision was made so it would appear independent website theme.
Similarly, my plugin is stored in app/code/local/ -> Project/Embeds, which contains Blocks, controllers, etc, Helper, Model, and sql as it should.
The button.phtml in question is located in app/design/frontend/default/default/project
My config.xml file stored in etc in the above directory is as follows. Anything referencing Project_Banner is important and the Project_Embed one is almost entirely deprecated.
<config>
<modules>
<Project_Embeds>
<version>0.1.0</version>
</Project_Embeds>
</modules>
<frontend>
<routers>
<embeds>
<use>standard</use>
<args>
<module>Project_Embeds</module>
<frontName>embeds</frontName>
</args>
</embeds>
</routers>
<layout>
<updates>
<embeds>
<file>projectEmbeds.xml</file>
</embeds>
</updates>
</layout>
</frontend>
<global>
<resources>
<project_embed_setup>
<setup>
<module>Project_Embeds</module>
<class>Project_Embeds_Model_Mysql4_Setup</class>
</setup>
</project_embed_setup>
</resources>
<models>
<embeds>
<class>Project_Embeds_Model</class>
<resourceModel>embeds_mysql4</resourceModel>
</embeds>
<projectbanner>
<class>Project_Banner_Model</class>
<resourceModel>banner_mysql4</resourceModel>
</projectbanner>
<embeds_mysql4>
<class>Project_Embeds_Model_Mysql4</class>
<entities>
<embeds>
<table>project_embed</table>
</embeds>
<banner>
<table>project_banner</table>
</banner>
</entities>
</embeds_mysql4>
</models>
<resources>
<embeds_setup>
<setup>
<embeds>Project_Embeds</embeds>
</setup>
<connection>
<use>core_setup</use>
</connection>
</embeds_setup>
<embeds_write>
<connection>
<use>core_write</use>
</connection>
</embeds_write>
<embeds_read>
<connection>
<use>core_read</use>
</connection>
</embeds_read>
</resources>
<blocks>
<embeds>
<class>Project_Embeds_Block</class>
</embeds>
</blocks>
<helpers>
<embeds>
<class>Project_Embeds_Helper</class>
</embeds>
</helpers>
</global>
<admin>
<routers>
<thisprojectname>
<use>admin</use>
<args>
<module>Project_Embeds</module>
<frontName>project</frontName>
</args>
</thisprojectname>
</routers>
<!-- default admin design package and theme -->
<design>
<package>
<name>base</name>
</package>
<theme>
<default>default</default>
</theme>
</design>
</admin>
<adminhtml>
<menu>
<embeds translate="title" module="embeds">
<title>Project</title>
<sort_order>9999</sort_order>
<children>
<projectbanner module="embeds">
<title>Edit Coupon</title>
<sort_order>1</sort_order>
<action>embeds/adminhtml_banner</action>
</projectbanner>
</children>
</embeds>
</menu>
<layout>
<updates handle="index_settings">
<embeds>
<file>projectEmbeds.xml</file>
</embeds>
</updates>
</layout>
</config>
Try adding the projectEmbeds.xml file in your theme used i.e default i guess
So add in
/app/design/frontend/default/default/layout/
and call the block inside
<default></default>
Let me know if it helps..

Resources