From b76ac53c9d8cba4652ee259e8e7c5301b40dd98f Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Thu, 20 Oct 2022 11:08:39 +0800 Subject: [PATCH] MDL-61880 core: don't clear issuer fields not present in form data In cases where we have an id, load the persistent and then set new data before saving. This ensures we don't delete fields which are missing in the form data. --- lib/classes/oauth2/api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/classes/oauth2/api.php b/lib/classes/oauth2/api.php index c6aece1b0e8..5aeac855a57 100644 --- a/lib/classes/oauth2/api.php +++ b/lib/classes/oauth2/api.php @@ -327,7 +327,10 @@ class api { */ protected static function create_or_update_issuer($data, bool $create): issuer { require_capability('moodle/site:config', context_system::instance()); - $issuer = new issuer(0, $data); + $issuer = new issuer($data->id ?? 0, $data); + if (!empty($data->id)) { + $issuer->set_many((array)$data); + } // Will throw exceptions on validation failures. if ($create) {