[BUGFIX] Make sure XML parser is created everytime when needed 86/18886/3
authorMarcus Krause <marcus.krause@typo3.org>
Wed, 13 Mar 2013 21:05:00 +0000 (22:05 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 16 Mar 2013 00:09:57 +0000 (01:09 +0100)
Currently, EM's MirrorXmlPushParser, which is based on ext/xml,
is not properly working. The constructor creates the parser and
within parseXML() method the parser resource is freed.
However, when clicking on retrieve/update button method
parseXML() is invoked multiple times which makes subsequent calls
fail.

Creating the parser is now done within parseXML() method.

Resolves: #25292
Releases: 6.1, 6.0, 4.7, 4.5
Change-Id: I7c6c15f65d08fb0264d7d66cc584cbe7ff423b45
Reviewed-on: https://review.typo3.org/18886
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/em/classes/parser/class.tx_em_parser_extensionxmlpullparser.php
typo3/sysext/em/classes/parser/class.tx_em_parser_extensionxmlpushparser.php
typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlpullparser.php
typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlpushparser.php
typo3/sysext/em/classes/parser/class.tx_em_parser_xmlabstractparser.php

index fa1516c..9468715 100644 (file)
  */
 class tx_em_Parser_ExtensionXmlPullParser extends tx_em_Parser_ExtensionXmlAbstractParser implements SplSubject {
 
+       /**
+        * Keeps XML parser.
+        *
+        * @var null|XMLReader
+        */
+       protected $objXML = NULL;
 
        /**
         * Keeps list of attached observers.
@@ -58,10 +64,16 @@ class tx_em_Parser_ExtensionXmlPullParser extends tx_em_Parser_ExtensionXmlAbstr
         */
        function __construct() {
                $this->requiredPHPExt = 'xmlreader';
+       }
 
-               if ($this->isAvailable()) {
-                       $this->objXML = new XMLReader();
-               }
+       /**
+        * Method creates the required parser.
+        *
+        * @access  protected
+        * @return  void
+        */
+       protected function createParser() {
+               $this->objXML = new XMLReader();
        }
 
        /**
@@ -72,6 +84,7 @@ class tx_em_Parser_ExtensionXmlPullParser extends tx_em_Parser_ExtensionXmlAbstr
         * @throws  em_extensionxml_Exception  in case of XML parser errors
         */
        public function parseXML($file) {
+               $this->createParser();
                if (!(is_object($this->objXML) && (get_class($this->objXML) == 'XMLReader'))) {
                        $this->throwException('Unable to create XML parser.');
                }
index d3ecb2b..3d124a1 100644 (file)
  */
 class tx_em_Parser_ExtensionXmlPushParser extends tx_em_Parser_ExtensionXmlAbstractParser implements SplSubject {
 
+       /**
+        * Keeps XML parser.
+        *
+        * @var null|resource
+        */
+       protected $objXML = NULL;
 
        /**
         * Keeps current element to process.
@@ -63,11 +69,17 @@ class tx_em_Parser_ExtensionXmlPushParser extends tx_em_Parser_ExtensionXmlAbstr
         */
        function __construct() {
                $this->requiredPHPExt = 'xml';
+       }
 
-               if ($this->isAvailable()) {
-                       $this->objXML = xml_parser_create();
-                       xml_set_object($this->objXML, $this);
-               }
+       /**
+        * Method creates the required parser.
+        *
+        * @access  protected
+        * @return  void
+        */
+       protected function createParser() {
+               $this->objXML = xml_parser_create();
+               xml_set_object($this->objXML, $this);
        }
 
        /**
@@ -78,7 +90,7 @@ class tx_em_Parser_ExtensionXmlPushParser extends tx_em_Parser_ExtensionXmlAbstr
         * @throws  tx_em_ExtensionXmlException  in case of XML parser errors
         */
        public function parseXML($file) {
-
+               $this->createParser();
                if (!is_resource($this->objXML)) {
                        $this->throwException('Unable to create XML parser.');
                }
index fa23623..dd037f3 100644 (file)
  */
 class tx_em_Parser_MirrorXmlPullParser extends tx_em_Parser_MirrorXmlAbstractParser implements SplSubject {
 
+       /**
+        * Keeps XML parser.
+        *
+        * @var null|XMLReader
+        */
+       protected $objXML = NULL;
 
        /**
         * Keeps list of attached observers.
@@ -66,10 +72,16 @@ class tx_em_Parser_MirrorXmlPullParser extends tx_em_Parser_MirrorXmlAbstractPar
         */
        function __construct() {
                $this->requiredPHPExt = 'xmlreader';
+       }
 
-               if ($this->isAvailable()) {
-                       $this->objXML = new XMLReader();
-               }
+       /**
+        * Method creates the required parser.
+        *
+        * @access  protected
+        * @return  void
+        */
+       protected function createParser() {
+               $this->objXML = new XMLReader();
        }
 
        /**
@@ -81,6 +93,7 @@ class tx_em_Parser_MirrorXmlPullParser extends tx_em_Parser_MirrorXmlAbstractPar
         * @throws  em_mirrorxml_Exception  in case of XML parser errors
         */
        public function parseXML($file) {
+               $this->createParser();
                if (!(is_object($this->objXML) && (get_class($this->objXML) == 'XMLReader'))) {
                        $this->throwException('Unable to create XML parser.');
                }
index d3497fe..18caee2 100644 (file)
  */
 class tx_em_Parser_MirrorXmlPushParser extends tx_em_Parser_MirrorXmlAbstractParser implements SplSubject {
 
+       /**
+        * Keeps XML parser.
+        *
+        * @var null|resource
+        */
+       protected $objXML = NULL;
 
        /**
         * Keeps list of attached observers.
@@ -69,11 +75,17 @@ class tx_em_Parser_MirrorXmlPushParser extends tx_em_Parser_MirrorXmlAbstractPar
         */
        function __construct() {
                $this->requiredPHPExt = 'xml';
+       }
 
-               if ($this->isAvailable()) {
-                       $this->objXML = xml_parser_create();
-                       xml_set_object($this->objXML, $this);
-               }
+       /**
+        * Method creates the required parser.
+        *
+        * @access  protected
+        * @return  void
+        */
+       protected function createParser() {
+               $this->objXML = xml_parser_create();
+               xml_set_object($this->objXML, $this);
        }
 
        /**
@@ -84,7 +96,7 @@ class tx_em_Parser_MirrorXmlPushParser extends tx_em_Parser_MirrorXmlAbstractPar
         * @throws  em_mirrorxml_Exception  in case of XML parser errors
         */
        public function parseXML($file) {
-
+               $this->createParser();
                if (!is_resource($this->objXML)) {
                        $this->throwException('Unable to create XML parser.');
                }
index 1975117..ce0425d 100644 (file)
@@ -93,6 +93,14 @@ abstract class tx_em_Parser_XmlAbstractParser {
        abstract public function parseXML($file);
 
        /**
+        * Method creates the required parser.
+        *
+        * @access  protected
+        * @return  void
+        */
+       abstract protected function createParser();
+
+       /**
         * Method provides a wrapper for an exception call
         *
         * @access  protected