From 4f84b1e774b05111389bc565a6bda44eeed2cc8f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Jun 2013 17:43:30 +0200 Subject: [PATCH] Fix: Bad error management --- htdocs/core/class/rssparser.class.php | 51 ++++++++++++++------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/htdocs/core/class/rssparser.class.php b/htdocs/core/class/rssparser.class.php index ebc71a9bfa8..13c7db642b1 100755 --- a/htdocs/core/class/rssparser.class.php +++ b/htdocs/core/class/rssparser.class.php @@ -183,6 +183,7 @@ class RssParser include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $rss=''; $str=''; // This will contain content of feed // Check parameters @@ -213,7 +214,7 @@ class RssParser } else { - dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); + dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); } } @@ -235,7 +236,6 @@ class RssParser //var_dump($opts);exit; $context = stream_context_create($opts); - // FIXME avoid error if no connection $str = file_get_contents($this->_urlRSS, false, $context); } catch (Exception $e) { @@ -243,36 +243,39 @@ class RssParser } } - // Convert $str into xml - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) + if ($str !== false) { - //print 'xx'.LIBXML_NOCDATA; - libxml_use_internal_errors(false); - $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA); + // Convert $str into xml + if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) + { + //print 'xx'.LIBXML_NOCDATA; + libxml_use_internal_errors(false); + $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA); + } + else + { + $xmlparser=xml_parser_create(''); + if (!is_resource($xmlparser)) { + $this->error="ErrorFailedToCreateParser"; return -1; + } + + xml_set_object($xmlparser, $this); + xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element'); + xml_set_character_data_handler($xmlparser, 'feed_cdata'); + $status = xml_parse($xmlparser, $str); + xml_parser_free($xmlparser); + $rss=$this; + //var_dump($rss->_format);exit; + } } - else - { - $xmlparser=xml_parser_create(''); - if (!is_resource($xmlparser)) { - $this->error="ErrorFailedToCreateParser"; return -1; - } - - xml_set_object($xmlparser, $this); - xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element'); - xml_set_character_data_handler($xmlparser, 'feed_cdata'); - $status = xml_parse($xmlparser, $str); - xml_parser_free($xmlparser); - $rss=$this; - //var_dump($rss->_format);exit; - } - + // If $rss loaded if ($rss) { // Save file into cache if (empty($foundintocache) && $cachedir) { - dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is saved onto disk."); + dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk."); if (! dol_is_dir($cachedir)) dol_mkdir($cachedir); $fp = fopen($newpathofdestfile, 'w'); fwrite($fp, $str);