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

Course modules Tag instances not deleted

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 3.11.11, 4.0.5
    • 3.9.14, 3.9.15, 3.10.11, 3.11.7, 3.11.10, 4.0.1, 4.0.4
    • Course, Tags
    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
    • MOODLE_311_STABLE, MOODLE_400_STABLE
    • Hide

      Setup, prior to MDL-75168 change/branch

      1. Log in as admin
      2. Create a new course (Course one)
      3. Edit course one Announcements forum activity
      4. Set Tags field to Cat, Dog and save
      5. Create a second new course (Course two)
      6. Edit course two Announcements forum activity
      7. Set Tags field to Fish, Monkey and save
      8. Navigate to Courses > Manage courses and categories in site administration
      9. Delete course one
      10. From a SQL console, execute the following (take care to correct database name/prefix):

        SELECT ti.*, ctx.id AS ctxid
        FROM moodle.m_tag_instance ti
        LEFT JOIN moodle.m_context ctx ON ctx.id = ti.contextid
        

      11. Note the ID of the orphaned tag instance rows (those where ctxid is null)

      Checkout MDL-75168 branch

      1. Run site upgrade
      2. Re-run the previous SQL query
      3. Confirm the two orphaned tag instance records have been deleted
      4. Confirm the non-orphaned tag instance records have not been deleted, make a note of each of their ID fields
      5. Navigate to Courses > Manage courses and categories in site administration
      6. Delete course two
      7. Re-run the previous SQL query
      8. Confirm the tag instances from the deleted course announcements forum have been deleted
      Show
      Setup, prior to MDL-75168 change/branch Log in as admin Create a new course ( Course one ) Edit course one Announcements forum activity Set Tags field to Cat, Dog and save Create a second new course ( Course two ) Edit course two Announcements forum activity Set Tags field to Fish, Monkey and save Navigate to Courses > Manage courses and categories in site administration Delete course one From a SQL console, execute the following (take care to correct database name/prefix): SELECT ti.*, ctx.id AS ctxid FROM moodle.m_tag_instance ti LEFT JOIN moodle.m_context ctx ON ctx.id = ti.contextid Note the ID of the orphaned tag instance rows (those where ctxid is null) Checkout MDL-75168 branch Run site upgrade Re-run the previous SQL query Confirm the two orphaned tag instance records have been deleted Confirm the non-orphaned tag instance records have not been deleted, make a note of each of their ID fields Navigate to Courses > Manage courses and categories in site administration Delete course two Re-run the previous SQL query Confirm the tag instances from the deleted course announcements forum have been deleted

      We noticed this as in cron \ core \ task \ tag_cron_task it breaks for a missing context.

      This is the message: "

      Scheduled task failed: Elaborazione in background: tag (core\task\tag_cron_task),Non è possibile trovare il record nella tabella context. (SELECT * FROM {context} WHERE id = ?
      [array (
        0 => '2264205',
      )])
      Debug info:
      SELECT * FROM {context} WHERE id = ?
      [array (
        0 => '2264205',
      )]
      Backtrace:

      • line 1622 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
      • line 5353 of /lib/accesslib.php: call to moodle_database->get_record()
      • line 221 of /lib/classes/event/base.php: call to context::instance_by_id()
      • line 96 of /lib/classes/event/tag_removed.php: call to core\event\base::create()
      • line 268 of /lib/classes/task/tag_cron_task.php: call to core\event\tag_removed::create_from_tag_instance()
      • line 209 of /lib/classes/task/tag_cron_task.php: call to core\task\tag_cron_task->bulk_delete_instances()
      • line 51 of /lib/classes/task/tag_cron_task.php: call to core\task\tag_cron_task->cleanup()
      • line 253 of /lib/cronlib.php: call to core\task\tag_cron_task->execute()
      • line 167 of /admin/cli/scheduled_task.php: call to cron_run_inner_scheduled_task()

      "

      We have therefore realized that the primitive delete_course does not delete the instances tag of the activities but only deletes the tags at the course level.
      The cron is consequently broken because the instances tag of the activities no longer have context.
      To realize this, just:
      1. create a course
      2. create any activity
      3. add a tag
      4. cancel the course
      5. execute the following query on db: "SELECT ti.id FROM mdl_tag_instance ti left join mdl_context c on c.id = ti.contextid where c.id is null order by ti.id ASC "
      6. the result shows the context orphaned instances tags. If it helps I have seen that there is a primitive course_delete_module that also deletes the instances tag at the activity level by calling the function: "core_tag_tag :: remove_all_item_tags ('core', 'course_modules', $ cm-> id);"

        1. MDL-75168_master.png
          MDL-75168_master.png
          48 kB
        2. MDL-75168_v311.png
          MDL-75168_v311.png
          50 kB
        3. MDL-75168_v400.png
          MDL-75168_v400.png
          102 kB

            pholden Paul Holden
            atty1985 Attilio Ferrari
            Carlos Escobedo Carlos Escobedo
            Andrew Lyons Andrew Lyons
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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