DB-field mapping per import model, so editors * configure the mapper once and reuse it on every delivery. * * Plain table without TCA (tx_vitec_import_mapping) - the records are pure * tool configuration, never edited through FormEngine. */ final class MappingRepository { private const TABLE = 'tx_vitec_import_mapping'; /** * @return array{mapping: array, identity: string}|null */ public function load(string $model): ?array { $qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE); $row = $qb->select('mapping', 'identity_field')->from(self::TABLE) ->where($qb->expr()->eq('model', $qb->createNamedParameter($model, ParameterType::STRING))) ->setMaxResults(1) ->executeQuery()->fetchAssociative(); if (!$row) { return null; } $mapping = json_decode((string)$row['mapping'], true); if (!is_array($mapping)) { return null; } return [ 'mapping' => array_map('strval', $mapping), 'identity' => (string)$row['identity_field'], ]; } /** @param array $mapping */ public function save(string $model, array $mapping, string $identity): void { $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::TABLE); $values = [ 'mapping' => (string)json_encode($mapping, JSON_UNESCAPED_UNICODE), 'identity_field' => $identity, 'tstamp' => time(), ]; $exists = $connection->count('uid', self::TABLE, ['model' => $model]) > 0; if ($exists) { $connection->update(self::TABLE, $values, ['model' => $model]); } else { $connection->insert(self::TABLE, $values + [ 'model' => $model, 'pid' => 0, 'crdate' => time(), ]); } } }