Expect usage of function setRetrivalMode instead of a GET param for
setting retrieval modes in NodaWikidataFetcher
This commit is contained in:
parent
7ff986bdd8
commit
d5b593c334
@ -83,9 +83,38 @@ final class NodaWikidataFetcher {
|
||||
'<p><span class="geo noexcerpt"',
|
||||
];
|
||||
|
||||
const RETRIEVAL_MODES_ACCEPTED = [
|
||||
'list',
|
||||
'add',
|
||||
'keep',
|
||||
'replace',
|
||||
];
|
||||
|
||||
const RETRIEVAL_MODES_DEFAULT = 'list';
|
||||
|
||||
/** @var 'list'|'add'|'keep'|'replace' */
|
||||
private string $_retrievalMode = self::RETRIEVAL_MODES_DEFAULT;
|
||||
|
||||
/** @var MDMysqli */
|
||||
private MDMysqli $_mysqli_noda;
|
||||
|
||||
/**
|
||||
* Sets the retrieval mode.
|
||||
*
|
||||
* @param string $retrievalMode New retrieval mode to set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setRetrievalMode(string $retrievalMode):void {
|
||||
|
||||
if (!in_array($retrievalMode, self::RETRIEVAL_MODES_ACCEPTED, true)) {
|
||||
throw new Exception("Retrieval mode not in list of accepted retrieval modes: " . implode(',', self::RETRIEVAL_MODES_ACCEPTED));
|
||||
}
|
||||
|
||||
$this->_retrievalMode = $retrievalMode;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a Wikidata ID. A Wikidata ID must start with a capital Q and be
|
||||
* numeric otherwise.
|
||||
@ -549,25 +578,24 @@ final class NodaWikidataFetcher {
|
||||
$cinfo = $cergebnis->fetch_assoc();
|
||||
if (!empty($cinfo['persinst_kurzinfo']) and substr($cinfo['persinst_kurzinfo'], 0, 3) !== 'GND') {
|
||||
|
||||
if (isset($_GET['keep'])) {
|
||||
if (!$_GET['keep'] || $_GET['keep'] === 'replace') {
|
||||
switch ($this->_retrievalMode) {
|
||||
case "add":
|
||||
|
||||
$updatePersinstStmt->bind_param("si", $datafromwiki, $persinst_id);
|
||||
$updatePersinstStmt->execute();
|
||||
|
||||
}
|
||||
else if ($_GET['keep'] === 'add') {
|
||||
|
||||
$newDesc = $cinfo['persinst_kurzinfo'] . PHP_EOL . PHP_EOL . $datafromwiki;
|
||||
|
||||
$updatePersinstStmt->bind_param("si", $newDesc, $persinst_id);
|
||||
$updatePersinstStmt->execute();
|
||||
|
||||
}
|
||||
$newDesc = $cinfo['persinst_kurzinfo'] . PHP_EOL . PHP_EOL . $datafromwiki;
|
||||
|
||||
$updatePersinstStmt->bind_param("si", $newDesc, $persinst_id);
|
||||
$updatePersinstStmt->execute();
|
||||
$output = true;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
|
||||
case "replace":
|
||||
|
||||
$updatePersinstStmt->bind_param("si", $datafromwiki, $persinst_id);
|
||||
$updatePersinstStmt->execute();
|
||||
$output = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$tlLoader = new MDTlLoader("wiki_getter_persinst", $preflang);
|
||||
echo self::generateHTMLHeadForWikidataFetcher($lang);
|
||||
@ -585,7 +613,7 @@ final class NodaWikidataFetcher {
|
||||
echo '<br><a href="get_wikidata_for_persinst.php?wikidata_id=' . $wikidata_id . write_get_vars(['suchbegriff', 'lang', 'persinst_id']) . '&keep=replace" class="buttonLike icons iconsPinOff">Replace with new entry</a>';
|
||||
echo '<br><a href="get_wikidata_for_persinst.php?wikidata_id=' . $wikidata_id . write_get_vars(['suchbegriff', 'lang', 'persinst_id']) . '&keep=add" class="buttonLike icons iconsPlusOne">Keep old and add new entry</a><br><br><br>';
|
||||
|
||||
exit;
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
@ -939,20 +967,14 @@ final class NodaWikidataFetcher {
|
||||
|
||||
if (!empty(trim($curPlaceInfo['ort_anmerkung'])) and substr($curPlaceInfo['ort_anmerkung'], 0, 3) !== 'GND') {
|
||||
|
||||
if (isset($_GET['keep'])) {
|
||||
|
||||
if ($_GET['keep'] === 'add') {
|
||||
|
||||
$datafromwiki = $curPlaceInfo['ort_anmerkung'] . PHP_EOL . PHP_EOL . $datafromwiki;
|
||||
|
||||
}
|
||||
else if ($_GET['keep'] === 'keep') {
|
||||
$datafromwiki = $curPlaceInfo['ort_anmerkung'];
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
switch ($this->_retrievalMode) {
|
||||
case "add":
|
||||
$datafromwiki = $curPlaceInfo['ort_anmerkung'] . PHP_EOL . PHP_EOL . $datafromwiki;
|
||||
break;
|
||||
case "keep":
|
||||
$datafromwiki = $curPlaceInfo['ort_anmerkung'];
|
||||
break;
|
||||
default:
|
||||
$tlLoader = new MDTlLoader("wiki_getter_place", $preflang);
|
||||
echo self::generateHTMLHeadForWikidataFetcher($lang);
|
||||
echo self::generateWikidataFetcherHeader($tlLoader);
|
||||
@ -1349,25 +1371,24 @@ final class NodaWikidataFetcher {
|
||||
|
||||
if (!empty($cinfo['tag_anmerkung']) and substr($cinfo['tag_anmerkung'], 0, 3) !== 'GND') {
|
||||
|
||||
if (isset($_GET['keep'])) {
|
||||
if (!$_GET['keep'] || $_GET['keep'] === 'replace') {
|
||||
switch ($this->_retrievalMode) {
|
||||
case "add":
|
||||
|
||||
$updateTagDescStmt->bind_param("si", $datafromwiki, $tag_id);
|
||||
$updateTagDescStmt->execute();
|
||||
|
||||
}
|
||||
else if ($_GET['keep'] === 'add') {
|
||||
|
||||
$newDesc = $cinfo['tag_anmerkung'] . PHP_EOL . PHP_EOL . $datafromwiki;
|
||||
|
||||
$updateTagDescStmt->bind_param("si", $newDesc, $tag_id);
|
||||
$updateTagDescStmt->execute();
|
||||
|
||||
}
|
||||
$newDesc = $cinfo['tag_anmerkung'] . PHP_EOL . PHP_EOL . $datafromwiki;
|
||||
|
||||
$updateTagDescStmt->bind_param("si", $newDesc, $tag_id);
|
||||
$updateTagDescStmt->execute();
|
||||
$output = true;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
|
||||
case "replace":
|
||||
|
||||
$updateTagDescStmt->bind_param("si", $datafromwiki, $tag_id);
|
||||
$updateTagDescStmt->execute();
|
||||
$output = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$tlLoader = new MDTlLoader("wiki_getter_tag", $preflang);
|
||||
echo self::generateHTMLHeadForWikidataFetcher($lang);
|
||||
|
Loading…
Reference in New Issue
Block a user