MDL-51694 core_grades: use transactions when deleting

This commit is contained in:
Martin Gauk 2020-01-17 12:13:41 +00:00
parent cd391f9922
commit 966556074c
3 changed files with 23 additions and 2 deletions

View File

@ -285,6 +285,9 @@ class grade_category extends grade_object {
* @return bool success
*/
public function delete($source=null) {
global $DB;
$transaction = $DB->start_delegated_transaction();
$grade_item = $this->load_grade_item();
if ($this->is_course_category()) {
@ -334,7 +337,10 @@ class grade_category extends grade_object {
$grade_item->delete($source);
// delete category itself
return parent::delete($source);
$success = parent::delete($source);
$transaction->allow_commit();
return $success;
}
/**

View File

@ -1111,6 +1111,9 @@ class grade_grade extends grade_object {
* @return bool Returns true if the deletion was successful, false otherwise.
*/
public function delete($source = null) {
global $DB;
$transaction = $DB->start_delegated_transaction();
$success = parent::delete($source);
// If the grade was deleted successfully trigger a grade_deleted event.
@ -1119,6 +1122,7 @@ class grade_grade extends grade_object {
\core\event\grade_deleted::create_from_grade($this)->trigger();
}
$transaction->allow_commit();
return $success;
}

View File

@ -407,8 +407,13 @@ class grade_item extends grade_object {
* @return bool success
*/
public function delete($source=null) {
global $DB;
$transaction = $DB->start_delegated_transaction();
$this->delete_all_grades($source);
return parent::delete($source);
$success = parent::delete($source);
$transaction->allow_commit();
return $success;
}
/**
@ -418,6 +423,10 @@ class grade_item extends grade_object {
* @return bool
*/
public function delete_all_grades($source=null) {
global $DB;
$transaction = $DB->start_delegated_transaction();
if (!$this->is_course_item()) {
$this->force_regrading();
}
@ -435,6 +444,8 @@ class grade_item extends grade_object {
$fs->delete_area_files($this->get_context()->id, GRADE_FILE_COMPONENT, GRADE_HISTORY_FEEDBACK_FILEAREA);
}
$transaction->allow_commit();
return true;
}