mass update
This commit is contained in:
+26
-11
@@ -161,26 +161,33 @@ function getLocalization(int $igdbId, string $lang = 'de'): ?array {
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
function saveLocalization(int $igdbId, string $lang, ?string $title, ?string $summary, ?string $storyline, ?int $userId): array {
|
||||
function saveLocalization(int $igdbId, string $lang, ?string $title, ?string $summary, ?string $storyline, ?int $userId, ?int $locked = null): array {
|
||||
$pdo = getDb();
|
||||
$existing = getLocalization($igdbId, $lang);
|
||||
$lockedVal = $locked === null ? (int)($existing['locked'] ?? 0) : (int)!!$locked;
|
||||
$titleToSave = $title !== null ? $title : ($existing['title'] ?? null);
|
||||
$summaryToSave = $summary !== null ? $summary : ($existing['summary'] ?? null);
|
||||
$storyToSave = $storyline !== null ? $storyline : ($existing['storyline'] ?? null);
|
||||
$sql = '
|
||||
INSERT INTO igdb_localizations (igdb_id, lang, title, summary, storyline, user_id)
|
||||
VALUES (:id, :lang, :title, :summary, :storyline, :user_id)
|
||||
INSERT INTO igdb_localizations (igdb_id, lang, title, summary, storyline, user_id, locked)
|
||||
VALUES (:id, :lang, :title, :summary, :storyline, :user_id, :locked)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
title = VALUES(title),
|
||||
summary = VALUES(summary),
|
||||
storyline = VALUES(storyline),
|
||||
user_id = VALUES(user_id),
|
||||
locked = VALUES(locked),
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':id' => $igdbId,
|
||||
':lang' => $lang,
|
||||
':title' => $title,
|
||||
':summary' => $summary,
|
||||
':storyline' => $storyline,
|
||||
':title' => $titleToSave,
|
||||
':summary' => $summaryToSave,
|
||||
':storyline' => $storyToSave,
|
||||
':user_id' => $userId,
|
||||
':locked' => $lockedVal,
|
||||
]);
|
||||
return getLocalization($igdbId, $lang);
|
||||
}
|
||||
@@ -498,10 +505,11 @@ if (isset($_GET['action'])) {
|
||||
$game['my_note'] = null;
|
||||
}
|
||||
$hasLoc = false;
|
||||
$locLocked = 0;
|
||||
if ($lang !== 'en') {
|
||||
$loc = getLocalization($id, $lang);
|
||||
if ($loc !== null) {
|
||||
$hasLoc = true;
|
||||
$locLocked = (int)($loc['locked'] ?? 0);
|
||||
if (!empty($loc['title'])) $game['name'] = $loc['title'];
|
||||
if (!empty($loc['summary'])) $game['summary'] = $loc['summary'];
|
||||
if (!empty($loc['storyline'])) $game['storyline'] = $loc['storyline'];
|
||||
@@ -509,15 +517,20 @@ if (isset($_GET['action'])) {
|
||||
'lang' => $lang,
|
||||
'source' => 'custom',
|
||||
'id' => $loc['id'],
|
||||
'locked' => $locLocked,
|
||||
];
|
||||
if ($locLocked === 1) {
|
||||
$hasLoc = true; // locked -> treat as authoritative, skip external fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
$game['has_localization'] = $hasLoc;
|
||||
$game['loc_locked'] = $locLocked;
|
||||
$game['has_external_de'] = false;
|
||||
$game['external_de_source']= null;
|
||||
$game['external_de_summary']= null;
|
||||
$game['external_de_url'] = null;
|
||||
if ($checkExternal && $lang === 'de' && !$hasLoc) {
|
||||
if ($checkExternal && $lang === 'de' && $locLocked === 0) {
|
||||
$wiki = wikiFetchGermanSummaryForTitle($game['name']);
|
||||
if ($wiki !== null && !empty($wiki['extract'])) {
|
||||
$game['has_external_de'] = true;
|
||||
@@ -1067,7 +1080,8 @@ try {
|
||||
CASE g.status WHEN 1 THEN 'Progress' WHEN 2 THEN 'Done' ELSE 'Init' END AS status,
|
||||
loc.title AS loc_title,
|
||||
loc.summary AS loc_summary,
|
||||
loc.storyline AS loc_storyline
|
||||
loc.storyline AS loc_storyline,
|
||||
loc.locked AS loc_locked
|
||||
FROM game g
|
||||
LEFT JOIN igdb_localizations loc
|
||||
ON loc.igdb_id = g.igdb_id AND loc.lang = ?
|
||||
@@ -1333,6 +1347,7 @@ try {
|
||||
$locTitle = isset($in['title']) ? trim($in['title']) : '';
|
||||
$locSummary = isset($in['summary']) ? trim($in['summary']) : '';
|
||||
$locStory = isset($in['storyline']) ? trim($in['storyline']) : '';
|
||||
$lockFlag = array_key_exists('locked', $in) ? (int)!!$in['locked'] : null;
|
||||
$coverUrl = isset($in['cover_url']) ? trim($in['cover_url']) : null;
|
||||
$releaseYear = isset($in['release_year']) ? (int)$in['release_year'] : null;
|
||||
$GLOBALS['__release_year'] = $releaseYear;
|
||||
@@ -1340,8 +1355,8 @@ try {
|
||||
if ($name === '') fail('Missing "name"');
|
||||
if ($status < 0 || $status > 2) fail('Invalid "status" (0,1,2)');
|
||||
$game = saveGameStatus($igdbId, $name, $orig !== '' ? $orig : null, $status, $note !== '' ? $note : null, $coverUrl ?: null);
|
||||
if ($locTitle !== '' || $locSummary !== '' || $locStory !== '') {
|
||||
saveLocalization($igdbId, $lang, $locTitle ?: null, $locSummary ?: null, $locStory ?: null, null);
|
||||
if ($locTitle !== '' || $locSummary !== '' || $locStory !== '' || $lockFlag !== null) {
|
||||
saveLocalization($igdbId, $lang, $locTitle ?: null, $locSummary ?: null, $locStory ?: null, null, $lockFlag);
|
||||
}
|
||||
resp(['ok' => true, 'game' => $game]);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user