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

Make it easier to use cm_info instead of get_coursemodule_from_id

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.7
    • 2.6.2, 2.7
    • Course, Performance
    • MOODLE_26_STABLE, MOODLE_27_STABLE
    • MOODLE_27_STABLE
    • wip-MDL-44720-master
    • Hide

      on any module view.php page substitute

      $event->add_record_snapshot('course_modules', $cm);

      with

      $event->add_record_snapshot('course_modules', $PAGE->cm);

      load page and make sure there are no errors

      (the rest is done in unittest)

      Show
      on any module view.php page substitute $event->add_record_snapshot('course_modules', $cm); with $event->add_record_snapshot('course_modules', $PAGE->cm); load page and make sure there are no errors (the rest is done in unittest)

      This used to be a part of MDL-44615 but I want to move it into separate issue because it is a very useful function and it looks like MDL-44615 is going to be delayed.

      I add a function cm_info::get_course_module_record() that allows to get an object from cm_info that is exactly the same as record in course_modules.

      Also it can be used instead of get_coursemodule_from_id() which is a very expensive function:

      $cm = get_coursemodule_from_id(null, $cmid, $courseid, true, MUST_EXIST);
      

      may be substituted with:

      $cm = get_fast_modinfo($courseid)->get_cm($cmid)->get_course_module_record(true);
      

      Assuming we are talking about current course, everything is already cached and the second option performs no DB queries.

      unittest included

            marina Marina Glancy
            marina Marina Glancy
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

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