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

'course_delete_modules' adhoc task fails when inserting {files} record with duplicate 'pathnamehash' field

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 3.9, 3.9.14, 3.10.11, 3.11.7, 4.0.1
    • Course, Tasks
    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
    • MDL-68774-master
    • Hide

      .

      Before applying the patch

      1. Ensure Course Recycle Bin is turned on:

        php admin/cli/cfg.php --component='tool_recyclebin' --name='coursebinenable' --set='1'
        

      2. Disable cron:

        php admin/cli/cfg.php --name='cron_enabled' --set='0'
        

      3. Create a new course, "My Course", short name "c1".
      4. Add a Quiz module "Quiz Original" in "Topic 1"
      5. Add a new Question, True-False, called "Dog: Cute or Not" with an image of a dog embedded in the question text section. Upload an image file and put it into the question textbox. Make sure the Category of the Question in "Default for c1".
      6. Add another new Question, True-False, called "Cat: Cute or Not" with an image of a cat embedded in the question text section. Upload an image  file and put it into the question textbox. Make sure the Category of  the Question in "Default for c1".
      7. Create another Quiz module "Quiz Recycling".
      8. In "Quiz Recycling", add question both questions from Question bank. (both the "Dog: Cute or Not" and the "Cat: Cute or Not" Questions).
      9. Execute the following command export the record associated with the dog image for the question:

        bash export.sh
        

      10. In the Question Bank for "Quiz Original", move the "Dog: Cute or Not" question to the "Default for Quiz Original" Question Category.
      11. Execute the following command to import the CSV record back into the mdl_files table:

        bash import.sh
        

      12. Confirm that the database table now has a record in both the "Quiz 1" context and the "My Course" context:

        moodle=# SELECT f.id, f.filename, f.component, f.filearea, f.contextid, c.contextlevel, c.instanceid FROM mdl_files f, mdl_context c WHERE c.id = f.contextid AND f.filename = 'dog-image.jpg' AND f.component = 'question' AND f.filearea = 'questiontext';
          id  |   filename    | component |   filearea   | contextid | contextlevel | instanceid 
        ------+---------------+-----------+--------------+-----------+--------------+------------
         4347 | dog-image.jpg | question  | questiontext |        52 |           50 |          6
         4353 | dog-image.jpg | question  | questiontext |        54 |           70 |         19
        (2 rows)
        

        where 6 is a course id and 19 is activity module id for "Quiz Original".

      13. Access "My Course" course page, click on "Edit" next to "Quiz Original" and delete "Quiz Original".
      14. Run the command from CLI:

        php admin/cli/adhoc_task.php --execute --force
        

      15. Confirm, that course_delete_modules adhoc task failed.
      16. Execute the following query:

        SELECT * FROM mdl_task_adhoc WHERE classname LIKE '%course_delete_modules%';
        

      17. Confirm, that the adhoc task remains with non-zero faildelay.

      After applying the patch

      1. Run the command from CLI:

        php admin/cli/adhoc_task.php --execute --force
        

      2. Confirm, that course_delete_modules adhoc task completes successfully.
      3. Execute the following query:

        SELECT * FROM mdl_task_adhoc WHERE classname LIKE '%course_delete_modules%';
        

      4. Confirm, that the adhoc task has gone.
      Show
      . Before applying the patch Ensure Course Recycle Bin is turned on: php admin/cli/cfg.php --component= 'tool_recyclebin' --name= 'coursebinenable' --set= '1' Disable cron: php admin/cli/cfg.php --name= 'cron_enabled' --set= '0' Create a new course, "My Course", short name "c1". Add a Quiz module "Quiz Original" in "Topic 1" Add a new Question, True-False, called "Dog: Cute or Not" with an image of a dog embedded in the question text section. Upload an image file and put it into the question textbox. Make sure the Category of the Question in "Default for c1". Add another new Question, True-False, called "Cat: Cute or Not" with an image of a cat embedded in the question text section. Upload an image  file and put it into the question textbox. Make sure the Category of  the Question in "Default for c1". Create another Quiz module "Quiz Recycling". In "Quiz Recycling", add question both questions from Question bank. (both the "Dog: Cute or Not" and the "Cat: Cute or Not" Questions). Execute the following command export the record associated with the dog image for the question: bash export.sh In the Question Bank for "Quiz Original", move the "Dog: Cute or Not" question to the "Default for Quiz Original" Question Category. Execute the following command to import the CSV record back into the mdl_files table: bash import .sh Confirm that the database table now has a record in both the "Quiz 1" context and the "My Course" context: moodle=# SELECT f.id, f.filename, f.component, f.filearea, f.contextid, c.contextlevel, c.instanceid FROM mdl_files f, mdl_context c WHERE c.id = f.contextid AND f.filename = 'dog-image.jpg' AND f.component = 'question' AND f.filearea = 'questiontext' ; id | filename | component | filearea | contextid | contextlevel | instanceid ------+---------------+-----------+--------------+-----------+--------------+------------ 4347 | dog-image.jpg | question | questiontext | 52 | 50 | 6 4353 | dog-image.jpg | question | questiontext | 54 | 70 | 19 ( 2 rows) where 6 is a course id and 19 is activity module id for "Quiz Original". Access "My Course" course page, click on "Edit" next to "Quiz Original" and delete "Quiz Original". Run the command from CLI: php admin/cli/adhoc_task.php --execute --force Confirm , that course_delete_modules adhoc task failed. Execute the following query: SELECT * FROM mdl_task_adhoc WHERE classname LIKE '%course_delete_modules%' ; Confirm , that the adhoc task remains with non-zero faildelay. After applying the patch Run the command from CLI: php admin/cli/adhoc_task.php --execute --force Confirm , that course_delete_modules adhoc task completes successfully. Execute the following query: SELECT * FROM mdl_task_adhoc WHERE classname LIKE '%course_delete_modules%' ; Confirm , that the adhoc task has gone.

      Another class of adhoc tasks which seem to get stuck and then get recycled for ever:

      core_course\task\course_delete_modules,Coding error detected, it must be fixed by a programmer: The course module 6634253 could not be deleted. #0 /var/www/site/lib/dml/moodle_database.php(1538): moodle_database->get_record_select('course_modules', 'WHERE id = ?', Array, 'id,course', 2)

      To reproduce:

      1. course, with 2 quizzes and 2 questions with images in the question textbox.
      2. Note: the second quiz should have used the questions from the first quiz via the question bank
      3. Then export to CSV file the mdl_files record associated with the image q1.
      4. Move the q1's question bank category to the Quiz level Question Category.
      5. Re-insert the mdl_files record back in (to fudge the unexpected file record which occasionally occurs in the wild)
      6. Delete the first Quiz
      7. Run the cron to execute the course_module_delete adhoc task

      At point (6), an attempt will be made to (1) create a new file record at the course level context for the question being "saved" in the "Questions saved from ..." Question Category. But since the mdl_file record exists with the same pathnamehash value, it spits out an error.

      The Quiz is hidden from view and appears in the Recycle bin, yet the adhoc_task remains in the queue forever!

        1. cat-image.jpg
          cat-image.jpg
          30 kB
        2. check_adhoc_tasks.sh
          0.1 kB
        3. dog-image.jpg
          dog-image.jpg
          54 kB
        4. export.sh
          0.2 kB
        5. import.sh
          0.3 kB

            brendanheywood Brendan Heywood
            brendanheywood Brendan Heywood
            Misha Golenkov Misha Golenkov
            Jun Pataleta Jun Pataleta
            Votes:
            7 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h

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