Skip to content

Commit

Permalink
documentation about actual behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed May 12, 2024
1 parent 54ef402 commit c30fb8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function adleradaptivity_delete_instance(int $instance_id): bool {
$adleradaptivity_repository = new adleradaptivity_repository();


// there is no transaction above this level. Unsuccessful deletions basically result in unpredictable
// behaviour. This at least ensures this module is either deleted completely or not at all.
$transaction = $DB->start_delegated_transaction();

try {
Expand Down Expand Up @@ -120,13 +122,13 @@ function adleradaptivity_delete_instance(int $instance_id): bool {
} catch (Exception $e) {
$logger->error('Could not delete adleradaptivity instance with id ' . $instance_id);
$logger->error($e->getMessage());
// although the existing documentation suggests this method should return true|false depending
// on whether the deletion succeeded, this does not actually lead to the desired behaviour.
// In case of an error this should throw an exception as otherwise:
// - postgresql databases are not rolled back
// - course deletion succeeds without indication of an error
// - only module deletion behaves as expected and shows an error
$transaction->rollback($e);
try {
$transaction->rollback($e);
} catch (Exception $e) {
// rollback triggers an exception, but I don't care. This method is expected to return false in case of an error.
}
return false;
}

return true;
Expand Down
1 change: 1 addition & 0 deletions tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_once($CFG->dirroot . '/mod/adleradaptivity/tests/lib/adler_testcase.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');

// TODO: properly adjust testcases for exception instead of "false" response

class lib_test extends adler_testcase {
public function test_add_instance() {
Expand Down

0 comments on commit c30fb8f

Please sign in to comment.