From c78dc5db3288c2070a15a5db37ed0f1a5aa2ee48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Sun, 28 Jul 2019 13:18:07 +0200 Subject: [PATCH] Avoid errors caused by corrupted xml files --- .../Classes/Service/ContingentImportService.php | 2 +- .../Classes/Service/DateImportService.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php b/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php index 077725de..6e22a50d 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php @@ -121,7 +121,7 @@ class ContingentImportService implements SingletonInterface { libxml_use_internal_errors (true); /** @var \SimpleXMLElement $xmlData */ - if (!$xmlData = simplexml_load_file($file)) { + if (!$xmlData = simplexml_load_string(file_get_contents($file))) { libxml_clear_errors(); return 0; } diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php index 4c27c6e0..f0942248 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php @@ -171,8 +171,12 @@ class DateImportService implements SingletonInterface */ public function parseProductXmlFile($file) { + libxml_use_internal_errors (true); /** @var \SimpleXMLElement $xmlData */ - $xmlData = simplexml_load_file($file); + if (!$xmlData = simplexml_load_string(file_get_contents($file))) { + libxml_clear_errors(); + return 0; + } if ($xmlData->reise[0] === null) { return 0; @@ -798,14 +802,18 @@ class DateImportService implements SingletonInterface if (!array_key_exists($key, $list)) { $list[$key] = []; } - $list[$key] = array_merge($list[$key], $section); + $list[$key] += $section; } } protected function importPickups() { + libxml_use_internal_errors (true); $path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport/zustiege.xml'); - $xmlData = simplexml_load_file($path); + if (!$xmlData = simplexml_load_string(file_get_contents($path))) { + libxml_clear_errors(); + return; + } foreach ($xmlData->zustieg as $entry) {