diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/BackendController.php b/public/typo3conf/ext/ep_products/Classes/Controller/BackendController.php index 17072f6a..40550a27 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/BackendController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/BackendController.php @@ -29,6 +29,7 @@ namespace EP\EpProducts\Controller; use EP\EpProducts\Service\ContingentImportService; use EP\EpProducts\Service\DateImportService; +use EP\EpProducts\Service\ImportTimestampService; use EP\EpProducts\Service\LogService; use EP\EpProducts\Service\SnowreportImportService; use TYPO3\CMS\Backend\View\BackendTemplateView; @@ -67,6 +68,10 @@ class BackendController extends ActionController * @var ContingentImportService */ protected $contingentImportService; + /** + * @var ImportTimestampService + */ + private $importTimestampService; /** * @param DateImportService $dateImportService @@ -79,7 +84,8 @@ class BackendController extends ActionController DateImportService $dateImportService, ContingentImportService $contingentImportService, SnowreportImportService $snowreportService, - LogService $logService + LogService $logService, + ImportTimestampService $importTimestampService ) { parent::__construct(); @@ -88,14 +94,12 @@ class BackendController extends ActionController $this->contingentImportService = $contingentImportService; $this->snowreportImportService = $snowreportService; $this->logService = $logService; + $this->importTimestampService = $importTimestampService; } public function indexAction() { - $updatedTimestampPath = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport/.lastupdate'); - if ($updatedTimestampPath && file_exists($updatedTimestampPath)) { - $updatedTimestamp = file_get_contents($updatedTimestampPath); - } + $updatedTimestamp = $this->importTimestampService->readImportTimestamp('fileadmin/products_import.info'); $this->view->assign('updatedTimestamp', $updatedTimestamp); } diff --git a/public/typo3conf/ext/ep_products/Classes/Service/ImportTimestampService.php b/public/typo3conf/ext/ep_products/Classes/Service/ImportTimestampService.php index 9f89f33f..3fc2844a 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/ImportTimestampService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/ImportTimestampService.php @@ -6,11 +6,29 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; class ImportTimestampService { + public function readImportTimestamp(string $importTimestampFile): ?\DateTime + { + $lastImportTimestampPath = GeneralUtility::getFileAbsFileName($importTimestampFile); + if (!$lastImportTimestampPath || !file_exists($lastImportTimestampPath)) { + return null; + } + + $line = trim(file($lastImportTimestampPath)[0]); + + return \DateTime::createFromFormat('d.m.Y H:i:s', $line); + } + + public function writeImportTimestamp(string $importTimestampFile): void + { + $lastImportTimestampPath = GeneralUtility::getFileAbsFileName($importTimestampFile); + $now = new \DateTime('now'); + file_put_contents($lastImportTimestampPath, $now->format('d.m.Y H:i:s')); + } + public function isImportRequired(string $uploadTimestampFile, string $importTimestampFile): bool { $updatedTimestampPath = GeneralUtility::getFileAbsFileName($uploadTimestampFile); - // No upload yet so no import required if (!$updatedTimestampPath || !file_exists($updatedTimestampPath)) { return false; } @@ -18,22 +36,10 @@ class ImportTimestampService $line = trim(file($updatedTimestampPath)[0]); $lastUploadAt = \DateTime::createFromFormat('d.m.Y H:i:s', $line); - $lastImportTimestampPath = GeneralUtility::getFileAbsFileName($importTimestampFile); + $lastImportAt = $this->readImportTimestamp($importTimestampFile); - // No import yet so import required - if (!$lastImportTimestampPath || !file_exists($lastImportTimestampPath)) { - $now = new \DateTime('now'); - file_put_contents($lastImportTimestampPath, $now->format('d.m.Y H:i:s')); - - return true; - } - - $line = trim(file($lastImportTimestampPath)[0]); - $lastImportAt = \DateTime::createFromFormat('d.m.Y H:i:s', $line); - - if ($lastUploadAt > $lastImportAt) { - $now = new \DateTime('now'); - file_put_contents($lastImportTimestampPath, $now->format('d.m.Y H:i:s')); + if (null === $lastImportAt || $lastUploadAt > $lastImportAt) { + $this->writeImportTimestamp($importTimestampFile); return true; } diff --git a/public/typo3conf/ext/ep_products/Resources/Private/Templates/Backend/Index.html b/public/typo3conf/ext/ep_products/Resources/Private/Templates/Backend/Index.html index c5b4538c..dddf8db0 100644 --- a/public/typo3conf/ext/ep_products/Resources/Private/Templates/Backend/Index.html +++ b/public/typo3conf/ext/ep_products/Resources/Private/Templates/Backend/Index.html @@ -8,7 +8,7 @@

E&P Funktionen

- Letzter XML Abruf aus BusPro: {f:if(condition: updatedTimestamp, then: updatedTimestamp, else: '-')} + Letzter automatischer XML Import: {f:if(condition: updatedTimestamp, then: '{updatedTimestamp -> f:format.date(format: \'d.m.Y H:i:s\')}', else: '-')}