Rewrite a class in magento - api

I have been trying to rewrite a class in Magento and I be doing all the correct procedures, however I am not getting.
I'm trying to rewrite app\code\core\Mage\Catalog\Model\Product\Attribute\Media\Api.php
Thanks in advance to anyone who can help me.
<config>
<modules>
<Namespace_Catalog>
<version>1.6.0.0.14</version>
</Namespace_Catalog>
</modules>
<global>
<models>
<catalog>
<rewrite>
<product_attribute_media_api>Namespace_Catalog_Model_Product_Attribute_Media_Api</product_attribute_media_api>
</rewrite>
</catalog>
</models>
</global>
</config>
Yeah I forgot to say that part
In the app/etc/modules/ I have with depends tag. I've tried with and without the tag depends and it never worked. I think I'm really doing everything right.
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</Namespace_Catalog>
</modules>
</config>
In the app\code\local\Namespace\Catalog\Model\Product\Attribute\Media\Api.php I have
class Namespace_Catalog_Model_Product_Attribute_Media_Api extends Mage_Catalog_Model_Product_Attribute_Media_Api
I rewrote the function removes and let it equal to the original, but with Mage::log('rewrote', null, 'rewrote.log'), to know that he had successfully rewritten.
I cleared my cache.
I corrected codePool tag for case sensitive.
I checked /var/log/ and not found any error inside exception.log and system.log.
My Index.php is set as developer mode and ini_set('display_errors', 1); uncommented.
I followed a tutorial on Magento here
This describes the state of your Magento system. It lists all modules, models, classes, event listeners or almost anything else you could think of. For example, consider the config.xml file you created above. If you search the XML file in your browser for the text Namespace_Catalog_Model_Product_Attribute_Media_Api you'll find your class listed. Every module's config.xml file is parsed by Magento and included in the global config.
Here is my class to write. It seems okay. What can I be missing?
<catalog>
<class>Mage_Catalog_Model</class>
<resourceModel>catalog_resource</resourceModel>
<rewrite>
<product_attribute_media_api>Namespace_Catalog_Model_Product_Attribute_Media_Api</product_attribute_media_api>
</rewrite>
</catalog>

Your code seems to be right.
Have you created an XML-file in app/etc/modules/?
It should look like:
Namespace_Catalog.xml
< ?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<active>true</active>
<codepool>local</codepool>
</Namespace_Catalog>
</modules>
</config>

i think you missed something
<version>1.6.0.0.14</version>
should be same with
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<active>true</active>
<codepool>local</codepool>
<version>1.6.0.0.14</version>
</Namespace_Catalog>
</modules>

"Codepool" is case sensitiv.
Try:
<codePool>local</codePool>
instead of
<codepool>local</codepool>

Related

Remove WebDAVModule from startup.cs asp.net core

IIS Server gives "Method Not Found Error". After Exploring Google, I got that WebDAVModule should be removed in web config file.
Every time i publish my Project, i have to add this
<modules> <remove name="WebDAVModule" /> </modules>
in Webconfig
Please suggest me how do i add this in Startup.cs or any other solution?
Just add a web.config file to your project, like bellow:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>
You can do it in several ways
Remove from IIS model
Go to your site in IIS
Click "Modules"
Remove WebDAVModule
Restart site (might not be needed)
Remove from windows features

Create Joomla Module > warning : JInstaller: :Install: Can't find Joomla XML setup file

I created Joomla Module by following tutorial on joomla website, for the first part it works but after i added 2nd part of tutorial about Creating a simple module/Using the Database it doesn't work.
i got warning
JInstaller: :Install: Can't find Joomla XML setup file.
the 2nd part tutorial is based on 1st tutorial. maybe i've done something wrong in my XML file.
this is my XML file
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>Hello, World 2</name>
<author>Dhany</author>
<version>1.0.0</version>
<description>Belajar Module 2</description>
<files>
<folder>sql</folder>
<filename>mod_helloworld2.xml</filename>
<filename module="mod_helloworld">mod_helloworld2.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<config>
</config>
</extension>
<install>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/install.mysql.utf8.sql</file>
</sql>
</install>
<uninstall>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/uninstall.mysql.utf8.sql</file>
</sql>
</uninstall>
<update>
<schemas>
<schemapath type="mysql">sql/mysql/updates</schemapath>
</schemas>
</update>
you can download my complete module here
thanks for your help
Remember </extension> should come at the end. Not in between. That should be the ending tag. Your code should looklike this.
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>Hello, World 2</name>
<author>Dhany</author>
<version>1.0.0</version>
<description>Belajar Module 2</description>
<files>
<folder>sql</folder>
<filename>mod_helloworld2.xml</filename>
<filename module="mod_helloworld">mod_helloworld2.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<config>
</config>
<install>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/install.mysql.utf8.sql</file>
</sql>
</install>
<uninstall>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/uninstall.mysql.utf8.sql</file>
</sql>
</uninstall>
<update>
<schemas>
<schemapath type="mysql">sql/mysql/updates</schemapath>
</schemas>
</update>
</extension>
Note: I also noted that your updates is a file instead of a folder. Remember it should be a folder.

