Collect unmapped entries in dry-run mode
See museum-digital/importer#235
This commit is contained in:
@@ -9,21 +9,48 @@ final class MDImporterMissingConcordance extends Exception {
|
||||
public string $target_type;
|
||||
public string $value_to_map;
|
||||
|
||||
/** @var array<string, string> */
|
||||
private static array $_missing_concordances = [];
|
||||
|
||||
/**
|
||||
* Sets up an error.
|
||||
*
|
||||
* @param string $target_type Target type (e.g. "measurements").
|
||||
* @param string $value_to_map Value to map.
|
||||
*
|
||||
* @return MDImporterMissingConcordance
|
||||
* @return void
|
||||
*/
|
||||
public static function setup(string $target_type, string $value_to_map):MDImporterMissingConcordance {
|
||||
public static function throw(string $target_type, string $value_to_map):void {
|
||||
|
||||
if (class_exists("MD_IMPORTER_CONF") && MD_IMPORTER_CONF::$dry_run === true) {
|
||||
|
||||
if (empty(self::$_missing_concordances)) {
|
||||
|
||||
// Register printing at the end
|
||||
register_shutdown_function(function() {
|
||||
echo PHP_EOL . PHP_EOL . "There are unmapped concordances. Please map them before proceeding." . PHP_EOL . "You may use https://concordance.museum-digital.org/ to do the mapping" . PHP_EOL . PHP_EOL;
|
||||
foreach (self::$_missing_concordances as $key => $values) {
|
||||
sort($values);
|
||||
echo PHP_EOL . PHP_EOL . $key . PHP_EOL . PHP_EOL;
|
||||
echo implode(PHP_EOL, array_unique($values));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (!isset(self::$_missing_concordances[$target_type])) {
|
||||
self::$_missing_concordances[$target_type] = [];
|
||||
}
|
||||
self::$_missing_concordances[$target_type][] = $value_to_map;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$exception = new MDImporterMissingConcordance("Unmapped specific value of type " . $target_type . ": " . $value_to_map);
|
||||
$exception->target_type = $target_type;
|
||||
$exception->value_to_map = $value_to_map;
|
||||
|
||||
return $exception;
|
||||
throw $exception;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user