Cleanup snowreport and webcam data after importing
This commit is contained in:
@@ -33,6 +33,7 @@ use EP\EpProducts\Domain\Repository\RegionRepository;
|
|||||||
use EP\EpProducts\Domain\Repository\SnowreportRepository;
|
use EP\EpProducts\Domain\Repository\SnowreportRepository;
|
||||||
use EP\EpProducts\Domain\Repository\WebcamRepository;
|
use EP\EpProducts\Domain\Repository\WebcamRepository;
|
||||||
use EP\EpProducts\Utility\SettingsUtility;
|
use EP\EpProducts\Utility\SettingsUtility;
|
||||||
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||||
use TYPO3\CMS\Core\SingletonInterface;
|
use TYPO3\CMS\Core\SingletonInterface;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
|
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
|
||||||
@@ -42,6 +43,16 @@ class SnowreportImportService implements SingletonInterface
|
|||||||
const XML_FILE_PATH = 'fileadmin/snowreport/snowreport.xml';
|
const XML_FILE_PATH = 'fileadmin/snowreport/snowreport.xml';
|
||||||
const XML_FILE_URL = 'http://www.skiresort-service.com/xml-feed/';
|
const XML_FILE_URL = 'http://www.skiresort-service.com/xml-feed/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $validSnowreportUids = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $validWebcamUids = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
|
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
|
||||||
*/
|
*/
|
||||||
@@ -170,11 +181,16 @@ class SnowreportImportService implements SingletonInterface
|
|||||||
$this->snowreportRepository->update($snowreport);
|
$this->snowreportRepository->update($snowreport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static::$validSnowreportUids[] = $vendorUid;
|
||||||
|
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->persistenceManager->persistAll();
|
$this->persistenceManager->persistAll();
|
||||||
|
|
||||||
|
$this->cleanupData('tx_epproducts_domain_model_webcam', static::$validWebcamUids);
|
||||||
|
$this->cleanupData('tx_epproducts_domain_model_snowreport', static::$validSnowreportUids);
|
||||||
|
|
||||||
$GLOBALS['BE_USER']->writelog(4, 0, 0, 0, sprintf('Snowreport XML import successful (%d records).', $count), []);
|
$GLOBALS['BE_USER']->writelog(4, 0, 0, 0, sprintf('Snowreport XML import successful (%d records).', $count), []);
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
@@ -206,9 +222,39 @@ class SnowreportImportService implements SingletonInterface
|
|||||||
$webcam->setName((string) $item->dt);
|
$webcam->setName((string) $item->dt);
|
||||||
$webcam->setAvailable((string) $item->verf === 'true');
|
$webcam->setAvailable((string) $item->verf === 'true');
|
||||||
}
|
}
|
||||||
|
static::$validWebcamUids[] = $vendorUid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function cleanupData($table, array $validUids)
|
||||||
|
{
|
||||||
|
/** @var ConnectionPool $connectionPool */
|
||||||
|
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
|
||||||
|
$qb = $connectionPool->getQueryBuilderForTable($table);
|
||||||
|
$result = $qb
|
||||||
|
->select('vendor_uid')
|
||||||
|
->from($table)
|
||||||
|
->execute()
|
||||||
|
->fetchAll()
|
||||||
|
;
|
||||||
|
|
||||||
|
$currentUids = array_map(function ($row) {
|
||||||
|
return (int)$row['vendor_uid'];
|
||||||
|
}, $result);
|
||||||
|
|
||||||
|
$obsoleteUids = array_diff($currentUids, $validUids);
|
||||||
|
if (0 === count($obsoleteUids)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb = $connectionPool->getQueryBuilderForTable($table);
|
||||||
|
$qb
|
||||||
|
->delete($table)
|
||||||
|
->where($qb->expr()->in('vendor_uid', $obsoleteUids))
|
||||||
|
->execute()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
public function downloadReportsXml()
|
public function downloadReportsXml()
|
||||||
{
|
{
|
||||||
$path = GeneralUtility::getFileAbsFileName(self::XML_FILE_PATH);
|
$path = GeneralUtility::getFileAbsFileName(self::XML_FILE_PATH);
|
||||||
|
|||||||
Reference in New Issue
Block a user