MDL-75137 mod_data: Add entry throws an exception if there is no field

This commit is contained in:
Amaia Anabitarte
2022-08-12 15:46:08 +02:00
parent 896e126a66
commit cb01747608
4 changed files with 58 additions and 2 deletions
+6 -1
View File
@@ -982,6 +982,12 @@ class mod_data_external extends external_api {
$fieldnotifications = array();
list($database, $course, $cm, $context) = self::validate_database($params['databaseid']);
$fields = $DB->get_records('data_fields', ['dataid' => $database->id]);
if (empty($fields)) {
throw new moodle_exception('nofieldindatabase', 'data');
}
// Check database is open in time.
data_require_time_available($database, null, $context);
@@ -1009,7 +1015,6 @@ class mod_data_external extends external_api {
$datarecord->{'field_' . $data['fieldid'] . $subfield} = json_decode($data['value']);
}
// Validate to ensure that enough data was submitted.
$fields = $DB->get_records('data_fields', array('dataid' => $database->id));
$processeddata = data_process_submission($database, $fields, $datarecord);
// Format notifications.