[BUGFIX] Old EM: t3lib_DB::exec_INSERTquery errors
authorJigal van Hemert <jigal@xs4all.nl>
Sat, 6 Aug 2011 09:01:04 +0000 (11:01 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Thu, 11 Aug 2011 07:14:58 +0000 (09:14 +0200)
storeXMLResult() fails to filter non-existing database fields and
tries to insert all fields which it parses from the XML. Solution
is to use a default record structure to only use existing column names.

Change-Id: I80ca3170c2840b44497398b2b9cf48c285dc2215
Fixes: #28637
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/4169
Reviewed-by: Rens Admiraal
Reviewed-by: Stefan Neufeind
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/em/classes/tools/class.tx_em_tools_xmlhandler.php

index d0fa556..ac82161 100644 (file)
@@ -102,6 +102,33 @@ class tx_em_Tools_XmlHandler {
        protected $currentTag = '';
 
        /**
+        * @var array Structure of extension record
+        */
+       protected $defaultExtensionRecord = array(
+               'extkey' => '',
+               'repository' => '1',
+               'version' => '',
+               'alldownloadcounter' => '0',
+               'downloadcounter' => '0',
+               'title' => '',
+               'description' => '',
+               'state' => '0',
+               'reviewstate' => '0',
+               'category' => '0',
+               'lastuploaddate' => '0',
+               'dependencies' => '',
+               'authorname' => '',
+               'authoremail' => '',
+               'ownerusername' => '',
+               't3xfilemd5' => '',
+               'uploadcomment' => '',
+               'authorcompany' => '',
+               'intversion' => '0',
+               'lastversion' => '0',
+               'lastreviewedversion' => '0',
+       );
+
+       /**
         * Reduces the entries in $this->extensionsXML to the latest version per extension and removes entries not matching the search parameter
         *
         * @param       string          $search         The list of extensions is reduced to entries matching this. If empty, the full list is returned.
@@ -514,7 +541,13 @@ class tx_em_Tools_XmlHandler {
                                        $vArr['lastreviewedversion'] = 1;
                                }
                                $vArr['state'] = isset($this->revStateArr[$vArr['state']]) ? $this->revStateArr[$vArr['state']] : $usestate; // 999 = not set category
-                               $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_extensions', $vArr);
+                                       // filter unusable fields
+                               $newRecord = array_intersect_key($vArr, $this->defaultExtensionRecord);
+                                       // add default values for fields
+                               $newRecord = t3lib_div::array_merge_recursive_overrule($this->defaultExtensionRecord, $newRecord, TRUE);
+                               if (!(empty($newRecord['extkey']) || empty($newRecord['version']))) {
+                                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_extensions', $newRecord);
+                               }
                        }
                }
        }