phpmagentoregistryobservers

magento registry already


I am developing a module for Magento that calls a web service and adds a cookie. I want a method in a class to be called when a user is saved ( customer_save_after ). I was somehow able to get it to work when developing on localhost, but I get this error on the live sites where I've attempted to implement it:

Mage registry key "_singleton/Eight18_Aqui4_Model_Observer" already exists

There is a similar thread here, but it leaves out the actual detail on how the problem was fixed.

Here is my config.xml: (the customer_save_after event seems to be where the error starts)

<?xml version="1.0"?>
<config>
    <global>
        <helpers>
            <aqui4>
                <class>Eight18_Aqui4_Helper</class>
            </aqui4>
        </helpers>
        <modules>
                <Eight18_aqui4>
                        <version>0.1.0</version>
                </Eight18_aqui4>
        </modules>
    </global>
    <adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
        <admin>
            <children>
            <Eight18_Aqui4>
                <title>Aqui4 Module</title>
                <sort_order>10</sort_order>
            </Eight18_Aqui4>
            </children>
        </admin>
        </resources>
    </acl>
    <layout>
        <updates>
        <aqui4>
            <file>aqui4.xml</file>
        </aqui4>
        </updates>
    </layout>
    </adminhtml>

    <default>
        <main>
            <enable>1</enable>
            <siteid>0</siteid>
            <sitetoken>0</sitetoken>
        </main>
    </default>


    <frontend>
        <events>
            <customer_save_after>
            <observers>
                <aqui4_observer>
                    <class>Eight18_Aqui4_Model_Observer</class>
                    <method>start_aqui4</method>
                </aqui4_observer>
            </observers>
        </customer_save_after>
        </events>
        <routers>
            <aqui4>
                <use>standard</use>
                <args>
                    <module>Eight18_Aqui4</module>
                    <frontName>aqui4</frontName>
                </args>
            </aqui4>
        </routers>
        <layout>
            <updates>
                <aqui4>
                      <file>aqui4.xml</file>
                </aqui4>
            </updates>
            </layout>
        </frontend>
</config>

/Company/Module/Model/observer.php:

Public function start_aqui4() {//THIS IS CALLED BY THE EVENT OBSERVER ON CUSTOMER CREATION
    // get variables
    $userEmail = Mage::helper('aqui4')->getUserEmail();
    $userFirstName = Mage::helper('aqui4')->getUserFirstName();
    $userLastName = Mage::helper('aqui4')->getUserLastName();
    $siteID = Mage::helper('aqui4')->getSiteID();
    $siteToken = Mage::helper('aqui4')->getSiteToken();
    $expire=time()+60*60*24*30.42*6;//THE LAST NUMBER IS THE MONTHS
    $randomNumber = rand(0, pow(10, 5));//SERVICE EXPECTS RAND NUMBER

    if(isset( $_COOKIE['aqui4userid'] )){//CHECK TO SEE IF USER ALREADY HAS A COOKIE
        return;
    }
    else{//CHANGE JSON DATA SO JSON_DECODE CAN READ IT
        $getContent = file_get_contents("http://www.domain.com/service.ashx?siteId=" . $siteID . "&token=" . $siteToken . "&email=" . $userEmail . "&data={\"firstName\":\"" . $userFirstName . "\",\"lastName\":\"" . $userLastName . "\",\"email\":\"" . $userEmail . "\",\"company\":\"\",\"position\":\"\",\"country\":\"\"}", true);
        $getContent = str_replace('function __authenticate() ', '', $getContent);
        $getContent = str_replace('{ return ', '', $getContent);
        $getContent = str_replace(';}', '', $getContent);
        $getContent = str_replace('\'', '"', $getContent);
        $getContent = str_replace(': "', ':"', $getContent);

        //SET THE USER ID AND ERROR VARS BASED ON DATA PASSED BACK
        $getContentArray = json_decode($getContent, true);
        $error = $getContentArray['HasError'];
        $userID = $getContentArray['UserId'];

        if($error){
            if($error != "True"){//SERVICE RETURNS NO ERROR
                setcookie("aqui4userid", $userID, $expire);
                return;
            }
            else{//NO COOKIE SET - USER WAS NOT ADDED
                return;
            }
        }
    }
}

}

And finally the system.log file:

2012-07-24T23:21:52+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:54+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:54+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93

Solution

  • Short Version: Your production system is running in "compiler mode" and you haven't compiled your module classes.

    Your production server is running with Magento's "compiler mode" (self-link) turned on. You can tell by the error message Magento's logging

    ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' 
    for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
    

    Magento's looking in includes/src for a class. That's where compiled classes are placed. Also, PHP is trying to include a fully underscored file name Eight18_Aqui4_Model_Observer.php. That only happens when compiler mode is on.

    When you push module changes to production you need to recompile your modules. You can do this from

    System -> Tools -> Compilation
    

    or with the command line compiler script

    $ php shell/compiler.php
    Usage:  php -f compiler.php -- [options]
    
      state         Show Compilation State
      compile       Run Compilation Process
      clear         Disable Compiler include path and Remove compiled files
      enable        Enable Compiler include path
      disable       Disable Compiler include path
      help          This help