MDL-74192 core: add strictness to persistent get_record method.

Allow developer to specify the given record MUST_EXIST, and the
method to throw the underlying database exception.
This commit is contained in:
Paul Holden
2022-05-19 15:21:39 +01:00
parent 6c114e2a80
commit 6d5c0190e2
3 changed files with 75 additions and 6 deletions
+4 -2
View File
@@ -854,12 +854,14 @@ abstract class persistent {
* Load a single record.
*
* @param array $filters Filters to apply.
* @param int $strictness Similar to the internal DB get_record call, indicate whether a missing record should be
* ignored/return false ({@see IGNORE_MISSING}) or should cause an exception to be thrown ({@see MUST_EXIST})
* @return false|static
*/
public static function get_record($filters = array()) {
public static function get_record(array $filters = [], int $strictness = IGNORE_MISSING) {
global $DB;
$record = $DB->get_record(static::TABLE, $filters);
$record = $DB->get_record(static::TABLE, $filters, '*', $strictness);
return $record ? new static(0, $record) : false;
}