Improve timetamp parsing, update date of last import in backend

This commit is contained in:
Björn Fromme
2021-02-04 21:14:51 +01:00
parent c8964e4ec6
commit 407e625aa9
3 changed files with 32 additions and 22 deletions
@@ -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);
}
@@ -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;
}
@@ -8,7 +8,7 @@
<h1>E&amp;P Funktionen</h1>
<f:flashMessages />
<p>
<strong>Letzter XML Abruf aus BusPro: {f:if(condition: updatedTimestamp, then: updatedTimestamp, else: '-')}</strong>
<strong>Letzter automatischer XML Import: {f:if(condition: updatedTimestamp, then: '{updatedTimestamp -> f:format.date(format: \'d.m.Y H:i:s\')}', else: '-')}</strong>
</p>
<p>
<f:link.action action="importProducts" class="btn btn-default">