MDL-75137 mod_data: Add entry throws an exception if there is no field
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user