Why am I getting, "Error 392 Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object."

Does a missing "Module" section in the Elements.xml file cause "Error 392 Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object."?
All of a sudden, I get that error when trying to rebuild a Sharepoint Web Part. One thing I researched indicates that perhaps Elements.xml has a problem. I haven't changed anythying in this in a long while, nor have I changed anything explicitly, I don't think, but here it is as it now stands:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="104">
<Receiver>
<Name>PostTravelItemEventReceiverItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>PostTravelWizard.PostTravelItemEventReceiver.PostTravelItemEventReceiver</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
<Receiver>
<Name>PostTravelItemEventReceiverContextEvent</Name>
<Type>ContextEvent</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>PostTravelWizard.PostTravelItemEventReceiver.PostTravelItemEventReceiver</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
So all it has right now is a reference to the two "Event Receiver" handlers I added; I compared this non-working project's Elements.xml file with other Elements.xml files I have (from Web Parts that do work); one of them looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<Module Name="TravelFormHelpWebPart" List="113" Url="_catalogs/wp">
<File Path="TravelFormHelpWebPart\TravelFormHelpWebPart.webpart" Url="TravelFormHelpWebPart.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="Financial Affairs Forms" />
</File>
</Module>
</Elements>
...and the other one is very similar, like so:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<Module Name="DPSVisualWebPart" List="113" Url="_catalogs/wp">
<File Path="DPSVisualWebPart\DPSVisualWebPart.webpart" Url="DPSVisualWebPart.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="Financial Affairs Forms" />
</File>
</Module>
</Elements>
The difference seems to be that the working Web Apps have a "Module" section in their Elements.xml file
There was one other clue, too, from the link above, to wit:
If step 2 didn't resolve your error, check if your deployment target is set to "WebApplication". It needs to be set to "Global AssemblyCache" instead.
...and here, too, somehow, this non-working WebPart was set to "WebApplication," whereas the others are set to "GAC"). Changing that didn't help, though - I still get the same err msg as reported above.
So if the missing "Module" section is the problem, that was apparently there earlier (when it was working) and somehow got 86'd (along with the changing of the project's "Assembly Deployment Target" property, apparently). Why would/how could that happen?
Adding (back, apparently) the Module section did the trick.
Specifically, I added the following above the "Receivers" section:
<Module Name="PostTravelWizardWebPart" List="113" Url="_catalogs/wp">
<File Path="PostTravelWizardWebPart\PostTravelWizardWebPart.webpart" Url="PostTravelWizardWebPart.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="Financial Affairs Forms" />
</File>
</Module>
...and it now deploys successfully.
(Note that I also changed (again, back, apparently) the value of the project's "Assembly Deployment Target" property to "GlobalAssemblyCache" from "WebApplication"

How to externalize properties of persistence.xml for JBOSS 7.1.1?

My persistence.xml is currently present in the application war(in META-INF folder.). However, for the application to be run across multiple DBs the persistence needs to be changed again and again. I want to avoid it. But, I am not able to understand how will i configure the properties(like dialect) in the persistence.xml from, say, a property file which i would change based on my DB, hence not compelling me to update and redeploy my war.
My problem can also be resolved if i can configure the dialect in the datasource in standalone.xml where i have mentioned other DB details. I am not being able to make out what the property would be.
Though i would prefer a solution for the first one.
PS: I am rookie in Web App development. Questions might annoy you. :D
I use a method that works well for hibernate.
1) put the hibernate configuration properties in a xml file (call it hibernate.cfg.xml but it's not mandatory)
this is an example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.search.default.directory_provider">ram</property>
</session-factory>
</hibernate-configuration>
you can put there only hibernate properties that do not start with hibernate.ejb
2) Create a jboss module. It's very simple. Suppose you want to call the module com.myorganization.config than create a directory structure in the modules folder of you server installation: /com/myorganization/config/main. In the main folder put the hibernate.cfg.xml file and the following module.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.myorganization.config">
<resources>
<resource-root path="."/>
</resources>
</module>
3) In your persistence.xml adding the following property:
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
4) Finally, in the META-INF/MANIFEST.MF file add the following line:
Dependencies: com.myorganization.config
If you like maven use the maven-war-plugin in order to change the MANIFEST.MF:
<configuration>
<archive>
<manifestEntries>
<Dependencies>com.myorganization.config</Dependencies>
</manifestEntries>
</archive>
</configuration>
That's all.

What's the recommended way of updating maven repository metadata

I'll like to know, what's the recommended way of updating maven repository metadata?
The scenario I'm working with is such that the content of maven-cargo plugin metadata is stale and does not reflect an updated repository metadata, hence, my reason to change it.
For example, I have this in maven-metadata-central.xml for the maven-cargo plugin:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-cargo-plugin</artifactId>
</metadata>
Whereas the updated version should be this:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
</metadata>
How do I go about this?
Thanks
Add below into settings.xml (This makes maven to use the specified group first.
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
<pluginGroup>org.codehaus.cargo</pluginGroup>
</pluginGroups>
And add below into your pom.xml
<configuration>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
</container>
</configuration>
see http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html