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

Delete quiz JSON error if question category deleted

XMLWordPrintable

      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);
      

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

            mudrd8mz David Mudrák (@mudrd8mz)
            mwebster Mark van Hoek
            Carlos Escobedo Carlos Escobedo
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            CiBoT CiBoT
            Votes:
            2 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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