From 7e21841dfe29f6fa721ddfaa77bee20f3c3bec03 Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Tue, 11 May 2021 14:09:09 +0200 Subject: [PATCH] avoid race condition when archiving solution, fixes #60 --- lib/VipsAssignment.php | 10 +++++----- lib/VipsSolution.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/VipsAssignment.php b/lib/VipsAssignment.php index 57b6caf..6c62f92 100644 --- a/lib/VipsAssignment.php +++ b/lib/VipsAssignment.php @@ -699,17 +699,17 @@ class VipsAssignment extends SimpleORMap $solution->options['session_id'] = session_id(); } + // in selftests, autocorrect solution + if ($this->isSelfAssessment()) { + $this->correctSolution($solution); + } + // move old solutions into vips_solution_archive VipsSolution::archiveBySQL( 'exercise_id = ? AND assignment_id = ? AND user_id = ?', [$exercise->id, $this->id, $user_id] ); - // in selftests, autocorrect solution - if ($this->isSelfAssessment()) { - $this->correctSolution($solution); - } - // insert new solution into vips_solution return $solution->store(); } diff --git a/lib/VipsSolution.php b/lib/VipsSolution.php index 6ca2db5..55c30c2 100644 --- a/lib/VipsSolution.php +++ b/lib/VipsSolution.php @@ -126,7 +126,7 @@ class VipsSolution extends SimpleORMap { $db = DBManager::get(); - $stmt = $db->prepare('INSERT INTO vips_solution_archive + $stmt = $db->prepare('INSERT IGNORE INTO vips_solution_archive SELECT * FROM vips_solution WHERE ' . $sql); $stmt->execute($params); -- GitLab