Moodle
  1. Moodle
  2. MDL-30869

Regression: Legacy Course Files point to wrong location from file picker

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Duplicate
    • Affects Version/s: 2.2
    • Fix Version/s: None
    • Component/s: Files API
    • Environment:
      MS-Windows Server 2008 R2, IIS 7.5, FastCGI, MS-SQL 2008, PHP 5.3.8
    • Database:
      PostgreSQL, Microsoft SQL
    • Workaround:
      Hide

      Downgrade server back to 2.1.2 or 2.1.3 which works correctly.

      Show
      Downgrade server back to 2.1.2 or 2.1.3 which works correctly.
    • Affected Branches:
      MOODLE_22_STABLE
    • Rank:
      33872

      Description

      http://moodle.org/mod/forum/discuss.php?d=192624

      I upgraded my server to Moodle 2.2 but found the legacy course file area accessed via the file picker started pointing to System\Front page. (see image filePicker.jpg) So as a teacher I see no files.

      If I click on System I can then see categories and work my way to my course.

      The legacy course file are from the LH menu remained correct in all courses.

      No errors were reported during the upgrade I tried accessing from different browsers. I also tried the upgrade on two different servers.

      I have restored the server back to 2.1.2 and all is working properly again i.e I can see the course files area from the file picker.

      Any help appreciated.

      Replication steps:

      1. Upgraded Moodle 2.1.2 server to Moodle 2.2
      2. Go to a course
      3. Click Add a resource -> select file
      4. Click on Add
      5. Click on Legacy Course files
      6. Points to system\Front page
      1. 0001-MDL-30869-fix-file-picker-for-legacy-course-files.patch
        4 kB
        Adam Olley
      2. MDL_30869_2
        1 kB
        Nathan Mares
      3. MDL_30869_3.txt
        0.9 kB
        Nathan Mares
      4. MDL_30869.txt
        0.8 kB
        Nathan Mares
      5. MDL-30869_url.txt
        1 kB
        João de Amorim Junior
      6. MDL-30869.moddata.patch
        2 kB
        Ashley Holman
      7. MDL-30869.patch
        3 kB
        Chris Wharton
      1. filePicker.jpg
        42 kB
      2. Legacy course files.jpg
        87 kB

        Issue Links

          Activity

          Hide
          Daniel Arndt Alves added a comment -

          I've found the same problem, running the Moodle site on Server Linux, and Mac OS X Server, and database as MySQL.

          Show
          Daniel Arndt Alves added a comment - I've found the same problem, running the Moodle site on Server Linux, and Mac OS X Server, and database as MySQL.
          Hide
          David Clark added a comment - - edited

          Have same issue with WAMP2 (2.2a) server running Moodle 2.2 on Windows Server 2003 SP2.

          Show
          David Clark added a comment - - edited Have same issue with WAMP2 (2.2a) server running Moodle 2.2 on Windows Server 2003 SP2.
          Hide
          Daniel Arndt Alves added a comment - - edited

          On the line 67 of file moodle/repository/coursefiles/lib.php, the reference to $this->context->id, always return the value of SYSCONTEXTID. If I force the value to an valid context, the module always show the files and folders into legacy courses area of this particular course.

          The optional parameter "ctx_id" isn't passed to modle/repository/repository_ajax.php call, when I click from file picker on the web interface, and apparently the default value SYSTENTEXTID is always used.

          I try to use the old way ( global $COURSE; ), but the value of $COURSE->id is always equal to 1 in this function!

          Show
          Daniel Arndt Alves added a comment - - edited On the line 67 of file moodle/repository/coursefiles/lib.php, the reference to $this->context->id, always return the value of SYSCONTEXTID. If I force the value to an valid context, the module always show the files and folders into legacy courses area of this particular course. The optional parameter "ctx_id" isn't passed to modle/repository/repository_ajax.php call, when I click from file picker on the web interface, and apparently the default value SYSTENTEXTID is always used. I try to use the old way ( global $COURSE; ), but the value of $COURSE->id is always equal to 1 in this function!
          Hide
          Bill Burgos added a comment - - edited

          Hi,

          We have the same situation with our clients.

          However, AFAIK, downgrading to 2.1.x negates the changes needed in response to http://tracker.moodle.org/browse/MDL-30160

          +1 for fix.

          Show
          Bill Burgos added a comment - - edited Hi, We have the same situation with our clients. However, AFAIK, downgrading to 2.1.x negates the changes needed in response to http://tracker.moodle.org/browse/MDL-30160 +1 for fix.
          Hide
          Paul Nijbakker added a comment -

          Hi all,
          We have the same problem, i.e. the Legacy course files repository in the file picker is empty for teachers, while administrators see the Legacy site files instead of the course files.

          Show
          Paul Nijbakker added a comment - Hi all, We have the same problem, i.e. the Legacy course files repository in the file picker is empty for teachers, while administrators see the Legacy site files instead of the course files.
          Hide
          Nathan Mares added a comment -

          Hello,
          The problem seem to be related to changes to the way context records are passed around Moodle between Moodle 2.1 and 2.2.

          For the technically minded.. In 2.1 the context records were just an stdClass with public members for id, path, depth, contextlevel and instanceid. In 2.2 the members are protected and the context is actually an instance of the context_course class in lib/accesslib.php. The context class that the context_course inherits from has some magic methods for fetching these values but (quite reasonably) these don't get picked up further down the pipeline when the context is attached to the list of options used to call M.form_filemanager.init in lib/form/filemanager.js. I've created a patch for lib/form/filemanager.php which fetches and sets the above values so they can be read further down the chain.

          Cheers,
          Nathan

          Show
          Nathan Mares added a comment - Hello, The problem seem to be related to changes to the way context records are passed around Moodle between Moodle 2.1 and 2.2. For the technically minded.. In 2.1 the context records were just an stdClass with public members for id, path, depth, contextlevel and instanceid. In 2.2 the members are protected and the context is actually an instance of the context_course class in lib/accesslib.php. The context class that the context_course inherits from has some magic methods for fetching these values but (quite reasonably) these don't get picked up further down the pipeline when the context is attached to the list of options used to call M.form_filemanager.init in lib/form/filemanager.js. I've created a patch for lib/form/filemanager.php which fetches and sets the above values so they can be read further down the chain. Cheers, Nathan
          Hide
          Nathan Mares added a comment -

          Patch attached

          Show
          Nathan Mares added a comment - Patch attached
          Hide
          Nathan Mares added a comment -

          I came across another place where this was a problem - the file picker in the TinyMCE editor so have made a second patch. There were a number of places in the codebase this could have gone so there may have been better places to put this particular fix..?

          Show
          Nathan Mares added a comment - I came across another place where this was a problem - the file picker in the TinyMCE editor so have made a second patch. There were a number of places in the codebase this could have gone so there may have been better places to put this particular fix..?
          Hide
          Paul Nijbakker added a comment -

          Hello Nathan,
          Thanks for your effort with this bug. In my 2.2.1 installation the first patch has the desired effect, but the second one (for the file picker opened from the HTML editor) I am afraid has no effect in my case.

          Show
          Paul Nijbakker added a comment - Hello Nathan, Thanks for your effort with this bug. In my 2.2.1 installation the first patch has the desired effect, but the second one (for the file picker opened from the HTML editor) I am afraid has no effect in my case.
          Hide
          Nathan Mares added a comment -

          Hi Paul,
          Yeh not sure what I was thinking with that second patch. This one should do the trick with changes in lib/form/editor.php

          Show
          Nathan Mares added a comment - Hi Paul, Yeh not sure what I was thinking with that second patch. This one should do the trick with changes in lib/form/editor.php
          Hide
          Paul Nijbakker added a comment -

          Hello Nathan,

          Great thanks for these patches, the third one did fix the filepicker also in the HTML editor. In the process I have also discovered how I can link to an index file and get the local links to work.

          Rgrds,
          Paul.

          Show
          Paul Nijbakker added a comment - Hello Nathan, Great thanks for these patches, the third one did fix the filepicker also in the HTML editor. In the process I have also discovered how I can link to an index file and get the local links to work. Rgrds, Paul.
          Hide
          Chris Wharton added a comment -

          valid git patch file

          Show
          Chris Wharton added a comment - valid git patch file
          Hide
          Chris Wharton added a comment -

          Hi Nathan, I have added a valid patch file for this. This is helpful patch

          Show
          Chris Wharton added a comment - Hi Nathan, I have added a valid patch file for this. This is helpful patch
          Hide
          João de Amorim Junior added a comment -

          Hi all.

          We found a similar problem when editing an URL resource.
          The file picker accessed via the "Choose a link ..." button (in the 'external URL' item) was not showing the Legacy Course files.
          So, we changed the file \moodle\lib\form\url.php, based on the helpful patch previously attached by Mr. Nathan Mares.
          The change we made is described in the file MDL-30869_url.txt, which was attached to this post.

          Thanks a lot.

          Show
          João de Amorim Junior added a comment - Hi all. We found a similar problem when editing an URL resource. The file picker accessed via the "Choose a link ..." button (in the 'external URL' item) was not showing the Legacy Course files. So, we changed the file \moodle\lib\form\url.php, based on the helpful patch previously attached by Mr. Nathan Mares. The change we made is described in the file MDL-30869 _url.txt, which was attached to this post. Thanks a lot.
          Hide
          Martin Dougiamas added a comment -

          This should be in the next sprint

          Show
          Martin Dougiamas added a comment - This should be in the next sprint
          Hide
          Martin Dougiamas added a comment -

          Bumping to blocker simply because it's annoying and easy to fix, and has a lot of votes.

          Show
          Martin Dougiamas added a comment - Bumping to blocker simply because it's annoying and easy to fix, and has a lot of votes.
          Hide
          Adam Olley added a comment -

          lib/form/filepicker.php needs the same fix, otherwise file pickers don't get their correct context.

          Patch incoming. (I can throw it up on github if thats easier for integrators).

          Show
          Adam Olley added a comment - lib/form/filepicker.php needs the same fix, otherwise file pickers don't get their correct context. Patch incoming. (I can throw it up on github if thats easier for integrators).
          Hide
          Michael de Raadt added a comment -

          I've lined this up for the next sprint.

          Show
          Michael de Raadt added a comment - I've lined this up for the next sprint.
          Hide
          Ashley Holman added a comment -

          Attaching an additional patch to fix the file picker in the database module fields.

          Show
          Ashley Holman added a comment - Attaching an additional patch to fix the file picker in the database module fields.
          Hide
          Hugh Davenport added a comment -

          Hi,

          I'm just letting anyone know that looks at this tracker that uses the patch. We had this patch applied on one of our clients systems, and a recent upgrade to 2.2.2 broke the site so that you couldn't add any new resources/activities/etc to a course. After this patch was reverted, these problems disappeared.

          A sample error we got was:
          Coding error detected, it must be fixed by a programmer: PHP catchable fatal error

          More information about this error

          Debug info: Argument 2 passed to has_capability() must be an instance of context, instance of stdClass given, called in /var/www/moodle/lib/weblib.php on line 1404 and defined
          Stack trace:
          line 365 of /lib/setuplib.php: coding_exception thrown
          line 348 of /lib/accesslib.php: call to default_error_handler()
          line 1404 of /lib/weblib.php: call to has_capability()
          line 47 of /lib/form/editor.php: call to trusttext_trusted()
          line 566 of /lib/pear/HTML/QuickForm.php: call to MoodleQuickForm_editor->MoodleQuickForm_editor()
          line 602 of /lib/pear/HTML/QuickForm.php: call to HTML_QuickForm->_loadElement()
          line 754 of /course/moodleform_mod.php: call to HTML_QuickForm->addElement()
          line 37 of /mod/label/mod_form.php: call to moodleform_mod->add_intro_editor()
          line 169 of /lib/formslib.php: call to mod_label_mod_form->definition()
          line 71 of /course/moodleform_mod.php: call to moodleform->moodleform()
          line 256 of /course/modedit.php: call to moodleform_mod->moodleform_mod()

          Cheers,

          Hugh

          Show
          Hugh Davenport added a comment - Hi, I'm just letting anyone know that looks at this tracker that uses the patch. We had this patch applied on one of our clients systems, and a recent upgrade to 2.2.2 broke the site so that you couldn't add any new resources/activities/etc to a course. After this patch was reverted, these problems disappeared. A sample error we got was: Coding error detected, it must be fixed by a programmer: PHP catchable fatal error More information about this error Debug info: Argument 2 passed to has_capability() must be an instance of context, instance of stdClass given, called in /var/www/moodle/lib/weblib.php on line 1404 and defined Stack trace: line 365 of /lib/setuplib.php: coding_exception thrown line 348 of /lib/accesslib.php: call to default_error_handler() line 1404 of /lib/weblib.php: call to has_capability() line 47 of /lib/form/editor.php: call to trusttext_trusted() line 566 of /lib/pear/HTML/QuickForm.php: call to MoodleQuickForm_editor->MoodleQuickForm_editor() line 602 of /lib/pear/HTML/QuickForm.php: call to HTML_QuickForm->_loadElement() line 754 of /course/moodleform_mod.php: call to HTML_QuickForm->addElement() line 37 of /mod/label/mod_form.php: call to moodleform_mod->add_intro_editor() line 169 of /lib/formslib.php: call to mod_label_mod_form->definition() line 71 of /course/moodleform_mod.php: call to moodleform->moodleform() line 256 of /course/modedit.php: call to moodleform_mod->moodleform_mod() Cheers, Hugh
          Hide
          Rex Lorenzo added a comment -

          I applied the 2.2.2 update to our test system and I was able to upload resources (e.g. files) fine.

          However, the "legacy course files" does still seem to be broken.

          1) Enable legacy course files repo
          2) Go to course and click on "Legacy course files" under Settings > Course administration
          3) Click "Edit legacy course files" and upload a file
          4) Now, go to add a resource and in the file picker choose the "Legacy course files" repo and see that you get "No files available" instead of seeing the file you just uploaded.

          Show
          Rex Lorenzo added a comment - I applied the 2.2.2 update to our test system and I was able to upload resources (e.g. files) fine. However, the "legacy course files" does still seem to be broken. 1) Enable legacy course files repo 2) Go to course and click on "Legacy course files" under Settings > Course administration 3) Click "Edit legacy course files" and upload a file 4) Now, go to add a resource and in the file picker choose the "Legacy course files" repo and see that you get "No files available" instead of seeing the file you just uploaded.
          Hide
          Rajesh Taneja added a comment -

          problem seems to occur when encoding context object in js_writer::function_call_with_Y (lib/outputcomponent.php). That's why converting context object to stdClass resolves this issue.

          Show
          Rajesh Taneja added a comment - problem seems to occur when encoding context object in js_writer::function_call_with_Y (lib/outputcomponent.php). That's why converting context object to stdClass resolves this issue.
          Hide
          Rajesh Taneja added a comment -

          This is duplicate of MDL-31789, hence closing this.
          Will add comment in MDL-31789 to include testing instruction for this bug.

          Show
          Rajesh Taneja added a comment - This is duplicate of MDL-31789 , hence closing this. Will add comment in MDL-31789 to include testing instruction for this bug.
          Hide
          Andrea Gregory (Gordon) added a comment -

          Hi There,

          I have tried all patches but still cannot get this working. This is using a version 2.2.1 release.

          Any ideas? Still getting the 'no files available' tetxt but yet there are files visible in the course admin panel.

          Thanks

          Andrea

          Show
          Andrea Gregory (Gordon) added a comment - Hi There, I have tried all patches but still cannot get this working. This is using a version 2.2.1 release. Any ideas? Still getting the 'no files available' tetxt but yet there are files visible in the course admin panel. Thanks Andrea
          Hide
          Rajesh Taneja added a comment -

          Hello Andrea,

          can you please check if you can see following changes in your code.
          http://git.moodle.org/gw?p=integration.git;a=commitdiff;h=b2cb00c2e91e75b1d625d667165de0de86c56ea3

          Show
          Rajesh Taneja added a comment - Hello Andrea, can you please check if you can see following changes in your code. http://git.moodle.org/gw?p=integration.git;a=commitdiff;h=b2cb00c2e91e75b1d625d667165de0de86c56ea3

            People

            • Votes:
              39 Vote for this issue
              Watchers:
              30 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: