Initial
Takes in a file, process it and output a new file with additional columns.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') {
|
||||
fwrite(STDERR, "This script must be run from the command line.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$token = (string) ($argv[1] ?? '');
|
||||
if ($token === '') {
|
||||
fwrite(STDERR, "Missing import token.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@set_time_limit(0);
|
||||
@ini_set('memory_limit', '-1');
|
||||
|
||||
$database = \App\Database::fromConfig($GLOBALS['appConfig'] ?? []);
|
||||
$repository = \App\Import\ImportRepository::fromDatabase($database);
|
||||
$jobStore = new \App\Import\ImportJobStore();
|
||||
$service = new \App\Import\ImportService(
|
||||
new \App\Import\SpreadsheetReader(),
|
||||
new \App\Import\SpreadsheetRowProcessor(),
|
||||
$repository,
|
||||
);
|
||||
|
||||
$state = $jobStore->get($token);
|
||||
if (!is_array($state)) {
|
||||
fwrite(STDERR, "Import job not found.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (!in_array(($state['status'] ?? 'pending'), ['completed', 'error'], true)) {
|
||||
$state = $service->processJobState($state);
|
||||
$jobStore->save($token, $state);
|
||||
}
|
||||
|
||||
if (($state['status'] ?? '') === 'error') {
|
||||
fwrite(STDERR, (string) ($state['message'] ?? 'Import failed.') . "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite(STDOUT, "Import completed.\n");
|
||||
Reference in New Issue
Block a user