From 95b3ebae5ecc9d092e4268956e244db7a2899006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Tue, 8 Jun 2021 18:02:45 +0200 Subject: [PATCH] Improve settings utility --- .../Service/SnowreportImportService.php | 12 +++++-- .../Classes/Utility/SettingsUtility.php | 31 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Service/SnowreportImportService.php b/public/typo3conf/ext/ep_products/Classes/Service/SnowreportImportService.php index 85b09ce1..5028dcca 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/SnowreportImportService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/SnowreportImportService.php @@ -122,7 +122,7 @@ class SnowreportImportService implements SingletonInterface $xmlContent = file_get_contents($file); $xmlData = simplexml_load_string($xmlContent); - $snowReportStoragePid = SettingsUtility::get('snowReportStoragePid'); + $snowReportStoragePid = $this->getStoragePid(); foreach ($xmlData->schneemeldung as $reportXml) { @@ -202,7 +202,7 @@ class SnowreportImportService implements SingletonInterface */ public function importWebcamData(\SimpleXMLElement $xml, Snowreport $snowreport) { - $snowReportStoragePid = SettingsUtility::get('snowReportStoragePid'); + $snowReportStoragePid = $this->getStoragePid(); foreach ($xml->children() as $item) { $include = (string) $item->aktuell === 'true'; @@ -243,7 +243,7 @@ class SnowreportImportService implements SingletonInterface ->select('vendor_uid') ->from($table) ->execute() - ->fetchAll() + ->fetchAllAssociative() ; $currentUids = array_map(function ($row) { @@ -282,4 +282,10 @@ class SnowreportImportService implements SingletonInterface @rename($backupPath, $path); } + public function getStoragePid() + { + $settingsUtility = new SettingsUtility(); + + return $settingsUtility->get('snowReportStoragePid'); + } } diff --git a/public/typo3conf/ext/ep_products/Classes/Utility/SettingsUtility.php b/public/typo3conf/ext/ep_products/Classes/Utility/SettingsUtility.php index 5df72390..4e6fecdb 100644 --- a/public/typo3conf/ext/ep_products/Classes/Utility/SettingsUtility.php +++ b/public/typo3conf/ext/ep_products/Classes/Utility/SettingsUtility.php @@ -34,23 +34,32 @@ use TYPO3\CMS\Extbase\Object\ObjectManager; class SettingsUtility { + /** + * @var array + */ + protected $settings = []; + + public function __construct() + { + /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $configurationManager = $objectManager->get(ConfigurationManager::class); + $settings = GeneralUtility::removeDotsFromTS( + $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT) + ); + $this->settings = $settings['plugin']['tx_epproducts']['settings']; + } /** * @param string $key * @return string|array */ - static public function get($key = null) + public function get($key = null) { - /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); - $configurationManager = $objectManager->get(ConfigurationManager::class); - $settings = GeneralUtility::removeDotsFromTS($configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)); - - if ($key !== null && array_key_exists($key, $settings['plugin']['tx_epproducts']['settings'])) { - return $settings['plugin']['tx_epproducts']['settings'][$key]; + if ($key !== null && array_key_exists($key, $this->settings)) { + return $this->settings[$key]; } - return $settings['plugin']['tx_epproducts']['settings']; + return $this->settings; } - -} \ No newline at end of file +}