Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:DB layer 2.0 delegated transactions

From MoodleDocs

Alternate API (from comments in Tracker/HQ chat

6. Normal usage of the moodle_delegated_transaction will be:

$transaction = $DB->start_require_transaction();
// Perform some $DB stuff
$transaction->end_require_transaction();

7. If, for any reason, developer needs to catch exceptions when using transactions, it will be mandatory to use it in this way:

try {
    $transaction = $DB->start_require_transaction();
    // Perform some $DB stuff
    $transaction->end_require_transaction();
} catch (exception $e) {
    $transaction->rollback($e); // ?
}

8. In order to be able to keep some parts of code out from top transactions completely, if we know it can lead to problems, we can use:

 $DB->forbide_transaction(); // Instant check to confirm we aren't using transactions in this point. Will throw exception if transaction is found.