Improve skipping detection in TYPO3 converter

All records which are not saved or useable are now skipped.
Some records were converted but could not be stored, e.g. because no
localization was configured for that table.

This should bring small performance improvement and also align import
log with actually imported (converted) records.

Logging is added as well, only debug level, to allow developer and
integrator to analyse why some records are skipped.

Ignore some errors which don't actually exist.
We already check type of entity, and logger is always injected.
This commit is contained in:
Daniel Siepmann 2021-09-02 10:02:24 +02:00
parent 07f189a7f8
commit 5179e82706
5 changed files with 77 additions and 10 deletions

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace WerkraumMedia\ThueCat\Domain\Import;
use TYPO3\CMS\Core\Utility\StringUtility;
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration as Typo3ImportConfiguration;
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLog;
/**
@ -56,6 +57,10 @@ class Import
public function start(ImportConfiguration $configuration): void
{
if (!$configuration instanceof Typo3ImportConfiguration) {
throw new \InvalidArgumentException('Currently only can process ImportConfiguration of TYPO3.', 1629708772);
}
$this->currentConfiguration = $configuration;
$this->currentImportLog = new ImportLog($configuration);

View file

@ -33,7 +33,6 @@ use WerkraumMedia\ThueCat\Domain\Import\Importer\SaveData;
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
use WerkraumMedia\ThueCat\Domain\Import\UrlProvider\Registry as UrlProviderRegistry;
use WerkraumMedia\ThueCat\Domain\Import\UrlProvider\UrlProvider;
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration as Typo3ImportConfiguration;
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLog;
use WerkraumMedia\ThueCat\Domain\Repository\Backend\ImportLogRepository;
@ -107,10 +106,6 @@ class Importer
public function importConfiguration(ImportConfiguration $configuration): ImportLog
{
if (!$configuration instanceof Typo3ImportConfiguration) {
throw new \InvalidArgumentException('Currently only can process ImportConfiguration of TYPO3.', 1629708772);
}
$this->import->start($configuration);
$this->import();
$this->import->end();

View file

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace WerkraumMedia\ThueCat\Domain\Import\Typo3Converter;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use WerkraumMedia\ThueCat\Domain\Import\Entity\AccessibilitySpecification;
use WerkraumMedia\ThueCat\Domain\Import\Entity\Base;
@ -46,8 +48,10 @@ use WerkraumMedia\ThueCat\Domain\Repository\Backend\OrganisationRepository;
use WerkraumMedia\ThueCat\Domain\Repository\Backend\ParkingFacilityRepository;
use WerkraumMedia\ThueCat\Domain\Repository\Backend\TownRepository;
class GeneralConverter implements Converter
class GeneralConverter implements Converter, LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* @var ResolveForeignReference
*/
@ -115,13 +119,13 @@ class GeneralConverter implements Converter
ImportConfiguration $importConfiguration,
string $language
): ?Entity {
$this->importConfiguration = $importConfiguration;
if (!$entity instanceof Minimum || $entity->hasName() === false) {
if ($this->shouldConvert($entity, $importConfiguration, $language) === false) {
return null;
}
return new GenericEntity(
$this->importConfiguration = $importConfiguration;
$converted = new GenericEntity(
$importConfiguration->getStoragePid(),
$this->getTableNameByEntityClass(get_class($entity)),
$this->languageHandling->getLanguageUidForString(
@ -134,6 +138,53 @@ class GeneralConverter implements Converter
$language
)
);
$this->logger->debug('Converted Entity', [
'remoteId' => $entity->getId(),
'storagePid' => $converted->getTypo3StoragePid(),
'table' => $converted->getTypo3DatabaseTableName(),
'language' => $converted->getTypo3SystemLanguageUid(),
]);
return $converted;
}
private function shouldConvert(
MapsToType $entity,
ImportConfiguration $importConfiguration,
string $language
): bool {
if (!$entity instanceof Minimum) {
$this->logger->debug('Skipped conversion of entity, got unexpected type', [
'expectedType' => Minimum::class,
'actualType' => get_class($entity),
]);
return false;
}
if ($entity->hasName() === false) {
$this->logger->debug('Skipped conversion of entity, had no name', [
'remoteId' => $entity->getId(),
]);
return false;
}
$languageUid = $this->languageHandling->getLanguageUidForString(
$importConfiguration->getStoragePid(),
$language
);
$tableName = $this->getTableNameByEntityClass(get_class($entity));
if (
$languageUid > 0
&& isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) === false
) {
$this->logger->debug('Skipped conversion of entity, table does not support translations', [
'remoteId' => $entity->getId(),
'requestedLanguage' => $language,
'resolvedLanguageUid' => $languageUid,
'resolvedTableName' => $tableName,
]);
return false;
}
return true;
}
private function getTableNameByEntityClass(string $className): string

View file

@ -33,6 +33,7 @@
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"psr/log": "^1.1",
"symfony/console": "^5.2",
"symfony/dependency-injection": "^5.2",
"symfony/property-access": "^5.3",

View file

@ -15,6 +15,21 @@ parameters:
count: 2
path: Classes/Domain/Import/Importer/SaveData.php
-
message: "#^Call to an undefined method WerkraumMedia\\\\ThueCat\\\\Domain\\\\Import\\\\Entity\\\\MapsToType\\:\\:getId\\(\\)\\.$#"
count: 2
path: Classes/Domain/Import/Typo3Converter/GeneralConverter.php
-
message: "#^Cannot call method debug\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
count: 4
path: Classes/Domain/Import/Typo3Converter/GeneralConverter.php
-
message: "#^Parameter \\#1 \\$entity of method WerkraumMedia\\\\ThueCat\\\\Domain\\\\Import\\\\Typo3Converter\\\\GeneralConverter\\:\\:buildDataArrayFromEntity\\(\\) expects WerkraumMedia\\\\ThueCat\\\\Domain\\\\Import\\\\Entity\\\\Minimum, WerkraumMedia\\\\ThueCat\\\\Domain\\\\Import\\\\Entity\\\\MapsToType given\\.$#"
count: 1
path: Classes/Domain/Import/Typo3Converter/GeneralConverter.php
-
message: "#^Property WerkraumMedia\\\\ThueCat\\\\Domain\\\\Model\\\\Backend\\\\ImportLog\\:\\:\\$logEntries \\(iterable\\<WerkraumMedia\\\\ThueCat\\\\Domain\\\\Model\\\\Backend\\\\ImportLogEntry\\>&TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage\\) does not accept TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage\\.$#"
count: 1