Clearing Cache In Magento Removes The Cart - php

I've inherited a Magento project and needed only to change the value of two config variables, both payment URLs in table core_config_data.
I did so easily, but the old values persisted when loading the payment button pages. I then attempted to clear the cache by running the following:
$mage_filename = 'app/Mage.php';
require_once $mage_filename;
umask(0);
Mage::run();
Mage::app()->cleanCache();
Now the link to the Shopping Cart is gone from the main UI. I also get 404s when attempting to add items to the cart. When displaying product pages I receive the following error message:
Fatal error: Call to a member function addExcludeProductFilter() on a non-object in /home/rcspaces/public_html/shop/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php on line 61
Please offer any suggestions you may have to help recover. Thanks.

open all your log files in magento, apache, system log and exception log. Chances are one of your xml files is corrupted.
then, if you notice a error like this one:
2014-03-12T06:15:28+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 1: parser error : XML declaration allowed only at the
start of the document in /var/www/magento1/lib/Varien/Simplexml/Config.php on line 510
2014-03-12T06:15:28+00:00 ERR (3): Warning: simplexml_load_string(): in /var/www/magento1/lib/Varien/Simplexml/Config.php on line 510
2014-03-12T06:15:28+00:00 ERR (3): Warning: simplexml_load_string(): ^ in /var/www/magento1/lib/Varien/Simplexml/Config.php on line 510
open up /var/www/magento1/lib/Varien/Simplexml/Config.php, navigate to line 510 and modify loadString function to look lie this:
public function loadString($string)
{
if (is_string($string)) {
$xml = simplexml_load_string($string, $this->_elementClass);
if ($xml instanceof Varien_Simplexml_Element) {
$this->_xml = $xml;
return true;
} else {
Mage::log($string);
}
} else {
Mage::logException(new Exception('"$string" parameter for simplexml_load_string is not a string'));
}
return false;
}
then, clear cache (can use 'rm -rf /var/www/magento1/var/cache/' unix command) and check system log again. You should see the content of the broken xml file. fix it comparing to vanilla magento files and you should be good. my broken xml was /var/www/magento1/app/code/core/Mage/Checkout/etc/config.xml
when I reproduced the error here.
once this is working, make sure to remove the else with Mage::log($string) from the Config.php file you modified earlier.

It sounds like you're missing server rewrite rules (.htaccess if you're on apache).
What version of Magento are you on?

Related

Magento add debug trace in system.log?

This error keeps filling system.log:
2016-03-27T13:59:10+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 12: parser error : Premature end of data in tag config line 2 in /home/xxxx/public_html/lib/Varien/Simplexml/Config.php on line 510
Every a few minutes or a few hours. To find the culprit, I tried to add this in Config.php:
file_put_contents('/home/xxxx/public_html/xml_errors/'.sha1(microtime(true)).'.txt', $string . PHP_EOL . '=====' . PHP_EOL . print_r(debug_backtrace(), true));
Before the 510 line of Config.php:
$xml = simplexml_load_string($string, $this->_elementClass);
Which is very quickly creating 5 - 10 files per second as my store is pretty busy and I still don't know how to pinpoint the $string that actually raises the warning.
How can I customize system.log to give debug trace of the warning so I can trace the actual source of the xml string that was passed to Config.php?
Or any other suggestion to find the source of the invalid XML would be very much appreciated!
I was able to trace back by adding to the problematic line:
$xml = simplexml_load_string($string, $this->_elementClass);
Like this:
set_error_handler("warning_handler", E_WARNING);
$xml = simplexml_load_string($string, $this->_elementClass);
restore_error_handler();
And then add a standalone function at the end of the Config.php file:
function warning_handler($errno, $errstr, $errfile, $errline) {
file_put_contents('/home/xxxx/public_html/xml_errors/'.sha1(microtime(true)).'.txt', print_r(debug_backtrace(), true));
}
You must manually create the folder xml_errors of course.

Error while reading an XML and validating the schema with XMLReader in PHP

