Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UploadNewAchievement): dont strip type value on RAIntegration edits #1783

Merged
11 changes: 8 additions & 3 deletions app/Helpers/database/achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function UploadNewAchievement(
return false;
}

if ($type !== null && !AchievementType::isValid($type)) {
if ($type !== null && (!AchievementType::isValid($type) && $type !== 'not-given')) {
$errorOut = "Invalid achievement type";

return false;
Expand All @@ -206,7 +206,7 @@ function UploadNewAchievement(
sanitize_sql_inputs($title, $desc, $mem, $progress, $progressMax, $progressFmt, $dbAuthor, $type);

$typeValue = "";
if ($type === null || trim($type) === '') {
if ($type === null || trim($type) === '' || $type === 'not-given') {
$typeValue = "NULL";
} else {
$typeValue = "'$type'";
Expand Down Expand Up @@ -268,7 +268,7 @@ function UploadNewAchievement(
$data = mysqli_fetch_assoc($dbResult);

$changingAchSet = ($data['Flags'] != $flag);
$changingType = ($data['type'] != $type);
$changingType = ($data['type'] != $type && $type !== 'not-given');
$changingPoints = ($data['Points'] != $points);
$changingTitle = ($data['Title'] !== $rawTitle);
$changingDescription = ($data['Description'] !== $rawDesc);
Expand Down Expand Up @@ -296,6 +296,11 @@ function UploadNewAchievement(
}
}

// `null` is a valid type value, so we use a different fallback value.
if ($type === 'not-given' && $data['type'] !== null) {
$typeValue = "'" . $data['type'] . "'";
}

$query = "UPDATE Achievements SET Title='$title', Description='$desc', Progress='$progress', ProgressMax='$progressMax', ProgressFormat='$progressFmt', MemAddr='$mem', Points=$points, Flags=$flag, type=$typeValue, DateModified=NOW(), Updated=NOW(), BadgeName='$badge' WHERE ID=$idInOut";

$db = getMysqliConnection();
Expand Down
2 changes: 1 addition & 1 deletion public/dorequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ function DoRequestError(string $error, ?int $status = 200, ?string $code = null)
progressMax: ' ',
progressFmt: ' ',
points: (int) request()->input('z', 0),
type: request()->input('x'),
type: request()->input('x', 'not-given'), // `null` is a valid achievement type value, so we use a different fallback value.
mem: request()->input('m'),
flag: (int) request()->input('f', AchievementFlag::Unofficial),
idInOut: $achievementID,
Expand Down
Loading