_
. The live tables are backed up first and restored at the end.
*/
putenv('TYPO3_PATH_ROOT=/var/www/html/public');
putenv('TYPO3_PATH_APP=/var/www/html');
$classLoader = require '/var/www/html/vendor/autoload.php';
\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(0, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI);
\TYPO3\CMS\Core\Core\Bootstrap::init($classLoader);
use EP\EpProducts\Service\ApiImportSource;
use EP\EpProducts\Service\DateImportService;
use EP\EpProducts\Service\XmlProductReader;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
$db = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionByName('Default');
$tables = ['date' => 'tx_epproducts_domain_model_date', 'room' => 'tx_epproducts_domain_model_room', 'product' => 'tx_epproducts_domain_model_product'];
$snapshot = function (string $prefix) use ($db, $tables) {
foreach ($tables as $short => $table) {
$db->executeStatement("DROP TABLE IF EXISTS cmp_{$prefix}_{$short}");
$db->executeStatement("CREATE TABLE cmp_{$prefix}_{$short} AS SELECT * FROM {$table}");
}
};
$restore = function () use ($db, $tables) {
foreach ($tables as $short => $table) {
$db->executeStatement("DELETE FROM {$table}");
$db->executeStatement("INSERT INTO {$table} SELECT * FROM cmp_bak_{$short}");
}
};
$snapshot('bak');
try {
$reader = new XmlProductReader(GeneralUtility::getFileAbsFileName('fileadmin/xmlexport'));
$rows = iterator_to_array($reader, false);
$count = GeneralUtility::makeInstance(DateImportService::class)->import($rows);
printf("xml: %d rows, %d dates imported, source generated at %s\n", count($rows), $count,
$reader->getSourceGeneratedAt() ? $reader->getSourceGeneratedAt()->format('c') : '?');
$snapshot('xml');
$restore();
// Bypass the "already imported" baseline: walk the export pages directly
$api = GeneralUtility::makeInstance(ApiImportSource::class);
$walk = new \ReflectionMethod($api, 'walkPages');
$walk->setAccessible(true);
$export = $walk->invoke($api);
if (!is_array($export)) {
throw new \RuntimeException('MyE&P export walk returned ' . var_export($export, true));
}
[$apiRows, $generatedAt] = $export;
$count = GeneralUtility::makeInstance(DateImportService::class)->import($apiRows);
printf("api: %d rows, %d dates imported, source generated at %s\n", count($apiRows), $count,
$generatedAt ? $generatedAt->format('c') : '?');
$snapshot('api');
// Raw rows of both sources, for a field-by-field comparison independent of the import
file_put_contents('/var/www/html/var/rows_xml.json', json_encode($rows));
file_put_contents('/var/www/html/var/rows_api.json', json_encode($apiRows));
} finally {
$restore();
echo "live tables restored\n";
}