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

Delete quiz JSON error if question category deleted

    XMLWordPrintable

    Details

      Description

      If you delete a quiz activity with ajax enabled and it deletes the question category, the ajax response incorrectly includes HTML feedback

      /lib/ajax/service.php?sesskey=blahblah&info=core_course_edit_module

      <table class="generaltable">
      <thead>
      <tr>
      <th class="header c0" style="" scope="col">Category</th>
      <th class="header c1 lastcol" style="" scope="col">Action</th>
      </tr>
      </thead>
      <tbody><tr class="lastrow">
      <td class="cell c0" style="">Default for Test Duplicate</td>
      <td class="cell c1 lastcol" style="">This category has been deleted because, after deleting the course, its questions weren't used any more.</td>
      </tr>
      </tbody>
      </table>
      [{"error":false,"data":""}]
      

      As expected, the on-screen error in Chrome is:

      SyntaxError: Unexpected token < in JSON at position 0
      

      The quiz is actually deleted as visible after a screen refresh, but the error is still causing confusion for instructors.

      I think the proper fix is to set the "not async" flag in the question_delete_activity() function call here to prevent feedback from being shown:

      course/lib.php::~1191

      function course_delete_module($cmid, $async = false) {
      ...
          // Delete activity context questions and question categories.
          question_delete_activity($cm, !$async);
      

        Attachments

        1. image-2019-06-12-09-41-27-361.png
          image-2019-06-12-09-41-27-361.png
          31 kB
        2. image-2019-06-12-09-41-57-097.png
          image-2019-06-12-09-41-57-097.png
          45 kB
        3. image-2019-06-12-09-44-30-571.png
          image-2019-06-12-09-44-30-571.png
          28 kB
        4. image-2020-01-03-10-42-11-092.png
          image-2020-01-03-10-42-11-092.png
          12 kB
        5. JSON error chrome.PNG
          JSON error chrome.PNG
          80 kB
        6. JSON error firefox.PNG
          JSON error firefox.PNG
          85 kB
        7. screenshot-1.png
          screenshot-1.png
          85 kB
        8. screenshot-2.png
          screenshot-2.png
          33 kB

          Issue Links

            Activity

              People

              Assignee:
              mudrd8mz David Mudrák (@mudrd8mz)
              Reporter:
              mwebster Mark van Hoek
              Peer reviewer:
              Carlos Escobedo
              Integrator:
              Eloy Lafuente (stronk7)
              Tester:
              CiBoT
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón, Tim Hunt, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              2 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Mar/20

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 1 hour, 15 minutes
                  1d 1h 15m