Add functions for logging to import log

This commit is contained in:
Joshua Ramon Enslin 2023-03-01 11:43:01 +01:00
parent 446c5d26f4
commit b6d229eed9
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 230 additions and 0 deletions

View File

@ -689,4 +689,128 @@ final class NodaIDGetter {
return $output;
}
/** Wrappers */
/**
* Gets a actor ID to check pre-existence for insertion.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the actor to search for.
* @param string $birthYear Year of birth. Optional.
* @param string $deathYear Year of death. Optional.
* @param string $instance Instance for checking import log. Optional.
* @param integer $institution_id Institution ID for checking import log. Optional.
*
* @return integer
*/
public static function getPersinstIDByNamesAndRewrites(MDMysqli $mysqli_noda, string $lang, string $name, string $birthYear, string $deathYear, string $instance = "", int $institution_id = 0):int {
if (($persinstIdByName = self::getPersinstIDByName($mysqli_noda, $lang, $name)) !== 0) {
return $persinstIdByName;
}
if (($persinstIdByRewrite = self::getPersinstIDByRewrite($mysqli_noda, $lang, $name)) !== 0) {
return $persinstIdByRewrite;
}
if ($instance !== "") {
if (($persinstIdByImportLog = self::getPersinstIDByImportLog($mysqli_noda, $instance, $institution_id, $name, $birthYear, $deathYear)) !== 0) {
return $persinstIdByImportLog;
}
}
return 0;
}
/**
* Gets a place ID to check pre-existence for insertion.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the place to search for.
* @param string $instance Instance for checking import log. Optional.
* @param integer $institution_id Institution ID for checking import log. Optional.
*
* @return integer
*/
public static function getPlaceIDByNamesAndRewrites(MDMysqli $mysqli_noda, string $lang, string $name, string $instance = "", int $institution_id = 0):int {
if (($placeIdByName = self::getPlaceIDByName($mysqli_noda, $lang, $name)) !== 0) {
return $placeIdByName;
}
if (($placeIdByRewrite = self::getPlaceIDByRewrite($mysqli_noda, $lang, $name)) !== 0) {
return $placeIdByRewrite;
}
if ($instance !== "") {
if (($placeIdByImportLog = self::getPlaceIDByImportLog($mysqli_noda, $instance, $institution_id, $name)) !== 0) {
return $placeIdByImportLog;
}
}
return 0;
}
/**
* Gets a tag ID to check pre-existence for insertion.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the tag to search for.
* @param string $instance Instance for checking import log. Optional.
* @param integer $institution_id Institution ID for checking import log. Optional.
*
* @return integer
*/
public static function getTagIDByNamesAndRewrites(MDMysqli $mysqli_noda, string $lang, string $name, string $instance = "", int $institution_id = 0):int {
if (($tagIdByName = self::getTagIDByName($mysqli_noda, $lang, $name)) !== 0) {
return $tagIdByName;
}
if (!empty($tagIdByRewrite = self::getTagIDByRewrite($mysqli_noda, $lang, $name))) {
return end($tagIdByRewrite);
}
if ($instance !== "") {
if (($tagIdByImportLog = self::getTagIDByImportLog($mysqli_noda, $instance, $institution_id, $name)) !== 0) {
return $tagIdByImportLog;
}
}
return 0;
}
/**
* Gets a time ID to check pre-existence for insertion.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the time to search for.
* @param string $instance Instance for checking import log. Optional.
* @param integer $institution_id Institution ID for checking import log. Optional.
*
* @return integer
*/
public static function getTimeIDByNamesAndRewrites(MDMysqli $mysqli_noda, string $lang, string $name, string $instance = "", int $institution_id = 0):int {
if (($timeIdByName = self::getTimeIDByName($mysqli_noda, $lang, $name)) !== 0) {
return $timeIdByName;
}
if ($instance !== "") {
if (($timeIdByImportLog = self::getTimeIDByImportLog($mysqli_noda, $instance, $institution_id, $name)) !== 0) {
return $timeIdByImportLog;
}
}
return 0;
}
}

106
src/NodaImportLogger.php Normal file
View File

@ -0,0 +1,106 @@
<?PHP
/**
* Contains class NodaImportLogger for logging the mapping between entered term names
* and their resulting IDs.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Contains class NodaImportLogger for logging the mapping between entered term names
* and their resulting IDs.
*/
final class NodaImportLogger {
/**
* Logs link of a person with an institution.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param integer $persinst_id Resulting actor ID.
* @param string $name Name of the persinst to search for.
* @param string $birthYear Year of birth. Optional.
* @param string $deathYear Year of death. Optional.
*
* @return void
*/
public static function logImportForPersinstByInstitution(MDMysqli $mysqli_noda, string $instance, int $institution_id, int $persinst_id, string $name, string $birthYear = "", string $deathYear = ""):void {
$loggedName = $name . $birthYear . $deathYear;
$logStmt = $mysqli_noda->do_prepare("INSERT INTO `persinst_logged_imports`
(`instance`, `institution_id`, `input_string`, `persinst_id`)
VALUES (?, ?, ?, ?)");
$logStmt->bind_param("sisi", $instance, $institution_id, $loggedName, $persinst_id);
$logStmt->execute();
$logStmt->close();
}
/**
* Logs link of a place with an institution.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param integer $ort_id Resulting place ID.
* @param string $name Name of the place to search for.
*
* @return void
*/
public static function logImportForPlaceByInstitution(MDMysqli $mysqli_noda, string $instance, int $institution_id, int $ort_id, string $name):void {
$logStmt = $mysqli_noda->do_prepare("INSERT INTO `orte_logged_imports`
(`instance`, `institution_id`, `input_string`, `ort_id`)
VALUES (?, ?, ?, ?)");
$logStmt->bind_param("sisi", $instance, $institution_id, $name, $ort_id);
$logStmt->execute();
$logStmt->close();
}
/**
* Logs link of a time with an institution.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param integer $zeit_id Resulting time ID.
* @param string $name Name of the time to search for.
*
* @return void
*/
public static function logImportForTimeByInstitution(MDMysqli $mysqli_noda, string $instance, int $institution_id, int $zeit_id, string $name):void {
$logStmt = $mysqli_noda->do_prepare("INSERT INTO `zeiten_logged_imports`
(`instance`, `institution_id`, `input_string`, `zeit_id`)
VALUES (?, ?, ?, ?)");
$logStmt->bind_param("sisi", $instance, $institution_id, $name, $zeit_id);
$logStmt->execute();
$logStmt->close();
}
/**
* Logs link of a tag with an institution.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param integer $tag_id Resulting tag ID.
* @param string $name Name of the tag to search for.
*
* @return void
*/
public static function logImportForTagByInstitution(MDMysqli $mysqli_noda, string $instance, int $institution_id, int $tag_id, string $name):void {
$logStmt = $mysqli_noda->do_prepare("INSERT INTO `tag_logged_imports`
(`instance`, `institution_id`, `input_string`, `tag_id`)
VALUES (?, ?, ?, ?)");
$logStmt->bind_param("sisi", $instance, $institution_id, $name, $tag_id);
$logStmt->execute();
$logStmt->close();
}
}