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

Database activity with file - no export with X-Sendfile/make_request_directory

XMLWordPrintable

      Moodle 4.3.3 (20240212)  on Debian 12 / Apache 2.4.57 / libapache2-mod-xsendfile 0.12-2 and config.php with:

      $CFG->xsendfile = 'X-Sendfile';
      $CFG->localrequestdir = $CFG->dataroot . '/temp/localrequestdir';
      

       

      1.  In a course, create a database activity and add two fields, one «text» and one «file»
      2. Add a new entry and upload a file
      3.  Go to "Actions"->"Export entries", check «Include files in export» and click «Export entries»
      4. Confirm
        1. empty tab - no file downloaded
        2. error in PHP logs:

          [Mon Mar 18 10:48:06.722110 2024] [:error] [pid xxxxxxx] (2)No such file or directory: [client ip:port] xsendfile: cannot open file: /var/www/xxxxxxxxxxxx/moodledata/temp/localrequestdir/jd2a/65f80dd6aec96/65f80dd6aee18/Exportfile.zip, referer: https://xxxxxxxxxxxxxxxxxxxx/mod/data/export.php?d=1&backto=https%3A%2F%2Fxxxxxxxxxxxxxxxxx%2Fmod%2Fdata%2Fview.php%3Fd%3D1

      5. In mod/data/classes/local/exporter/entries_exporter.php in function create_zip_archive, replace

        $tmpdir = make_request_directory();


        with

        $tmpdir = make_temp_directory(uniqid('test'));

      6. Confirm that database export worked as expected

       

      If I understand correctly, make_request_directory create a directory which die with it's content at end of PHP request  (\core_shutdown_manager::register_function('remove_dir', [$dir]);), so, Apache/X-Sendfile haven't time to get the file

       
      If correct, it's not specific to database activity, it could happen each time make_request_directory is used to download a file

            Unassigned Unassigned
            lwafflard Laurent Wafflard
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 minutes
                7m

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