Moodle

Permission denied error when importing .csv files with quiz results into a course

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.2, 1.9.3
  • Fix Version/s: 1.9.5
  • Component/s: Course, Gradebook
  • Labels:
    None
  • Environment:
    Windows Server 2003 SP2, IIS 6, MSSQL 2005, PHP 5.2.6
    Also occurs on Windows XP SP2, IIS 5.1
    Moodle 1.9.2+ (build 20081008). I also tried it on the most recent version of Moodle 1.9.3+
  • Database:
    Microsoft SQL
  • URL:
    Not available - the Moodle site is on my dev box.
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

I'm getting an error when I import a .csv file containing quiz results into a course. Moodle shows a message saying: "Grade import success" but then it also gives me this warning:

Warning: unlink(D:\MoodleData/temp/gradeimport/cvs/2/1223556950) [function.unlink]: Permission denied in D:\Moodle\grade\import\csv\index.php on line 481

See the attached screenshot.

If I do a select on the mdl_grade_grades_history table (or mdl_grade_grades) the quiz results from the .csv file have not been added.

The first thing I did was to give both the moodle installation folder and the moodledata folders various different NTFS permissions to try and resolve the permission denied problem e.g.:

IUSR_myserver : modify, read, write, read & execute
IWAM_myserver : modify, read, write, read & execute
NETWORK SERVICE : modify, read, write, read & execute

I even gave the 'Everyone' group full control of both my ..\moodle and ..\moodledata folders, but the problem persists - I still get the permission denied error and the grades are not imported into Moodle.

I had a look at the code in line 481 of the ..\grade\import\csv\index.php file and it contains the unlink() function:

unlink($filename);

I think that this command tries to delete the file contained in $filename, but it is not able to and I don't know why. Could it be because the file is still open, or is it genuinely a NTFS permission error?

I then tried to disable line 481 by commenting out the unlink($filename); command. Then I tried to import the .csv files into Moodle again and this time I did NOT get any permission denied errors. Moodle successfully imported the .csv files and I was able to see the quiz results in the Grader Report.

But I'm a bit concerned about the implications of disabling the unlink($filename); line.
Will it leave a bunch of unnecessary temporary files on the server? Will it cause some other regression?

Finally, when I had a closer look at the error message that Moodle was giving me (see screenshot) I noticed that there are forward AND back slashes in the path of the MoodleData folder that is passed to the unlink() function:

Warning: unlink(D:\MoodleData/temp/gradeimport/cvs/2/1223556950)

Does this have any meaning? Shouldn't they all be backslashes? I don't think the above path is valid - at least, not in Windows!

If it helps debug the problem, the .csv file that I used to import the users has this structure:

id,username,password,email,firstname,lastname,idnumber,institution,department,phone1,phone2,city,url,icq,skype,aim,yahoo,msn,country,deleted,course1,course2
1,student1,changeme,me@mail.co.za,Student 1,User 1,7501020304085,ABC.com,ABC,0123454567,0123334545,SomeVille,N/A,N/A,N/A,N/A,N/A,N/A,ZA,0,CRS_TEST1,CRS_TEST2

And the .csv file that I used to import quiz data into the QZ_TEST1 quiz has this structure:

username,Quiz: QZ_TEST1
student1,9.00
student2,2.00

Moodle is able to import both these .csv files only when the unlink($filename); line is disabled.

Activity

Hide
Luis de Vasconcelos added a comment -

I experimented a bit and added this command:

fclose($fp);

on line 480 of the ..\grade\import\csv\index.php file just before the unlink($filename); command. It seems to work and Moodle doesn't give me the unlink permission denied error.

But what are the consequences of issuing the fclose($fp); command in this place?
And will it break some other Moodle functionality?

Show
Luis de Vasconcelos added a comment - I experimented a bit and added this command: fclose($fp); on line 480 of the ..\grade\import\csv\index.php file just before the unlink($filename); command. It seems to work and Moodle doesn't give me the unlink permission denied error. But what are the consequences of issuing the fclose($fp); command in this place? And will it break some other Moodle functionality?
Hide
Eloy Lafuente (stronk7) added a comment -

Assigning to Nicolas and addressing for 1.9.4...

thanks for the report, Luis. Ciao

Show
Eloy Lafuente (stronk7) added a comment - Assigning to Nicolas and addressing for 1.9.4... thanks for the report, Luis. Ciao
Hide
Tim Hunt added a comment -

Not actually anything to do with quiz.

Show
Tim Hunt added a comment - Not actually anything to do with quiz.
Hide
Petr Škoda (skodak) added a comment -

fixed, thanks a lot!

Show
Petr Škoda (skodak) added a comment - fixed, thanks a lot!
Hide
Sam Hemelryk added a comment -

Confirmed unlink success. Thanks

Show
Sam Hemelryk added a comment - Confirmed unlink success. Thanks

Dates

  • Created:
    Updated:
    Resolved: