Create transaction for logic
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
This commit is contained in:
@@ -2,17 +2,25 @@
|
||||
require_once "api.php";
|
||||
require_once "../include/logic.php";
|
||||
if (array_key_exists("solved", $_GET)) {
|
||||
|
||||
$solved = GetLogicSolved();
|
||||
$complexity = GetLogicTotalComplexity();
|
||||
$complexity += $_GET["solved"];
|
||||
$solved++;
|
||||
dbCommand("DELETE FROM information WHERE pointer='logicSolved'");
|
||||
dbCommand("DELETE FROM information WHERE pointer='logicComplexity'");
|
||||
dbCommand("INSERT INTO information VALUES ('logicComplexity', ?)", [$complexity]);
|
||||
dbCommand("INSERT INTO information VALUES ('logicSolved', ?)", [$solved]);
|
||||
echo json_encode([
|
||||
"solved" => $solved,
|
||||
"average" => GetLogicAverageComplexity()
|
||||
]);
|
||||
try {
|
||||
dbCommand("START TRANSACTION");
|
||||
$solved = GetLogicSolved();
|
||||
$complexity = GetLogicTotalComplexity();
|
||||
$complexity += $_GET["solved"];
|
||||
$solved++;
|
||||
dbCommand("DELETE FROM information WHERE pointer='logicSolved'");
|
||||
dbCommand("DELETE FROM information WHERE pointer='logicComplexity'");
|
||||
dbCommand("INSERT INTO information VALUES ('logicComplexity', ?)", [$complexity]);
|
||||
dbCommand("INSERT INTO information VALUES ('logicSolved', ?)", [$solved]);
|
||||
dbCommand("COMMIT");
|
||||
echo json_encode([
|
||||
"solved" => $solved,
|
||||
"average" => GetLogicAverageComplexity()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
dbCommand("ROLLBACK");
|
||||
http_response_code(500);
|
||||
writeLog(9, "Error updating logic count with error: " . $e->getMessage());
|
||||
echo "Error saving solve";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user