Moodle
  1. Moodle
  2. MDL-18952

Importing files to Question bank DON'T WORK from "Import from file upload..." and WORKS from "Import from file already in course files..."

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.4
    • Fix Version/s: 1.9.14
    • Component/s: Questions
    • Labels:
    • Environment:
      Moodle 1.9.4+ build 20090422, PHP 5.2.8, MYSQL 5.0.67, WINDOWS 2003 SERVER, IIS WEB SERVER
    • Database:
      MySQL
    • Testing Instructions:
      Hide

      1. Test importing questions one your normal server, to ensure this change does not cause any regressions.

      2. If you have an IIS install that demonstrated this old problem, verify that this fix actually fixes it.

      Show
      1. Test importing questions one your normal server, to ensure this change does not cause any regressions. 2. If you have an IIS install that demonstrated this old problem, verify that this fix actually fixes it.
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE
    • Rank:
      5227

      Description

      When importing files to Question Bank previously exported from there in any format like MOODLE XML, when trying to import using option "Import from file upload..." DON'T WORK looking like file not uploaded and a message showing this: "Parsing questions from import file. Cannot read import file (or file is empty) An error occurred during import processing".

      If you use the other option down named "Import from file already in course files..." that allow you to upload a file and select it IT WORKS PROPERLY with the same file.

          • Updated 28-04-2009 ***
            Just discovered what's happening: Looks like not taken TEMP variable enviroment properly and using a ¿default? one where Web Server user don't have write permissions to upload file:

      TEMP and TMP variables are pointting to "C:\TEMP" and discovered that it's training to write in "C:\WINDOWS\TEMP" so getting error "Cannot read import file (or file is empty) An error occurred during import processing".

      ¿Perhaps an error taken environment?

        Issue Links

          Activity

          Hide
          Tim Hunt added a comment -

          Thank you!

          Several people have reported this before in the forums, and I have never been able to work out what the problem was. It should be quite easy to fix now.

          Please could I ask you to check one more thing for me: Does uploading files directly into a form, for example, uploading a new picture into your user profile, work for you?

          (Basically, I want to work out, is this a problem with any form that does file upload, or is it just a problem with the question import form.)

          Show
          Tim Hunt added a comment - Thank you! Several people have reported this before in the forums, and I have never been able to work out what the problem was. It should be quite easy to fix now. Please could I ask you to check one more thing for me: Does uploading files directly into a form, for example, uploading a new picture into your user profile, work for you? (Basically, I want to work out, is this a problem with any form that does file upload, or is it just a problem with the question import form.)
          Hide
          Raimundo Alba added a comment -

          Hello Tim,

          Just tried several upload forms (images, users, etc...) and works properly without C:\WINDOWS\TEMP permissions, retried reported one and it fails so it looks like related to import questions form/module...

          Please, also take note this is related (the same) as reported by me in MDL-18953 that has been asigned to Mark Nielsen. Should I update this report in any way or leave this in your hands?

          NOTE: Discovered too that it don't write in C:\WINDOWS\TEMP but needs at least READ permissions to work or better to only look in TEMP enviroment variable...

          Thanks in Advance.
          Raimundo Alba

          Show
          Raimundo Alba added a comment - Hello Tim, Just tried several upload forms (images, users, etc...) and works properly without C:\WINDOWS\TEMP permissions, retried reported one and it fails so it looks like related to import questions form/module... Please, also take note this is related (the same) as reported by me in MDL-18953 that has been asigned to Mark Nielsen. Should I update this report in any way or leave this in your hands? NOTE: Discovered too that it don't write in C:\WINDOWS\TEMP but needs at least READ permissions to work or better to only look in TEMP enviroment variable... Thanks in Advance. Raimundo Alba
          Hide
          Tim Hunt added a comment -

          I can't work this out. I did find on http://php.net/tempnam this bit that looked relevant:

          "If the directory does not exist, tempnam() may generate a file in the system's temporary directory, and return the name of that."

          However, I can't find any calls to tempnam or related functions in the question import code.

          Any help with working out exactly why Moodle wants read-only access to the windows temporary files folder during question import would be gratefully received.

          Show
          Tim Hunt added a comment - I can't work this out. I did find on http://php.net/tempnam this bit that looked relevant: "If the directory does not exist, tempnam() may generate a file in the system's temporary directory, and return the name of that." However, I can't find any calls to tempnam or related functions in the question import code. Any help with working out exactly why Moodle wants read-only access to the windows temporary files folder during question import would be gratefully received.
          Hide
          Charles Fulton added a comment - - edited

          We've just encountered this problem at Kalamazoo but I think I've got a fix. The problem is that not all system configurations (particularly out-of-the-box IIS) will allow read access to the temporary upload directly, although writing isn't a problem. The question import process doesn't move the uploaded file into the dataroot before attempting to read it (as opposed to Moodle's standard file upload). Please see https://github.com/mackensen/moodle/compare/MOODLE_19_STABLE...MDL-18952 for a patch which moves a new upload into the temp folder in the dataroot prior to reading. This resolved our problem.

          EDIT: To clarify, this is present on 1.9.13.

          Show
          Charles Fulton added a comment - - edited We've just encountered this problem at Kalamazoo but I think I've got a fix. The problem is that not all system configurations (particularly out-of-the-box IIS) will allow read access to the temporary upload directly, although writing isn't a problem. The question import process doesn't move the uploaded file into the dataroot before attempting to read it (as opposed to Moodle's standard file upload). Please see https://github.com/mackensen/moodle/compare/MOODLE_19_STABLE...MDL-18952 for a patch which moves a new upload into the temp folder in the dataroot prior to reading. This resolved our problem. EDIT: To clarify, this is present on 1.9.13.
          Hide
          Tim Hunt added a comment -

          Can I be picky and point out that if you compute $importfile = $CFG->dataroot . '/temp/' . $realfilename; outside the if, then you can use that in the if test, which makes the code less duplicated, and easier to read.

          Any chance you could do a quick git commit --amend?

          Show
          Tim Hunt added a comment - Can I be picky and point out that if you compute $importfile = $CFG->dataroot . '/temp/' . $realfilename; outside the if, then you can use that in the if test, which makes the code less duplicated, and easier to read. Any chance you could do a quick git commit --amend?
          Hide
          Charles Fulton added a comment -

          Makes sense to me; commit amended.

          Show
          Charles Fulton added a comment - Makes sense to me; commit amended.
          Hide
          Tim Hunt added a comment -

          Looks good to me!

          Show
          Tim Hunt added a comment - Looks good to me!
          Hide
          Charles Fulton added a comment -

          I've posted a related fix for MDL-18953, which doesn't currently have anyone assigned to it.

          Show
          Charles Fulton added a comment - I've posted a related fix for MDL-18953 , which doesn't currently have anyone assigned to it.
          Hide
          Sam Hemelryk added a comment -

          Thanks guys, this has been integrated now

          Show
          Sam Hemelryk added a comment - Thanks guys, this has been integrated now
          Hide
          Sam Hemelryk added a comment -

          Hi Charles thanks for mentioning MDL-18953 I've now assigned that to Rosie who has been fixing our lesson issues recently and marked it so that hopefully it gets into our next sprint.

          Cheers
          Sam

          Show
          Sam Hemelryk added a comment - Hi Charles thanks for mentioning MDL-18953 I've now assigned that to Rosie who has been fixing our lesson issues recently and marked it so that hopefully it gets into our next sprint. Cheers Sam
          Hide
          Eloy Lafuente (stronk7) added a comment -

          I've tested uploading files and seems to work here. But his is a Mac, no access to IIS here. So if anybody else can confirm it's working there in a site previously failing... it would be great, TIA!

          Show
          Eloy Lafuente (stronk7) added a comment - I've tested uploading files and seems to work here. But his is a Mac, no access to IIS here. So if anybody else can confirm it's working there in a site previously failing... it would be great, TIA!
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Anyone can confirm IIS behavior with this patch applied? 3..2..1..

          Show
          Eloy Lafuente (stronk7) added a comment - Anyone can confirm IIS behavior with this patch applied? 3..2..1..
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Assuming it's a good solution for problematic IIS sites. Normal sites seem to continue working ok.

          Feel free to create new issue if problem persists.

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Assuming it's a good solution for problematic IIS sites. Normal sites seem to continue working ok. Feel free to create new issue if problem persists. Ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          And this code has been spread to all Moodle git and cvs repositories. Many thanks! Closing.

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - And this code has been spread to all Moodle git and cvs repositories. Many thanks! Closing. Ciao

            People

            • Votes:
              7 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: