Moodle
  1. Moodle
  2. MDL-35158

Random Glossary block returns an error when you delete the linked glossary

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.3.1
    • Fix Version/s: 2.3.4
    • Component/s: Glossary
    • Labels:

      Description

      Notice: Undefined index: 72 in S:\htdocs\moodle\blocks\glossary_random\block_glossary_random.php on line 132

      We're getting the above error on a course with the glossary and glossary random module installed.

      Reproduction steps:

      1. switch on debugging
      2. add a glossary activity (can be empty)
      3. add a Random Glossary block and configure it - just need to point it at the glossary you added and save
      4. delete the original Glossary
      5. Refresh the course page

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            Filip Benčo added a comment -

            This happens when you delete glossary, which is used by glossary_random block.

            I have attached a patch.

            Have a nice day.

            Filip

            Show
            Filip Benčo added a comment - This happens when you delete glossary, which is used by glossary_random block. I have attached a patch. Have a nice day. Filip
            Hide
            Michael de Raadt added a comment -

            Thanks for the report and the patch.

            Show
            Michael de Raadt added a comment - Thanks for the report and the patch.
            Hide
            Michael de Raadt added a comment -

            Here is some more information from a duplicate issue. Credit to Howard Miller.

            The code checks that it has configuration data and doesn't do anything if it doesn't. Once it has been successfully configured it can drop through to this line..

            $cm = $modinfo->instances['glossary'][$glossaryid];
            

            This fails because there is no 'glossary' index (there aren't any). A simple solution is to wrap that in an isset() and provide a sensible message. Better yet, it should un-configure itself under these conditions

            Show
            Michael de Raadt added a comment - Here is some more information from a duplicate issue. Credit to Howard Miller. The code checks that it has configuration data and doesn't do anything if it doesn't. Once it has been successfully configured it can drop through to this line.. $cm = $modinfo->instances['glossary'][$glossaryid]; This fails because there is no 'glossary' index (there aren't any). A simple solution is to wrap that in an isset() and provide a sensible message. Better yet, it should un-configure itself under these conditions
            Hide
            Stephen Bloomer added a comment -

            Still there in 2.3.2. Causing issues as it wipes all access (including admins) and we have to restore from the last backup. It has happened twice to us know.

            Show
            Stephen Bloomer added a comment - Still there in 2.3.2. Causing issues as it wipes all access (including admins) and we have to restore from the last backup. It has happened twice to us know.
            Hide
            David added a comment - - edited

            This seemed related, so I'm adding it to this issue instead of starting a new one. Main difference is that the glossary in question was not deleted, but had all of its entries deleted during a reset, and the error shows when importing material from that course into another course.:

            Situation (Moodle 2.3.2+ Build: 20120920):

            Course A containing several glossary and one Random Glossary Entry Block
            Course A is reset, deleting all glossary entries
            New Course B created and Import function used to pull one topic section from Course A
            Process ends with the following (debugging on):

            Coding error detected, it must be fixed by a programmer: PHP catchable fatal error
            Debug info: Argument 2 passed to has_capability() must be an instance of context, null given, called in /usr/share/moodle/blocks/glossary_random/block_glossary_random.php on line 134 and defined
            Error code: codingerror
            Stack trace:
            • line 397 of /lib/setuplib.php: coding_exception thrown
            • line 355 of /lib/accesslib.php: call to default_error_handler()
            • line 134 of /blocks/glossary_random/block_glossary_random.php: call to has_capability()
            • line 281 of /blocks/moodleblock.class.php: call to block_glossary_random->get_content()
            • line 232 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
            • line 935 of /lib/blocklib.php: call to block_base->get_content_for_output()
            • line 987 of /lib/blocklib.php: call to block_manager->create_block_contents()
            • line 352 of /lib/blocklib.php: call to block_manager->ensure_content_created()
            • line 7 of /theme/base/layout/general.php: call to block_manager->region_has_content()
            • line 765 of /lib/outputrenderers.php: call to include()
            • line 712 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
            • line 227 of /course/view.php: call to core_renderer->header()

            If the Random Entry Block is removed, the process competes successfully.
            If the Random Entry Block is added back, same error and stack trace are returned.

            The imported section contains a glossary, but not the one associated with the Random Glossary Entry Block.

            If the entire course is imported into the new course, the process completes successfully.

            Show
            David added a comment - - edited This seemed related, so I'm adding it to this issue instead of starting a new one. Main difference is that the glossary in question was not deleted, but had all of its entries deleted during a reset, and the error shows when importing material from that course into another course.: Situation (Moodle 2.3.2+ Build: 20120920): Course A containing several glossary and one Random Glossary Entry Block Course A is reset, deleting all glossary entries New Course B created and Import function used to pull one topic section from Course A Process ends with the following (debugging on): Coding error detected, it must be fixed by a programmer: PHP catchable fatal error Debug info: Argument 2 passed to has_capability() must be an instance of context, null given, called in /usr/share/moodle/blocks/glossary_random/block_glossary_random.php on line 134 and defined Error code: codingerror Stack trace: • line 397 of /lib/setuplib.php: coding_exception thrown • line 355 of /lib/accesslib.php: call to default_error_handler() • line 134 of /blocks/glossary_random/block_glossary_random.php: call to has_capability() • line 281 of /blocks/moodleblock.class.php: call to block_glossary_random->get_content() • line 232 of /blocks/moodleblock.class.php: call to block_base->formatted_contents() • line 935 of /lib/blocklib.php: call to block_base->get_content_for_output() • line 987 of /lib/blocklib.php: call to block_manager->create_block_contents() • line 352 of /lib/blocklib.php: call to block_manager->ensure_content_created() • line 7 of /theme/base/layout/general.php: call to block_manager->region_has_content() • line 765 of /lib/outputrenderers.php: call to include() • line 712 of /lib/outputrenderers.php: call to core_renderer->render_page_layout() • line 227 of /course/view.php: call to core_renderer->header() If the Random Entry Block is removed, the process competes successfully. If the Random Entry Block is added back, same error and stack trace are returned. The imported section contains a glossary, but not the one associated with the Random Glossary Entry Block. If the entire course is imported into the new course, the process completes successfully.
            Hide
            omer added a comment -

            Was able to reproduce here...
            2.3.1

            Also happens when you import a whole course and the glossary comes empty.

            Omer

            Show
            omer added a comment - Was able to reproduce here... 2.3.1 Also happens when you import a whole course and the glossary comes empty. Omer
            Hide
            Allan Lee Mesina added a comment -

            This is also happening on our freshly installed Moodle 2.3.2

            By looking at line 134 of the block_glossary_random.php, it tries to get the context_instance of a glossary. If the glossary has already been deleted, it will give out the error. Starting at line 138 is a code that should prevent the error. This is a simple logic that has been missed by the programmer. This should be changed so that the check is done prior to calling for a context_instance.

            In my attempt to resolve this issue, I managed to get rid of the error by changing the order of the if statements starting at line 134.

            Change lines 134 through 148

            from

            <code>
            if (!has_capability('mod/glossary:view', get_context_instance(CONTEXT_MODULE, $cm->id)))

            { return ''; }

            if (!isset($modinfo->instances['glossary'][$glossaryid])) { // we can get here if the glossary has been deleted, so // unconfigure the glossary from the block.. $this->config->glossary = 0; $this->config->cache = ''; $this->instance_config_commit(); $this->content->text = get_string('notyetconfigured','block_glossary_random'); $this->content->footer = ''; return $this->content; }
            </code>

            to

            <code>
            if (!isset($modinfo->instances['glossary'][$glossaryid])) { // we can get here if the glossary has been deleted, so // unconfigure the glossary from the block.. $this->config->glossary = 0; $this->config->cache = ''; $this->instance_config_commit(); $this->content->text = get_string('notyetconfigured','block_glossary_random'); $this->content->footer = ''; return $this->content; }

            if (!has_capability('mod/glossary:view', get_context_instance(CONTEXT_MODULE, $cm->id))) { return ''; }

            </code>

            Show
            Allan Lee Mesina added a comment - This is also happening on our freshly installed Moodle 2.3.2 By looking at line 134 of the block_glossary_random.php, it tries to get the context_instance of a glossary. If the glossary has already been deleted, it will give out the error. Starting at line 138 is a code that should prevent the error. This is a simple logic that has been missed by the programmer. This should be changed so that the check is done prior to calling for a context_instance. In my attempt to resolve this issue, I managed to get rid of the error by changing the order of the if statements starting at line 134. Change lines 134 through 148 from <code> if (!has_capability('mod/glossary:view', get_context_instance(CONTEXT_MODULE, $cm->id))) { return ''; } if (!isset($modinfo->instances ['glossary'] [$glossaryid] )) { // we can get here if the glossary has been deleted, so // unconfigure the glossary from the block.. $this->config->glossary = 0; $this->config->cache = ''; $this->instance_config_commit(); $this->content->text = get_string('notyetconfigured','block_glossary_random'); $this->content->footer = ''; return $this->content; } </code> to <code> if (!isset($modinfo->instances ['glossary'] [$glossaryid] )) { // we can get here if the glossary has been deleted, so // unconfigure the glossary from the block.. $this->config->glossary = 0; $this->config->cache = ''; $this->instance_config_commit(); $this->content->text = get_string('notyetconfigured','block_glossary_random'); $this->content->footer = ''; return $this->content; } if (!has_capability('mod/glossary:view', get_context_instance(CONTEXT_MODULE, $cm->id))) { return ''; } </code>
            Hide
            Jozas Nhial added a comment -

            We solved the issue deleting the block in the database. In case anyone runs into this problem:
            select * from mdl_context where instanceid=COURSEID;
            (From the output read the ID of the table with depth 3, which will assume the value of CONTEXTID in the next select);
            select * from mdl_block_instances where parentcontextid=CONTEXTID and blockname="glossary_random";
            Check the ID of the block you want to delete (IDBLOCKINSTANCES). Then, after backuping up everything:
            delete from mdl_block_instances where id=IDBLOCKINSTANCES

            Show
            Jozas Nhial added a comment - We solved the issue deleting the block in the database. In case anyone runs into this problem: select * from mdl_context where instanceid=COURSEID; (From the output read the ID of the table with depth 3, which will assume the value of CONTEXTID in the next select); select * from mdl_block_instances where parentcontextid=CONTEXTID and blockname="glossary_random"; Check the ID of the block you want to delete (IDBLOCKINSTANCES). Then, after backuping up everything: delete from mdl_block_instances where id=IDBLOCKINSTANCES
            Hide
            Jason Fowler added a comment -

            Thanks Andreas, I've just had a look at the code (this was pushed before I could set up the peer review) and it passes the requirements as best I can tell. I haven't tested the code or done any work on this at all.

            Show
            Jason Fowler added a comment - Thanks Andreas, I've just had a look at the code (this was pushed before I could set up the peer review) and it passes the requirements as best I can tell. I haven't tested the code or done any work on this at all.
            Hide
            Dan Poltawski added a comment -

            Makes sense, thanks guys, i've integrated this now.

            Show
            Dan Poltawski added a comment - Makes sense, thanks guys, i've integrated this now.
            Hide
            Rossiani Wijaya added a comment -

            This is working as expected.

            However, after deleting the glossary activity, strict standards warning appears. I created MDL-36737 to fix the warning.

            Test passed.

            Show
            Rossiani Wijaya added a comment - This is working as expected. However, after deleting the glossary activity, strict standards warning appears. I created MDL-36737 to fix the warning. Test passed.
            Hide
            Dan Poltawski added a comment -

            Congratulations! Another bug solved.. only another 7330 to go, thanks for contributing to contributing to 0.8% of all bugs being fixed this week!

            ciao
            Dan

            Show
            Dan Poltawski added a comment - Congratulations! Another bug solved.. only another 7330 to go, thanks for contributing to contributing to 0.8% of all bugs being fixed this week! ciao Dan

              People

              • Votes:
                5 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: