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

Upgrade of 1.9 to 2.0.1 loses all resource files on Windows server



    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.0.2
    • Component/s: Resource
    • Labels:
    • Environment:
      Windows 7, but likely will work same on Windows server machines
    • Difficulty:
    • Affected Branches:
    • Fixed Branches:


      In "mod/resource/db/upgrade.php" at line 180, conversion for versions older than 2009062603 calls "resource_20_migrate()". This sets a filed in "resource" table called "mainfile". That part works correctly. Later at line 219 the conversion code for versions older than 2009080501 removed the "mainfile" field from the "resource" table, and instead sets a field called "sortorder". At line 235 the PHP function "dirname" is used, which on Windows systems may return Windows style directory separators '
      '. Since the "files" library doesn't follow the Windows conventions, this leads to problems. Specifically, the line
      $filepath = file_correct_filepath(dirname($instance->mainfile));
      often returns '/
      /'. Two lines later, function "file_set_sortorder()" is called, but fails because the $filepath condition is not met. No error message is produced at this point.

      After the conversion completes, links to resource files will be unreliable. This is because each file actually has 2 entries in the file table. One for the file itself and one for a related file with name "." (the containing directory?). Since the sortorder never gets set, the "view" code picks whichever one comes back first from the query. Sometimes it works and sometimes it results in a "File Not Found" error. If sortorder had been set correctly, the view code would work correctly.

      I made a temporary fix with the lines:
      if( $filepath == '/
      /' )

      { // We don't store Windows style paths in DB, so make sure we // don't end up with a Windows style result - MJL $filepath = '/'; }

      BTW, the "sortorder" field is not mentioned in "http://docs.moodle.org/en/Development:Using_the_file_API". It would be helpful if somebody could explain its use. I see how it's is being used for resource files, but am unclear about the more general case.




            • Assignee:
              skodak Petr Skoda
              mlitzkow Michael J Litzkow
              Eloy Lafuente (stronk7)
              Component watchers:
              Adrian Greeve, Mihail Geshoski, Peter Dias
            • Votes:
              1 Vote for this issue
              1 Start watching this issue


              • Created:
                Fix Release Date: