Moodle
  1. Moodle
  2. MDL-26452

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker 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:
      Easy
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      16663

      Description

      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.

        Activity

        Hide
        Petr Škoda added a comment -

        Hello,

        I have submitted a patch that selects field with the lowest id if sortorder missing and also fixed the upgrade, hopefully this should solve it.

        Petr

        Show
        Petr Škoda added a comment - Hello, I have submitted a patch that selects field with the lowest id if sortorder missing and also fixed the upgrade, hopefully this should solve it. Petr
        Hide
        Helen Foster added a comment -

        Michael, thanks for reporting this issue. Fix included in latest 2.0.1+ weekly.

        Show
        Helen Foster added a comment - Michael, thanks for reporting this issue. Fix included in latest 2.0.1+ weekly.

          People

          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: