Mondcrater erweitert
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -76,6 +76,37 @@ function parseNullableDate(?string $value): ?string
|
||||
return null;
|
||||
}
|
||||
|
||||
function isSatelliteCraterRow(array $assoc, ?string $csvPath = null): bool
|
||||
{
|
||||
$nameType = normalizeImportValue($assoc['NAME_TYPE'] ?? null);
|
||||
if ($nameType !== null && strcasecmp($nameType, 'Satellite feature') === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($csvPath !== null) {
|
||||
$filename = basename($csvPath);
|
||||
if (stripos($filename, 'SATELLITE') !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function deriveParentCraterName(string $name, bool $isSatelliteCrater): ?string
|
||||
{
|
||||
if (!$isSatelliteCrater) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^(.*?)\s+([A-Z])$/', $name, $matches) === 1) {
|
||||
$parentName = trim($matches[1]);
|
||||
return $parentName !== '' ? $parentName : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function translateCatalogValue(string $field, ?string $value): ?string
|
||||
{
|
||||
$value = normalizeImportValue($value);
|
||||
@@ -168,6 +199,8 @@ function createMoonCraterTableSql(): string
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
lun VARCHAR(64) DEFAULT NULL,
|
||||
is_satellite_crater TINYINT(1) NOT NULL DEFAULT 0,
|
||||
parent_crater_name VARCHAR(255) DEFAULT NULL,
|
||||
name_type VARCHAR(255) DEFAULT NULL,
|
||||
iau_type VARCHAR(100) DEFAULT NULL,
|
||||
iau_type_de VARCHAR(100) DEFAULT NULL,
|
||||
@@ -239,6 +272,8 @@ function createMoonCraterTableSql(): string
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uniq_lun (lun),
|
||||
KEY idx_is_satellite_crater (is_satellite_crater),
|
||||
KEY idx_parent_crater_name (parent_crater_name),
|
||||
KEY idx_name (name),
|
||||
KEY idx_type (type),
|
||||
KEY idx_face (face),
|
||||
@@ -263,16 +298,33 @@ function ensureMoonCraterTable(PDO $pdo): void
|
||||
$columns[] = (string)($row['Field'] ?? '');
|
||||
}
|
||||
|
||||
$requiredColumns = ['name', 'lun', 'iau_type', 'type', 'longi_n_360', 'lati_n'];
|
||||
$missingColumns = array_values(array_diff($requiredColumns, $columns));
|
||||
$alterStatements = [];
|
||||
|
||||
if ($missingColumns === []) {
|
||||
return;
|
||||
if (!in_array('is_satellite_crater', $columns, true)) {
|
||||
$alterStatements[] = "ADD COLUMN is_satellite_crater TINYINT(1) NOT NULL DEFAULT 0 AFTER lun";
|
||||
}
|
||||
|
||||
$backupTable = 'moon_craters_backup_' . date('Ymd_His');
|
||||
$pdo->exec("RENAME TABLE moon_craters TO `" . $backupTable . "`");
|
||||
$pdo->exec(createMoonCraterTableSql());
|
||||
if (!in_array('parent_crater_name', $columns, true)) {
|
||||
$alterStatements[] = "ADD COLUMN parent_crater_name VARCHAR(255) DEFAULT NULL AFTER is_satellite_crater";
|
||||
}
|
||||
|
||||
if ($alterStatements !== []) {
|
||||
$pdo->exec("ALTER TABLE moon_craters\n " . implode(",\n ", $alterStatements));
|
||||
}
|
||||
|
||||
$indexNames = [];
|
||||
$indexStmt = $pdo->query("SHOW INDEX FROM moon_craters");
|
||||
foreach ($indexStmt->fetchAll() as $row) {
|
||||
$indexNames[] = (string)($row['Key_name'] ?? '');
|
||||
}
|
||||
|
||||
if (!in_array('idx_is_satellite_crater', $indexNames, true)) {
|
||||
$pdo->exec("ALTER TABLE moon_craters ADD KEY idx_is_satellite_crater (is_satellite_crater)");
|
||||
}
|
||||
|
||||
if (!in_array('idx_parent_crater_name', $indexNames, true)) {
|
||||
$pdo->exec("ALTER TABLE moon_craters ADD KEY idx_parent_crater_name (parent_crater_name)");
|
||||
}
|
||||
}
|
||||
|
||||
$report = null;
|
||||
@@ -344,7 +396,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$headers = array_map(static fn($value) => strtoupper((string)$value), $headers);
|
||||
|
||||
$insertSql = "INSERT INTO moon_craters (
|
||||
name, lun, name_type, iau_type, iau_type_de, type, type_de, subtype, subtype_de,
|
||||
name, lun, is_satellite_crater, parent_crater_name, name_type, iau_type, iau_type_de, type, type_de, subtype, subtype_de,
|
||||
process, process_de, period, period_de, period_source, geology, geology_de,
|
||||
name_detail, name_origin, iau_approval_date, langrenus, hevelius, riccioli, work,
|
||||
country, country_de, nationality, nationality_de, century_n, century_c, birth_place,
|
||||
@@ -354,7 +406,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
interest_c_de, lunation, moonday_s, moonday_s_de, moonday_m, moonday_m_de, diam_inst,
|
||||
diam_inst_de, th_instru, th_instru_de, pr_instru, pr_instru_de, source_row_json
|
||||
) VALUES (
|
||||
:name, :lun, :name_type, :iau_type, :iau_type_de, :type, :type_de, :subtype, :subtype_de,
|
||||
:name, :lun, :is_satellite_crater, :parent_crater_name, :name_type, :iau_type, :iau_type_de, :type, :type_de, :subtype, :subtype_de,
|
||||
:process, :process_de, :period, :period_de, :period_source, :geology, :geology_de,
|
||||
:name_detail, :name_origin, :iau_approval_date, :langrenus, :hevelius, :riccioli, :work,
|
||||
:country, :country_de, :nationality, :nationality_de, :century_n, :century_c, :birth_place,
|
||||
@@ -366,6 +418,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name),
|
||||
is_satellite_crater = VALUES(is_satellite_crater),
|
||||
parent_crater_name = VALUES(parent_crater_name),
|
||||
name_type = VALUES(name_type),
|
||||
iau_type = VALUES(iau_type),
|
||||
iau_type_de = VALUES(iau_type_de),
|
||||
@@ -454,9 +508,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isSatelliteCrater = isSatelliteCraterRow($assoc, $uploadedLabel ?? $csvPath);
|
||||
|
||||
$payload = [
|
||||
'name' => $name,
|
||||
'lun' => normalizeImportValue($assoc['LUN'] ?? null),
|
||||
'is_satellite_crater' => $isSatelliteCrater ? 1 : 0,
|
||||
'parent_crater_name' => deriveParentCraterName($name, $isSatelliteCrater),
|
||||
'name_type' => normalizeImportValue($assoc['NAME_TYPE'] ?? null),
|
||||
'iau_type' => normalizeImportValue($assoc['IAU_TYPE'] ?? null),
|
||||
'iau_type_de' => translateCatalogValue('iau_type', $assoc['IAU_TYPE'] ?? null),
|
||||
|
||||
Reference in New Issue
Block a user