Moodle
  1. Moodle
  2. MDL-26616

On migrating to 2.0+ files create two rows in mdl_files with the same sortorder, breaking the links

    Details

    • Database:
      MySQL
    • Difficulty:
      Moderate
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      The symptom is after upgrading, when some links to files were clicked you get a message like "Sorry, the requested file could not be found", after editing the resource and saving the problem was gone.

      The problem is in the resource lib, in the function resource_get_coursemodule_info in which the module gets all the files for a context and if there are more than one, it pops the first one in the list.

      The problem is that when you migrate to 2.0+ all files create two resources (according to documentation): The file itself and the folder where it belongs, and the sortorder for both is exactly the same: 0. So when mysql returns the file first, it works, and when it returns the other way around it doesn't (pretty hard to find).

      I fixed it by updating the sortorder to 1 for all rows in mdl_files that had component 'mod_resource' and did not have a filename equal to '.' (folder). I also deleted the course cached info. In sql:

      update mdl_files set sortorder=1 where component='mod_resource' and filename <> '.' and sortorder = 0;

      update mdl_course set modinfo = NULL;

      Hope it helps you fixing it.

        Gliffy Diagrams

          Activity

          Hide
          Petr Skoda added a comment -

          Oh, this is caused by the borked upgrade of resource module. I have already fixed the upgrade code and added a workaround into the mod/resource/view.php, I forgot to review the resource_get_coursemodule_info() too.

          Thanks for the report!

          Show
          Petr Skoda added a comment - Oh, this is caused by the borked upgrade of resource module. I have already fixed the upgrade code and added a workaround into the mod/resource/view.php, I forgot to review the resource_get_coursemodule_info() too. Thanks for the report!
          Hide
          Petr Skoda added a comment -

          This should be Windows only problem.

          Show
          Petr Skoda added a comment - This should be Windows only problem.
          Hide
          Petr Skoda added a comment -

          This should be fixed in the next weekly build, thanks a lot for the report!

          Petr

          Show
          Petr Skoda added a comment - This should be fixed in the next weekly build, thanks a lot for the report! Petr
          Hide
          Jorge Villalon added a comment -

          Hi Petr.
          It isn't a Windows only problem, we are using CentOs.

          Show
          Jorge Villalon added a comment - Hi Petr. It isn't a Windows only problem, we are using CentOs.
          Hide
          Petr Skoda added a comment -

          hmmm, it should fix it anyway, could you please try the git branch from PULL request?

          Show
          Petr Skoda added a comment - hmmm, it should fix it anyway, could you please try the git branch from PULL request?
          Hide
          David Mudrak added a comment -

          Tested. Thanks Jorge for the report and Petr for the fix. That patch will be part of the next weekly build.

          Show
          David Mudrak added a comment - Tested. Thanks Jorge for the report and Petr for the fix. That patch will be part of the next weekly build.

            People

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

              Dates

              • Created:
                Updated:
                Resolved: