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

$PAGE context error when trying to duplicate or delete activity

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 3.7
    • Course
    • MOODLE_37_STABLE

      in debug mode, when we duplicate activity, and delete it, we've a popup error:

      $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context()

       

      Error code: codingerror
      * line 488 of /lib/pagelib.php: coding_exception thrown
      * line 820 of /lib/pagelib.php: call to moodle_page->magic_get_context()
      * line 1456 of /lib/weblib.php: call to moodle_page->__get()
      * line 474 of /mod/url/locallib.php: call to format_string()
      * line 109 of /mod/url/locallib.php: call to url_get_variable_values()
      * line 247 of /mod/url/lib.php: call to url_get_full_url()
      * line 465 of /course/lib.php: call to url_get_coursemodule_info()
      * line 671 of /lib/modinfolib.php: call to get_array_of_activities()
      * line 463 of /lib/modinfolib.php: call to course_modinfo::inner_build_course_cache()
      * line 418 of /lib/modinfolib.php: call to course_modinfo->__construct()
      * line 2169 of /lib/modinfolib.php: call to course_modinfo::instance()
      * line 2243 of /lib/modinfolib.php: call to get_fast_modinfo()
      * line 3591 of /course/externallib.php: call to get_course_and_cm_from_cmid()
      * line 244 of /lib/externallib.php: call to core_course_external::edit_module()
      * line 59 of /lib/ajax/service.php: call to external_api::call_external_function()
      

      We can't reproduce this with a new empty course.
      But this is corrected with this changes in /mod/url/locallib.php, function url_get_variable_values() : 

      Whenever there is a call to format_string(...), inject context «, true, array('context' => $coursecontext)» like this :

          $values = array (
              'courseid'        => $course->id,
              'coursefullname'  => format_string($course->fullname, true, array('context' => $coursecontext)),
              'courseshortname' => format_string($course->shortname, true, array('context' => $coursecontext)),
              'courseidnumber'  => $course->idnumber,
              'coursesummary'   => $course->summary,
              'courseformat'    => $course->format,
              'lang'            => current_language(),
              'sitename'        => format_string($site->fullname, true, array('context' => $coursecontext)),
              'serverurl'       => $CFG->wwwroot,
              'currenttime'     => time(),
              'urlinstance'     => $url->id,
              'urlcmid'         => $cm->id,
              'urlname'         => format_string($url->name, true, array('context' => $coursecontext)),
              'urlidnumber'     => $cm->idnumber,
      
      

      I don't know if it's the good way, but this work for us.
      Why initially 'courseshortname' have context injection, but not the others ?

       

        1. image-2019-06-17-09-33-13-555.png
          image-2019-06-17-09-33-13-555.png
          154 kB
        2. image-2020-01-13-10-50-40-308.png
          image-2020-01-13-10-50-40-308.png
          258 kB
        3. image-2020-01-13-10-52-26-616.png
          image-2020-01-13-10-52-26-616.png
          228 kB
        4. MDL-65916.patch
          1 kB
        5. MDL-65916.wmv
          3.60 MB

            Unassigned Unassigned
            philippematabiau Philippe Matabiau
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.