Merge branch 'MDL-51694-37' of https://github.com/MartinGauk/moodle into MOODLE_37_STABLE

This commit is contained in:
Jake Dallimore
2020-05-08 11:23:23 +08:00
3 changed files with 23 additions and 2 deletions
+7 -1
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;
}
/**
+4
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;
}
+12 -1
View File
@@ -400,8 +400,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;
}
/**
@@ -411,6 +416,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();
}
@@ -428,6 +437,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;
}