Mondcrater erweitert

This commit is contained in:
Eskimue
2026-04-08 11:11:14 +02:00
parent e7ffbffd00
commit 049eb73a3d
5 changed files with 9153 additions and 14 deletions
+5 -5
View File
@@ -404,7 +404,7 @@ expose_php = On
; Maximum execution time of each script, in seconds ; Maximum execution time of each script, in seconds
; https://php.net/max-execution-time ; https://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI ; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 30 max_execution_time = 120
; Maximum amount of time each script may spend parsing request data. It's a good ; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly ; idea to limit this time on productions servers in order to eliminate unexpectedly
@@ -414,7 +414,7 @@ max_execution_time = 30
; Development Value: 60 (60 seconds) ; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds) ; Production Value: 60 (60 seconds)
; https://php.net/max-input-time ; https://php.net/max-input-time
max_input_time = 60 max_input_time = 120
; Maximum input variable nesting level ; Maximum input variable nesting level
; https://php.net/max-input-nesting-level ; https://php.net/max-input-nesting-level
@@ -430,7 +430,7 @@ max_input_time = 60
; Maximum amount of memory a script may consume ; Maximum amount of memory a script may consume
; https://php.net/memory-limit ; https://php.net/memory-limit
memory_limit = 128M memory_limit = 256M
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ; ; Error handling and logging ;
@@ -694,7 +694,7 @@ auto_globals_jit = On
; Its value may be 0 to disable the limit. It is ignored if POST data reading ; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading. ; is disabled through enable_post_data_reading.
; https://php.net/post-max-size ; https://php.net/post-max-size
post_max_size = 8M post_max_size = 32M
; Automatically add files before PHP document. ; Automatically add files before PHP document.
; https://php.net/auto-prepend-file ; https://php.net/auto-prepend-file
@@ -846,7 +846,7 @@ file_uploads = On
; Maximum allowed size for uploaded files. ; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize ; https://php.net/upload-max-filesize
upload_max_filesize = 2M upload_max_filesize = 32M
; Maximum number of files that can be uploaded via a single request ; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20 max_file_uploads = 20
+4
View File
@@ -417,6 +417,8 @@ CREATE TABLE IF NOT EXISTS `moon_craters` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`lun` varchar(64) DEFAULT 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, `name_type` varchar(255) DEFAULT NULL,
`iau_type` varchar(100) DEFAULT NULL, `iau_type` varchar(100) DEFAULT NULL,
`iau_type_de` varchar(100) DEFAULT NULL, `iau_type_de` varchar(100) DEFAULT NULL,
@@ -488,6 +490,8 @@ CREATE TABLE IF NOT EXISTS `moon_craters` (
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `uniq_lun` (`lun`), 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_name` (`name`),
KEY `idx_type` (`type`), KEY `idx_type` (`type`),
KEY `idx_face` (`face`), KEY `idx_face` (`face`),
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+67 -9
View File
@@ -76,6 +76,37 @@ function parseNullableDate(?string $value): ?string
return null; 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 function translateCatalogValue(string $field, ?string $value): ?string
{ {
$value = normalizeImportValue($value); $value = normalizeImportValue($value);
@@ -168,6 +199,8 @@ function createMoonCraterTableSql(): string
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
lun VARCHAR(64) DEFAULT 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, name_type VARCHAR(255) DEFAULT NULL,
iau_type VARCHAR(100) DEFAULT NULL, iau_type VARCHAR(100) DEFAULT NULL,
iau_type_de 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, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uniq_lun (lun), 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_name (name),
KEY idx_type (type), KEY idx_type (type),
KEY idx_face (face), KEY idx_face (face),
@@ -263,16 +298,33 @@ function ensureMoonCraterTable(PDO $pdo): void
$columns[] = (string)($row['Field'] ?? ''); $columns[] = (string)($row['Field'] ?? '');
} }
$requiredColumns = ['name', 'lun', 'iau_type', 'type', 'longi_n_360', 'lati_n']; $alterStatements = [];
$missingColumns = array_values(array_diff($requiredColumns, $columns));
if ($missingColumns === []) { if (!in_array('is_satellite_crater', $columns, true)) {
return; $alterStatements[] = "ADD COLUMN is_satellite_crater TINYINT(1) NOT NULL DEFAULT 0 AFTER lun";
} }
$backupTable = 'moon_craters_backup_' . date('Ymd_His'); if (!in_array('parent_crater_name', $columns, true)) {
$pdo->exec("RENAME TABLE moon_craters TO `" . $backupTable . "`"); $alterStatements[] = "ADD COLUMN parent_crater_name VARCHAR(255) DEFAULT NULL AFTER is_satellite_crater";
$pdo->exec(createMoonCraterTableSql()); }
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; $report = null;
@@ -344,7 +396,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$headers = array_map(static fn($value) => strtoupper((string)$value), $headers); $headers = array_map(static fn($value) => strtoupper((string)$value), $headers);
$insertSql = "INSERT INTO moon_craters ( $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, process, process_de, period, period_de, period_source, geology, geology_de,
name_detail, name_origin, iau_approval_date, langrenus, hevelius, riccioli, work, name_detail, name_origin, iau_approval_date, langrenus, hevelius, riccioli, work,
country, country_de, nationality, nationality_de, century_n, century_c, birth_place, 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, 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 diam_inst_de, th_instru, th_instru_de, pr_instru, pr_instru_de, source_row_json
) VALUES ( ) 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, :process, :process_de, :period, :period_de, :period_source, :geology, :geology_de,
:name_detail, :name_origin, :iau_approval_date, :langrenus, :hevelius, :riccioli, :work, :name_detail, :name_origin, :iau_approval_date, :langrenus, :hevelius, :riccioli, :work,
:country, :country_de, :nationality, :nationality_de, :century_n, :century_c, :birth_place, :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 ON DUPLICATE KEY UPDATE
name = VALUES(name), name = VALUES(name),
is_satellite_crater = VALUES(is_satellite_crater),
parent_crater_name = VALUES(parent_crater_name),
name_type = VALUES(name_type), name_type = VALUES(name_type),
iau_type = VALUES(iau_type), iau_type = VALUES(iau_type),
iau_type_de = VALUES(iau_type_de), iau_type_de = VALUES(iau_type_de),
@@ -454,9 +508,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
continue; continue;
} }
$isSatelliteCrater = isSatelliteCraterRow($assoc, $uploadedLabel ?? $csvPath);
$payload = [ $payload = [
'name' => $name, 'name' => $name,
'lun' => normalizeImportValue($assoc['LUN'] ?? null), 'lun' => normalizeImportValue($assoc['LUN'] ?? null),
'is_satellite_crater' => $isSatelliteCrater ? 1 : 0,
'parent_crater_name' => deriveParentCraterName($name, $isSatelliteCrater),
'name_type' => normalizeImportValue($assoc['NAME_TYPE'] ?? null), 'name_type' => normalizeImportValue($assoc['NAME_TYPE'] ?? null),
'iau_type' => normalizeImportValue($assoc['IAU_TYPE'] ?? null), 'iau_type' => normalizeImportValue($assoc['IAU_TYPE'] ?? null),
'iau_type_de' => translateCatalogValue('iau_type', $assoc['IAU_TYPE'] ?? null), 'iau_type_de' => translateCatalogValue('iau_type', $assoc['IAU_TYPE'] ?? null),