0
votes

I am struggling for the life of me to really get into the backend of Magento on my domain. I have reinstalled a couple of times and I just can’t get in without some error popping up. This one is the latest:

Fatal error: Call to a member function getAttribute() on a non-object in /app/code/core/Mage/Core/Helper/Js.php on line 149

The above error pops up when I login to the admin area, and it’s the only thing I see. I refresh, clear cache, use different browser (I’ve tried the latest versions of Firefox and Chrome) and same error.

Will someone please help me out? I’ve been going at this for a couple of days now, trying to figure this out on my own. But I’m all out of ideas. Thanks!

THE Js.php FILE IS BELOW

<?php

class Mage_Core_Helper_Js extends Mage_Core_Helper_Abstract { /** * Key for cache */ const JAVASCRIPT_TRANSLATE_CONFIG_KEY = 'javascript_translate_config';

/**
 * Translate file name
 */
const JAVASCRIPT_TRANSLATE_CONFIG_FILENAME = 'jstranslator.xml';

/**
 * Array of senteces of JS translations
 *
 * @var array
 */
protected $_translateData = null;

/**
 * Translate config
 *
 * @var Varien_Simplexml_Config
 */
protected $_config = null;

/**
 * Retrieve JSON of JS sentences translation
 *
 * @return string
 */
public function getTranslateJson()
{
    return Mage::helper('core')->jsonEncode($this->_getTranslateData());
}

/**
 * Retrieve JS translator initialization javascript
 *
 * @return string
 */
public function getTranslatorScript()
{
    $script = 'var Translator = new Translate('.$this->getTranslateJson().');';
    return $this->getScript($script);
}

/**
 * Retrieve framed javascript
 *
 * @param   string $script
 * @return  script
 */
public function getScript($script)
{
    return '<script type="text/javascript">//<![CDATA[
    '.$script.'
    //]]></script>';
}

/**
 * Retrieve javascript include code
 *
 * @param   string $file
 * @return  string
 */
public function includeScript($file)
{
    return '<script type="text/javascript" src="'.$this->getJsUrl($file).'"></script>'."\n";
}

/**
 * Retrieve
 *
 * @param   string $file
 * @return  string
 */
public function includeSkinScript($file)
{
    return '<script type="text/javascript" src="'.$this->getJsSkinUrl($file).'"></script>';
}

/**
 * Retrieve JS file url
 *
 * @param   string $file
 * @return  string
 */
public function getJsUrl($file)
{
    return Mage::getBaseUrl('js').$file;
}

/**
 * Retrieve skin JS file url
 *
 * @param   string $file
 * @return  string
 */
public function getJsSkinUrl($file)
{
    return Mage::getDesign()->getSkinUrl($file, array());
}

/**
 * Retrieve JS translation array
 *
 * @return array
 */
protected function _getTranslateData()
{
    if ($this->_translateData === null) {
        $this->_translateData = array();
        $messages = $this->_getXmlConfig()->getXpath('*/message');
        if (!empty($messages)) {
            foreach ($messages as $message) {
                $messageText = (string)$message;
                $module = $message->getParent()->getAttribute("module");
                $this->_translateData[$messageText] = Mage::helper(empty($module) ? 'core' : $module
                )->__($messageText);
            }
        }

        foreach ($this->_translateData as $key => $value) {
            if ($key == $value) {
                unset($this->_translateData[$key]);
            }
        }
    }
    return $this->_translateData;
}

/**
 * Load config from files and try to cache it
 *
 * @return Varien_Simplexml_Config
 */
protected function _getXmlConfig()
{
    if (is_null($this->_config)) {
        $canUsaCache = Mage::app()->useCache('config');
        $cachedXml = Mage::app()->loadCache(self::JAVASCRIPT_TRANSLATE_CONFIG_KEY);
        if ($canUsaCache && $cachedXml) {
            $xmlConfig = new Varien_Simplexml_Config($cachedXml);
        } else {
            $xmlConfig = new Varien_Simplexml_Config();
            $xmlConfig->loadString('<?xml version="1.0"?><jstranslator></jstranslator>');
            Mage::getConfig()->loadModulesConfiguration(self::JAVASCRIPT_TRANSLATE_CONFIG_FILENAME, $xmlConfig);

            if ($canUsaCache) {
                Mage::app()->saveCache($xmlConfig->getXmlString(), self::JAVASCRIPT_TRANSLATE_CONFIG_KEY,
                    array(Mage_Core_Model_Config::CACHE_TAG));
            }
        }
        $this->_config = $xmlConfig;
    }
    return $this->_config;
}

}

1

1 Answers

0
votes

You cleared cache? How? Did you also clear sessions? We have a feature right now that means we have to manually clear these every now and then just to get into admin ourselves. This is output from SSH shell...

var# ls
./  ../  cache/  export/  locks/  log/  package/  pear/  report/  session/
var# rm -rf cache/*
var# rm -rf session/*

So I wrote a webpage/php-script to do it so our staff could do it without SSH:

<pre><?php
$output;
$retval;
$errors="";
$command="pwd";
exec ( $command ,  &$output, &$retval  );
$path=$output[0];
unset($output);
echo "rm -rf $path/var/cache/*\n";
if( 0 ) {   // change to 1 after seeing the above looks ok!
    $command="rm -rf $path/var/cache/*";
    exec ( $command ,  &$output, &$retval  );
    echo "<b>$command</b> returned $retval\n";
    if($retval > 0)
        $errors .= "There was a problem deleting cache files.\n";
    // ------------------------------------------------
    $command="ls -alh $path/var/cache";
    exec ( $command ,  &$output, &$retval  );
    echo "<b>$command</b> returned $retval; the directory listing should only have . and ..\n\$output:";
    print_r($output);
    unset($output);
    // ------------------------------------------------
    $command="rm -rf $path/var/session/*";
    exec ( $command ,  &$output, &$retval  );
    echo "<b>$command</b> returned $retval\n";
    if($retval > 0)
        $errors .= "There was a problem deleting session files.\n";
    // ------------------------------------------------
    $command="ls -alh $path/var/session";
    exec ( $command ,  &$output, &$retval  );
    echo "<b>$command</b> returned $retval; the directory listing should only have . and ..\n\$output:";
    print_r($output);
    unset($output);
}
if( strlen($errors) == 0 )
    echo "<h2>Yaay! you can get into admin again...</h2>";
else
    echo "<h2 style=\"color:red\">Boo! something went wrong...</h2>$errors\n";
?></pre>

After changing the if(0) to 1, if you visit this file (I called it __cache_clear.php) this is how the output should look:

rm -rf /home/username/public_html/var/cache/*
rm -rf /home/username/public_html/var/cache/* returned 0
ls -alh /home/username/public_html/var/cache returned 0; the directory listing should only have . and ..
$output:Array
(
    [0] => total 16K
    [1] => drwxrwxrwx  2 username username 4.0K May 13 19:42 .
    [2] => drwxr-xr-x 10 username username 4.0K May 10 15:17 ..
)
rm -rf /home/username/public_html/var/session/* returned 0
ls -alh /home/username/public_html/var/session returned 0; the directory listing should only have . and ..
$output:Array
(
    [0] => total 248K
    [1] => drwxrwxrwx  2 username username 232K May 13 19:42 .
    [2] => drwxr-xr-x 10 username username 4.0K May 10 15:17 ..
)
Yaay! you can get into admin again...

Note that "username" is your assigned username on the webhosting company and will be different. I made the script dynamic in that once placed in the Magento folder, it will act properly.