From d244065dbee689137b1ed549200abbff08d6e0a0 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 27 May 2021 02:33:51 +0200 Subject: [PATCH] Update base update time of places when editing a place --- src/NodaIDGetter.php | 30 ++++++++++++++++++++++++++++++ src/NodaLogEdit.php | 16 ++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/NodaIDGetter.php b/src/NodaIDGetter.php index 576eebf..9d8031f 100644 --- a/src/NodaIDGetter.php +++ b/src/NodaIDGetter.php @@ -143,6 +143,36 @@ final class NodaIDGetter { } + /** + * Returns place ID by base name. + * + * @param MDMysqli $mysqli_noda Database connection. + * @param string $name Name of the place to search for. + * + * @return integer + */ + public static function getPlaceIDByBaseName(MDMysqli $mysqli_noda, string $name):int { + + if (empty($name)) return 0; + + $placeByBaseNameResult = $mysqli_noda->query_by_stmt(" + SELECT `ort_id` + FROM `orte` + WHERE `ort_name` = ? + LIMIT 2", "s", $name); + + if ($placeByBaseData = $placeByBaseNameResult->fetch_row()) { + $output = $placeByBaseData[0]; + } + else $output = 0; + + $placeByBaseNameResult->close(); + $placeByBaseNameResult = null; + + return $output; + + } + /** * Returns place ID by entry in place translations table. * diff --git a/src/NodaLogEdit.php b/src/NodaLogEdit.php index db8d6c5..5db4b77 100644 --- a/src/NodaLogEdit.php +++ b/src/NodaLogEdit.php @@ -191,5 +191,21 @@ final class NodaLogEdit { $insertStmt->close(); $insertStmt = null; + // Update the main tag table, except for edits to the base, + // as these have built-in updating and updating in this case + // would be superfluous. + if ($section !== 'base') { + + $updateStmt = $mysqli_noda->do_prepare("UPDATE `orte` + SET `ort_erfasst_am` = NOW(), + `ort_erfasst_von` = ? + WHERE `ort_id` = ?"); + $updateStmt->bind_param("si", $user_name, $ort_id); + $updateStmt->execute(); + $updateStmt->close(); + $updateStmt = null; + + } + } }