Skip to content

Commit

Permalink
Delete customcert_pages rows after elements (#571)
Browse files Browse the repository at this point in the history
Previously template->delete_page() deleted the corresponding
mdl_customcert_pages row, and then called element->delete() for each
element on the page.  But the latter then called
element_deleted::create_from_element() which relied on that
mdl_customcert_pages row to obtain the contextid for the event.

Now element->delete() is called for each element on the page, then the
mdl_customcert_pages row is deleted.
  • Loading branch information
leonstr authored and mdjnelson committed Dec 29, 2023
1 parent f205a1a commit 501eedc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions classes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ public function delete_page($pageid) {
// Get the page.
$page = $DB->get_record('customcert_pages', array('id' => $pageid), '*', MUST_EXIST);

// Delete this page.
$DB->delete_records('customcert_pages', array('id' => $page->id));

\mod_customcert\event\page_deleted::create_from_page($page, $this)->trigger();

// The element may have some extra tasks it needs to complete to completely delete itself.
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id))) {
foreach ($elements as $element) {
Expand All @@ -233,6 +228,11 @@ public function delete_page($pageid) {
}
}

// Delete this page.
$DB->delete_records('customcert_pages', array('id' => $page->id));

\mod_customcert\event\page_deleted::create_from_page($page, $this)->trigger();

// Now we want to decrease the page number values of
// the pages that are greater than the page we deleted.
$sql = "UPDATE {customcert_pages}
Expand Down

0 comments on commit 501eedc

Please sign in to comment.