Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84230

When Filemanager is Optional, Moodle Throws Multiple Files Error

XMLWordPrintable

    • MOODLE_405_STABLE

      I discovered a rather strange bug, and it was quite challenging to identify.

      In the context of a MOD-type plugin, when using $mform->addElement("filemanager") in the mod_form.php file, I noticed that when the field is optional, the form submits $draftid=0. In my validator, I check if the value is zero and consider it acceptable.

      The problem occurs because Moodle, when processing this situation, looks in the database for all files with itemid=0 for the current user. This results in a query like this:
       
      {{SELECT * }}
      {{FROM mdl_files }}
      WHERE contextid = 5
      AND component = 'user'
      AND filearea = 'draft'
      AND itemid = 0

      If more than one file is associated with itemid=0, the system displays the error:
      "You cannot attach more than 1 file here."

      This happens because, before line 461 of formslib.php, there is no validation to check if the field rule is truly 'required'. The absence of this check allows the issue to occur.

      Additionally, there is no validation for itemid!=0.

            Unassigned Unassigned
            eduardokraus Eduardo Kraus
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.