I'm having the following PHP code block:
if (file_exists($name)) {
$reader = new XMLReader();
$reader->open($name);
$reader->setSchema('inc/schema.xsd');
while($reader->read());
$reader->close();
} else {
die("you're having trouble with the files!");
}
For certain URLs I'm getting the following error:
Warning: XMLReader::read(): Unimplemented block at
..\xmlschemas.c:28351 in xml2csv.php on line
43
Warning: XMLReader::read(): An Error Occurred while reading in
xml2csv.php on line 43
Warning: DOMDocument::load(): Premature end of data in tag Products
line 1 in products.xml, line:
532571 in xml2csv.php on line 55
Mostly, the URLs that give me this problem are local URLs (when $name = "file.xml") or remote URLs (when $name = "http://www.domain.com/products.xml") are broken (returning 404, 500, etc.).
A simple Google search on the error brought me to this: https://github.com/Chronic-Dev/libxml2/blob/master/xmlschemas.c
At the line mentioned, 28351, it seems there's a text saying TODO. Because my C skills are very limited (as in close to nothing), I'd like to better understand the reasons of this error and how can I avoid bumping into it.
As XMLReader states, open method return boolean, which is TRUE in case of success and FALSE in case of failure. You may want to try the snippet below?
if (file_exists($name)) {
$reader = new XMLReader();
if ($reader->open($name)) {
$reader->setSchema('inc/schema.xsd');
while($reader->read());
$reader->close();
}
} else {
die("you're having trouble with the files!");
}

Invalid argument supplied for foreach() in

