#173 Fix race condition on certificate issues in scheduled task

This commit is contained in:
Eugene Venter 2018-03-27 15:30:50 +13:00 committed by Mark Nelson
parent a1613478e2
commit df7ada60a1

View file

@ -125,6 +125,10 @@ class email_certificate_task extends \core\task\scheduled_task {
} }
} }
// Ensure the cert hasn't already been issued, e.g via the UI (view.php) - a race condition.
$issueid = $DB->get_field('customcert_issues', 'id',
array('userid' => $enroluser->id, 'customcertid' => $customcert->id));
if (empty($issueid)) {
// Ok, issue them the certificate. // Ok, issue them the certificate.
$customcertissue = new \stdClass(); $customcertissue = new \stdClass();
$customcertissue->customcertid = $customcert->id; $customcertissue->customcertid = $customcert->id;
@ -135,6 +139,7 @@ class email_certificate_task extends \core\task\scheduled_task {
// Insert the record into the database. // Insert the record into the database.
$issueid = $DB->insert_record('customcert_issues', $customcertissue); $issueid = $DB->insert_record('customcert_issues', $customcertissue);
}
// Add them to the array so we email them. // Add them to the array so we email them.
$enroluser->issueid = $issueid; $enroluser->issueid = $issueid;