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

Category overview inaccessible if capabilities cache fetch fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 4.5
    • Course
    • MOODLE_405_STABLE

      Steps to recreate:
      1) make sure $hascapability = $cache->get_many($keys); gets an empty array.
      2) Assign a user to Site Administrator
      3) Navigate to Course and category management page.

      Expected result: the page is shown.
      Actual result: the user is redirected to course/index.php?categoryid=1

      Analysis:
      A dig unearthed the function has_capability_on_any($capabilities)
      in the file course/classes/category.php
      which starts with checking the cache for the capabilities.

      If the cache fetch fails, $cache->get_many($keys) returns an empty array.
      This forces $needtoload to remain false, because an empty array isn't iterable.

      Suggest the following solution:
      ++
      diff --git a/course/classes/category.php b/course/classes/category.php
      index 86b6abb17ad..b1abf985cbd 100644
      — a/course/classes/category.php
      +++ b/course/classes/category.php
      @@ -1456,6 +1456,9 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
               $cache = cache::make('core', 'coursecat');
               $hascapability = $cache->get_many($keys);
               $needtoload = false;
      +        if (empty($hascapability))

      { +            $needtoload = true; +        }

               foreach ($hascapability as $capability) {
                   if ($capability === '1') {
                       return true;

            Unassigned Unassigned
            sashaanastasi1 SashaAnastasi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 38 minutes
                38m

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