i keep getting the error for this code even though it works as it should when i run it in browser, but when called by include_once it doesnt work due to the error
foreach(($hostlist->uploaded) as $uploaded) {
if (strcmp($uploaded->url,"http://someurl.com/")==0) {
$host = simplexml_load_file($config['hostlist']);
unset($host->uploaded->url);
unset($host->uploaded->pass);
$host->uploaded->addChild('url',"http://anotherurl.com/");
$host->uploaded->addChild('pass',"anotherpass");
$host->uploaded->asXML($config['hostlist']);
$host->asXML($config['hostlist']);`
echo "URL Changed to http://anotherurl.com/";
}
}
knowing that the variables are as follows:
$config['hostlist'] = 'xml/host.xml';
$hostlist = simplexml_load_file($config['hostlist']);
and this is a sample of the xml file:
<host>
<uploaded>
<work>yes</work>
<url>http://someurl.com/</url>
<pass>pass</pass>
</uploaded>
</host>
As I had early mentioned via comments, your issue maybe that the file is using a relative path and being accessed via include_once by a script on a different folder, which causes the file path of your XML to be invalid.
Here is a simple example of what may be happening to you.
I have the following folder structure:
root
- include_folder/
- include_folder/read_host.php
- include_folder/xml
- include_folder/xml/host.xml
- test_xml.php
When accessing include_folder/read_host.php it reads the file just fine.
This is my read_host.php:
<?php
$config['hostlist'] = 'xml/host.xml';
$hostlist = simplexml_load_file($config['hostlist']);
foreach($hostlist->uploaded as $uploaded)
{
echo $uploaded->work, "\n";
echo $uploaded->url, "\n";
echo $uploaded->pass, "\n";
}
The output:
yes
http://someurl.com/
pass
However if I access from test_xml.php which have the following content:
<?php
include_once('include_folder/read_host.php');
echo "what happens";
It fails with error:
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "xml/host.xml" in /home/admin/include_folder/read_host.php on line 4
PHP Notice: Trying to get property of non-object in /home/admin/include_folder/read_host.php on line 5
PHP Warning: Invalid argument supplied for foreach() in /home/admin/include_folder/read_host.php on line 5
what happens
However if I change $config['hostlist'] = 'xml/host.xml'; to the absolute path to the XML file it works just fine and output:
yes
http://someurl.com/
pass
what happens
So in my case the absolute folder was:
$config['hostlist'] = '/home/admin/include_folder/xml/host.xml';

phpseclib Warning: unpack() [function.unpack]: Type C: not enough inpu

Some SFTP credential works fine for below open source, but some credential throwing below error. what is the root cause for the below error, i saw some threads they posted some workouts, but those solutions does not worked for me.
Why i am getting below error, what will be the solution.
open source: phpseclib
Error: Bellow Error
Warning: unpack() [function.unpack]: Type C: not enough input, need 1, have 0 in \Net\SSH2.php on line 1469
Warning: extract() expects parameter 1 to be array, boolean given in \Net\SSH2.php on line 1469
https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Net/SSH2.php#L1538
What is on your line 1469? The version you linked to has this on line 1469:
while ($this->decrypt_block_size > strlen($iv)) {
Your link is to line 1538, which is this:
break;
If you could post the three lines before and after, too, that'd be great.
Thanks!
I know this is an older question and it's been down-rated, but I am actually having the same error. It happens intermittently, so it's hard to troubleshoot. My errors are referencing line 2127 of \Net\SSH2.php. Here is that line, plus a few surrounding lines:
2121 $response = $this->_get_binary_packet();
2122 if ($response === false) {
2123 user_error('Connection closed by server');
2124 return false;
2125 }
2127 extract(unpack('Ctype', $this->_string_shift($response, 1)));
2129 switch ($type) {
2130 case NET_SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ: // in theory, the password can be changed
2131 if (defined('NET_SSH2_LOGGING')) {
This is the syntax that I'm using to copy a file from an external server to my own after logging in:
$sftp->get('/remote/file/path/file.csv', 'myfile.csv');
Here's the link to the page: https://files.maf.org/mp/forms/ChangePL.php
Actually, that page isn't accessed directly normally, but inside an iframe via https://www.maf.org/change
I will say that I've never produced the error when going to the direct link; only accessing it from the parent page via the iframe. Why would that be the case?

Premature end of script headers on index.php magento

I have searched this a lot and none of the solutions has worked so far, so I guess I really need to troubleshoot to see what the problem is:
When I browse our website www.theprinterdepo.com, it works fine on chrome, ie or firefox.
However when I go to the admin on www.theprinterdepo.com/admin on Internet explorer, then it shows the 500 internal server error, and after that if I try to use Internet Explorer to www.theprinterdepo.com, it shows the same error. At the same time I can be in Google Chrome or Firefox surfing the site and it works without a problem.
It takes ages to load on Internet Explorer when it works. while on chrome still loads perfect.
I set chmod 755 in index.php.
I added this on index.php
if ($_SERVER['REMOTE_ADDR'] == '83.134.93.212') { Mage::setIsDeveloperMode(true); ini_set('display_errors', 1); }
I got this
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 60: parser error : Opening and ending tag mismatch: config line 28 and confg in /home/theprint/public_html/lib/Varien/Simplexml/Config.php on line 510
#0 [internal function]: mageCoreErrorHandler(2, 'simplexml_load_...', '/home/theprint/...', 510, Array)
#1 /home/theprint/public_html/lib/Varien/Simplexml/Config.php(510): simplexml_load_string('loadString('loadFile('/home/theprint/...')
#4 /home/theprint/public_html/app/code/core/Mage/Admin/Model/Config.php(59): Mage_Core_Model_Config->loadModulesConfiguration('adminhtml.xml', Object(Varien_Simplexml_Config))
Line 510 correspond to this:
public function loadString($string)
{
if (is_string($string)) {
$xml = simplexml_load_string($string, $this->_elementClass);
if ($xml instanceof Varien_Simplexml_Element) {
$this->_xml = $xml;
return true;
}
} else {
Mage::logException(new Exception('"$string" parameter for simplexml_load_string is not a string'));
}
return false;
}
Since your error is Opening and ending tag mismatch: one of the quickest way to debug this is to disable all custom module/layout.xml modification and then reenable them one by one, until you find the xml that causing this error.
by editing that config file I was able to ech the path and find the xml failing, the start tag was and the end tag was
I fixed that and then it started to work

Categories