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
          31 kB
          Paul L
        2. image-2019-06-12-09-41-57-097.png
          45 kB
          Paul L
        3. image-2019-06-12-09-44-30-571.png
          28 kB
          Paul L
        4. image-2020-01-03-10-42-11-092.png
          12 kB
          Henrik Sune Pedersen
        5. JSON error chrome.PNG
          80 kB
          Mark van Hoek
        6. JSON error firefox.PNG
          85 kB
          Mark van Hoek
        7. screenshot-1.png
          85 kB
          David Mudrák (@mudrd8mz)
        8. screenshot-2.png
          33 kB
          David Mudrák (@mudrd8mz)

        Issue Links

          Activity

            People

              mudrd8mz David Mudrák (@mudrd8mz)
              mwebster Mark van Hoek
              Carlos Escobedo Carlos Escobedo
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              CiBoT CiBoT
              Amaia Anabitarte, Carlos Escobedo, Laurent David, Mikel Martín Corrales, Sabina Abellan, Sara Arjona (@sarjona), Tim Hunt, Ilya Tregubov, Kevin Percy, Mathew May, Mihail Geshoski, Shamim Rezaie
              Votes:
              2 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                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