Moodle
  1. Moodle
  2. MDL-28180

If you duplicate an assignment in Moodle 2.1 that has course completion enabled, it breaks course completion for the course

    Details

    • Database:
      MySQL
    • Testing Instructions:
      Hide

      IMPORTANT: Testing this requires git-abilities in order to switch of branch and/or apply patches.

      IMPORTANT: This needs to be tested on all 2.x branches and master, so all the steps below are for each branch:

      1) BEFORE applying the patch, create one course, with course completion enabled.

      2) Add 1-2 students to it.

      3) create one activity (any is ok), for example one "page" and define activity completion to require viewing the resource.

      4) define course completion to include the page resource just created.

      5) logged as student, view the page.

      6) TEST: As admin, look to the course-completion report and verify that the student appears to have completed the page resource.

      7) Backup the course, with users and all activities.

      8) duplicate the activity (x2 icon). Should end ok. (Note, in 20_STABLE where the duplication feature was not available you can go to the page resource and then perform one backup & restore of that activity. It's 100% equivalent).

      9) TEST: go to the completion report. Error happens.

      10) TEST: Go to the DB, look the course_completion_aggr_methd table, some records for the course are duplicated.

      11) SWITCH to branch having the patch applied OR apply it for the current branch.

      12) Go to site main page. Upgrade process should be ignited.

      13) TEST: The upgrade process ends without error.

      14) TEST: Go to the DB, look the course_completion_aggr_methd table, the duplicate records in 10) are out.

      15) TEST: go to the completion report. No error happens.

      16) Duplicate the page resource again.

      17) TEST: go to the completion report. No error happens.

      18) TEST: The completion report continues showing only one page resource.

      19) Restore the course backup created in 7) restoring onto current course and adding information.

      20) TEST: The restore ends without problem

      21) TEST: go to the completion report. No error happens.

      22) TEST: In the completion report now there are 2 page resources shown, both with the student in 5) being shown as completed.

      Show
      IMPORTANT: Testing this requires git-abilities in order to switch of branch and/or apply patches. IMPORTANT: This needs to be tested on all 2.x branches and master, so all the steps below are for each branch: 1) BEFORE applying the patch, create one course, with course completion enabled. 2) Add 1-2 students to it. 3) create one activity (any is ok), for example one "page" and define activity completion to require viewing the resource. 4) define course completion to include the page resource just created. 5) logged as student, view the page. 6) TEST: As admin, look to the course-completion report and verify that the student appears to have completed the page resource. 7) Backup the course, with users and all activities. 8) duplicate the activity (x2 icon). Should end ok. (Note, in 20_STABLE where the duplication feature was not available you can go to the page resource and then perform one backup & restore of that activity. It's 100% equivalent). 9) TEST: go to the completion report. Error happens. 10) TEST: Go to the DB, look the course_completion_aggr_methd table, some records for the course are duplicated. 11) SWITCH to branch having the patch applied OR apply it for the current branch. 12) Go to site main page. Upgrade process should be ignited. 13) TEST: The upgrade process ends without error. 14) TEST: Go to the DB, look the course_completion_aggr_methd table, the duplicate records in 10) are out. 15) TEST: go to the completion report. No error happens. 16) Duplicate the page resource again. 17) TEST: go to the completion report. No error happens. 18) TEST: The completion report continues showing only one page resource. 19) Restore the course backup created in 7) restoring onto current course and adding information. 20) TEST: The restore ends without problem 21) TEST: go to the completion report. No error happens. 22) TEST: In the completion report now there are 2 page resources shown, both with the student in 5) being shown as completed.
    • Workaround:
      Hide

      Go to the database and manually delete all the duplicate entries in the tables mdl_course_completion_aggr_methd and mdl_course_completion_criteria associated with the course that has the problem. This fixes the issue.

      Show
      Go to the database and manually delete all the duplicate entries in the tables mdl_course_completion_aggr_methd and mdl_course_completion_criteria associated with the course that has the problem. This fixes the issue.
    • Affected Branches:
      MOODLE_21_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      17795

      Description

      If you duplicate an assignment that has course completion enabled then course completion no longer works.
      If you then go to the course completion report, or the course completion settings you get the following errors.

      Found more than one record in fetch() !

      Debugging on

      More information about this error Stack trace:

      line 429 of /lib/setuplib.php: moodle_exception thrown

      line 130 of /lib/completion/data_object.php: call to print_error()

      line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper()

      line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch()

      line 374 of /lib/completionlib.php: call to data_object->__construct()

      line 65 of /course/completion_form.php: call to completion_info->get_aggregation_method()

      line 152 of /lib/formslib.php: call to course_completion_form->definition()

      line 73 of /course/completion.php: call to moodleform->moodleform()

      The table mdl_course_completion_aggr_methd is then populated with 1000's of records relating to the course with the issue. Only fix is to delete these records. Then all works fine.

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          Thanks for reporting this.

          I've put it on our backlog and we'll try to get to it as soon as we can.

          In the meantime adding more information, such as screenshots or even a code solution, will help us and other users.

          Show
          Michael de Raadt added a comment - Thanks for reporting this. I've put it on our backlog and we'll try to get to it as soon as we can. In the meantime adding more information, such as screenshots or even a code solution, will help us and other users.
          Hide
          Sam Marshall added a comment -

          Just to note: to judge by the description and the tables involved, I think this problem is related to course completion rather than activity completion - so removing activity completion from list and reassigning.

          Show
          Sam Marshall added a comment - Just to note: to judge by the description and the tables involved, I think this problem is related to course completion rather than activity completion - so removing activity completion from list and reassigning.
          Hide
          Richard Ackland added a comment -

          Just to add, there are more serious issues with this bug.
          If you duplicate ANY activity when course completion is enabled the error occurs and one is unable to access the course completion report or settings. In addition, a NON admin (e.g a student) gets locked out of the course completely and just gets the moodle database error screen with the message

          Found more than one record in fetch() !.

          The only way back in is to remove the extra rows from the table
          mdl_course_completion_aggr_methd
          that are created

          (and it created loads - sometimes 1000's)

          Show
          Richard Ackland added a comment - Just to add, there are more serious issues with this bug. If you duplicate ANY activity when course completion is enabled the error occurs and one is unable to access the course completion report or settings. In addition, a NON admin (e.g a student) gets locked out of the course completely and just gets the moodle database error screen with the message Found more than one record in fetch() !. The only way back in is to remove the extra rows from the table mdl_course_completion_aggr_methd that are created (and it created loads - sometimes 1000's)
          Hide
          Aaron Barnes added a comment -

          Hi Richard,

          Thanks for the report - I'm having a look at this. Need to get my head around 2.0 backup/restore and activity duplication.

          Cheers,
          Aaron

          Show
          Aaron Barnes added a comment - Hi Richard, Thanks for the report - I'm having a look at this. Need to get my head around 2.0 backup/restore and activity duplication. Cheers, Aaron
          Hide
          Aaron Barnes added a comment -

          OK, this is an issue with backup/restore. When duplicating an activity, it performs a backup and restore of the activity into the same course.

          For some reason the backup/restore code is duplicating all the criteria and aggregation methods for the course when restoring!

          Will keep investigating.

          Show
          Aaron Barnes added a comment - OK, this is an issue with backup/restore. When duplicating an activity, it performs a backup and restore of the activity into the same course. For some reason the backup/restore code is duplicating all the criteria and aggregation methods for the course when restoring! Will keep investigating.
          Hide
          Aaron Barnes added a comment -

          Updated workaround to mention criteria table.

          Show
          Aaron Barnes added a comment - Updated workaround to mention criteria table.
          Hide
          Aaron Barnes added a comment -

          OK, looks like the course completion backup/restore code does not distinguish between a course and an activity backup.

          Show
          Aaron Barnes added a comment - OK, looks like the course completion backup/restore code does not distinguish between a course and an activity backup.
          Hide
          Aaron Barnes added a comment -

          Could someone with more knowledge of Backup and Restore please look into this for me?

          Show
          Aaron Barnes added a comment - Could someone with more knowledge of Backup and Restore please look into this for me?
          Hide
          Lewis Black added a comment -

          Are there any updates on this as I am experiencing the same issue.

          Thanks,

          Lewis

          Show
          Lewis Black added a comment - Are there any updates on this as I am experiencing the same issue. Thanks, Lewis
          Hide
          Lewis Black added a comment -

          Temporary fix that worked for me:

          In /backup/moodle2/restore_activity_task.class.php I commented out the following line (155):

          //$this->add_step(new restore_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));

          Show
          Lewis Black added a comment - Temporary fix that worked for me: In /backup/moodle2/restore_activity_task.class.php I commented out the following line (155): //$this->add_step(new restore_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));
          Hide
          Paul Vaughan added a comment - - edited

          This is a major concern for me/us as it's preventing backups from running.

          This is also causing a seperate issue as I was relying on last night's backups to gather more information for another Tracker issue. :/

          I have voted accordingly above and will encourage others to do the same.

          Edited to add: is it too much to ask that there might be a simple db query to 'undo' the damage which has been done? This would at least get our automated backups running again.

          Show
          Paul Vaughan added a comment - - edited This is a major concern for me/us as it's preventing backups from running. This is also causing a seperate issue as I was relying on last night's backups to gather more information for another Tracker issue. :/ I have voted accordingly above and will encourage others to do the same. Edited to add: is it too much to ask that there might be a simple db query to 'undo' the damage which has been done? This would at least get our automated backups running again.
          Hide
          Paul Vaughan added a comment -

          A couple of our users are unable to access a course, which throws the following very similar stack trace:

          Found more than one record in fetch() ! Stack trace:
          *line 429 of /lib/setuplib.php: moodle_exception thrown
          *line 130 of /lib/completion/data_object.php: call to print_error()
          *line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper()
          *line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch()
          *line 374 of /lib/completionlib.php: call to data_object->__construct()
          *line 208 of /blocks/completionstatus/block_completionstatus.php: call to completion_info->get_aggregation_method()
          *line 280 of /blocks/moodleblock.class.php: call to block_completionstatus->get_content()
          *line 232 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
          *line 924 of /lib/blocklib.php: call to block_base->get_content_for_output()
          *line 976 of /lib/blocklib.php: call to block_manager->create_block_contents()
          *line 349 of /lib/blocklib.php: call to block_manager->ensure_content_created()
          *line 7 of /theme/sdctwo/layout/general.php: call to block_manager->region_has_content()
          *line 654 of /lib/outputrenderers.php: call to include()
          *line 612 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
          *line ? of unknownfile: call to core_renderer->header()
          *line 1291 of /lib/setuplib.php: call to call_user_func_array()
          *line 196 of /course/view.php: call to bootstrap_renderer->__call()
          *line 196 of /course/view.php: call to bootstrap_renderer->header()

          What I did to fix this issue for a course known to suffer with this:

          Queried mdl_course_completion_aggr_methd.course for the id of the course, ordered by id. It was quite obvious that of the 8 rows returned, the 2nd four were duplicates of the first four. The data was exported as SQL (so it could be reimported in case of failure) and the duplicates removed. The user was then able to log in normally.

          Show
          Paul Vaughan added a comment - A couple of our users are unable to access a course, which throws the following very similar stack trace: Found more than one record in fetch() ! Stack trace: *line 429 of /lib/setuplib.php: moodle_exception thrown *line 130 of /lib/completion/data_object.php: call to print_error() *line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper() *line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch() *line 374 of /lib/completionlib.php: call to data_object->__construct() *line 208 of /blocks/completionstatus/block_completionstatus.php: call to completion_info->get_aggregation_method() *line 280 of /blocks/moodleblock.class.php: call to block_completionstatus->get_content() *line 232 of /blocks/moodleblock.class.php: call to block_base->formatted_contents() *line 924 of /lib/blocklib.php: call to block_base->get_content_for_output() *line 976 of /lib/blocklib.php: call to block_manager->create_block_contents() *line 349 of /lib/blocklib.php: call to block_manager->ensure_content_created() *line 7 of /theme/sdctwo/layout/general.php: call to block_manager->region_has_content() *line 654 of /lib/outputrenderers.php: call to include() *line 612 of /lib/outputrenderers.php: call to core_renderer->render_page_layout() *line ? of unknownfile: call to core_renderer->header() *line 1291 of /lib/setuplib.php: call to call_user_func_array() *line 196 of /course/view.php: call to bootstrap_renderer->__call() *line 196 of /course/view.php: call to bootstrap_renderer->header() What I did to fix this issue for a course known to suffer with this: Queried mdl_course_completion_aggr_methd.course for the id of the course, ordered by id. It was quite obvious that of the 8 rows returned, the 2nd four were duplicates of the first four. The data was exported as SQL (so it could be reimported in case of failure) and the duplicates removed. The user was then able to log in normally.
          Hide
          Evan Irving-Pease added a comment -

          Hi Paul,

          I've sucessfully used this query in MySQL to remove the duplicate course completion records:

          DELETE
          FROM  mdl_course_completions
          WHERE id IN (
              SELECT *
              FROM (
                  SELECT MAX(id)
                  FROM mdl_course_completions
                  GROUP BY userid, course
                  HAVING COUNT(id) > 1
              ) AS X
          );
          

          This will only clean up one set of duplicates, if you have more than one then you will need to run this query multiple times.

          Show
          Evan Irving-Pease added a comment - Hi Paul, I've sucessfully used this query in MySQL to remove the duplicate course completion records: DELETE FROM mdl_course_completions WHERE id IN ( SELECT * FROM ( SELECT MAX(id) FROM mdl_course_completions GROUP BY userid, course HAVING COUNT(id) > 1 ) AS X ); This will only clean up one set of duplicates, if you have more than one then you will need to run this query multiple times.
          Hide
          Paul Vaughan added a comment -

          Thanks for the query Evan, although I do make a point of not running delete queries on the production Moodle database unless *absolutely* necessary. Remember folks, always backup!!

          Show
          Paul Vaughan added a comment - Thanks for the query Evan, although I do make a point of not running delete queries on the production Moodle database unless * absolutely * necessary. Remember folks, always backup!!
          Hide
          Teresa Gibbison added a comment -

          I also think the course enrolment methods are duplicated. I came across this issue when I duplicated a label in a course with completion and later found that the enrolment methods are also duplicated although receive no error.

          Show
          Teresa Gibbison added a comment - I also think the course enrolment methods are duplicated. I came across this issue when I duplicated a label in a course with completion and later found that the enrolment methods are also duplicated although receive no error.
          Hide
          Paul Vaughan added a comment -

          Hi Teresa.

          That's an interesting comment, as we've seen duplicate 'self enrolment' methods appear for some courses,sometimes as many as ten, but had no idea why.

          I will have to dig deeper.

          Show
          Paul Vaughan added a comment - Hi Teresa. That's an interesting comment, as we've seen duplicate 'self enrolment' methods appear for some courses,sometimes as many as ten, but had no idea why. I will have to dig deeper.
          Hide
          Richard Ackland added a comment -

          Is there anyway to disable the duplicate assignment. We use course completion a lot so i don't want to disable that. However, A member of staff on a different course duplicated some assigments and labels and the resulting repeating rows, basically brought our site to a halt.

          Show
          Richard Ackland added a comment - Is there anyway to disable the duplicate assignment. We use course completion a lot so i don't want to disable that. However, A member of staff on a different course duplicated some assigments and labels and the resulting repeating rows, basically brought our site to a halt.
          Hide
          Chris Collman added a comment -

          I was trying to add activity completion retroactively to questionnaire activities. I have about 70 evaluations/questionnaires that I want a check mark to appear next to after they have been completed by receiving a grade. Some of these have been completed by students. My process was to enter the activity setting, ignore the warning about confusing students and change the setting. For the first 15 or so activities, I went back to the completion block and looked at the report after every one. In fact I used the report to get to the activities and update the settings. The column would fill with check marks and I would go on to the next one. Thought I was OK and proceeded to change the rest of the activities that I knew students had completed. Then I click on the report and got the fetch error.

          line 429 of /lib/setuplib.php: moodle_exception thrown
          line 130 of /lib/completion/data_object.php: call to print_error()
          line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper()
          line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch()
          line 374 of /lib/completionlib.php: call to data_object->__construct()
          line 385 of /course/report/completion/index.php: call to completion_info->get_aggregation_method()

          I am not sure what to look for in the mysql tables. This is a new server, With 3 courses and 1 that I am using this feature. So far nobody has screamed at me that they can not get into the course or are having issues....but the day is young.

          Any ideas. Moodle 2.1.1 (Build: 20110801)

          I will modify the delete script to see if there are any duplicate course completion records. Thanks Chris

          Show
          Chris Collman added a comment - I was trying to add activity completion retroactively to questionnaire activities. I have about 70 evaluations/questionnaires that I want a check mark to appear next to after they have been completed by receiving a grade. Some of these have been completed by students. My process was to enter the activity setting, ignore the warning about confusing students and change the setting. For the first 15 or so activities, I went back to the completion block and looked at the report after every one. In fact I used the report to get to the activities and update the settings. The column would fill with check marks and I would go on to the next one. Thought I was OK and proceeded to change the rest of the activities that I knew students had completed. Then I click on the report and got the fetch error. line 429 of /lib/setuplib.php: moodle_exception thrown line 130 of /lib/completion/data_object.php: call to print_error() line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper() line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch() line 374 of /lib/completionlib.php: call to data_object->__construct() line 385 of /course/report/completion/index.php: call to completion_info->get_aggregation_method() I am not sure what to look for in the mysql tables. This is a new server, With 3 courses and 1 that I am using this feature. So far nobody has screamed at me that they can not get into the course or are having issues....but the day is young. Any ideas. Moodle 2.1.1 (Build: 20110801) I will modify the delete script to see if there are any duplicate course completion records. Thanks Chris
          Hide
          Chris Collman added a comment -

          Sam please note: I think my error also has to do with the Course completion status block (which I refered to earlier) that gives me the fetch error.

          What is weird is that when I go to the Navigation menu >Reports > activity completion I see the data just fine. It is when I use the block that I have the fetch error. Just logged in as a few of my students while they were at lunch. I can see the checkmarks next to their completed Questionnaire activities. I hid the offending block.

          I am going to blame the Course completion status block. When I try an csv export from the block, the column header values do not come out in the first row. When I try an export usng the Reports>Activity completion, they appear. I like the Completion report view better because it puts the activity names vertically but the other puts them horizontally.

          Show
          Chris Collman added a comment - Sam please note: I think my error also has to do with the Course completion status block (which I refered to earlier) that gives me the fetch error. What is weird is that when I go to the Navigation menu >Reports > activity completion I see the data just fine. It is when I use the block that I have the fetch error. Just logged in as a few of my students while they were at lunch. I can see the checkmarks next to their completed Questionnaire activities. I hid the offending block. I am going to blame the Course completion status block. When I try an csv export from the block, the column header values do not come out in the first row. When I try an export usng the Reports>Activity completion, they appear. I like the Completion report view better because it puts the activity names vertically but the other puts them horizontally.
          Hide
          Chris Collman added a comment -

          OK, one is a
          moodle/course/report/completion/index.php?course= and the other is
          moodle/course/report/progress/index.php

          Show
          Chris Collman added a comment - OK, one is a moodle/course/report/completion/index.php?course= and the other is moodle/course/report/progress/index.php
          Hide
          Miriam Laidlaw added a comment -

          We have just come across this error.

          Course completion is enabled in the course, the Course Completion Status block was added, as well as the Self Completion block.

          A teacher then duplicated a label that had completion criteria, and got the message "completion/multipleselfcompletioncriteria" and were locked out of their course.

          I went back and changed the url so I could view the course settings page, disabled course completion, and was able to access the course again.

          However... even once I had removed the label in question, AS LONG AS THE SELF COMPLETION BLOCK was still on the page, the course would break again. If the self-completion block is removed, the course is fine.

          This is a serious error, as all it takes is a teacher to duplicate any resource or activity that has completion tracking, and they and everyone else is locked out of the course.

          Show
          Miriam Laidlaw added a comment - We have just come across this error. Course completion is enabled in the course, the Course Completion Status block was added, as well as the Self Completion block. A teacher then duplicated a label that had completion criteria, and got the message "completion/multipleselfcompletioncriteria" and were locked out of their course. I went back and changed the url so I could view the course settings page, disabled course completion, and was able to access the course again. However... even once I had removed the label in question, AS LONG AS THE SELF COMPLETION BLOCK was still on the page, the course would break again. If the self-completion block is removed, the course is fine. This is a serious error, as all it takes is a teacher to duplicate any resource or activity that has completion tracking, and they and everyone else is locked out of the course.
          Hide
          Peter Roberts added a comment -

          I suspect it breaks the CRON job as well -

          Starting the completion cron...
          !!! Found more than one record in fetch() ! !!!

          Any chance the CRON job for completion can be adapted to remove duplicates before it does anything else?

          Show
          Peter Roberts added a comment - I suspect it breaks the CRON job as well - Starting the completion cron... !!! Found more than one record in fetch() ! !!! Any chance the CRON job for completion can be adapted to remove duplicates before it does anything else?
          Hide
          Eloy Lafuente (stronk7) added a comment - - edited

          Hi,

          course completion backup and restore (B&R) was initially planned to work only when all activities in a course backup were being included in the backup. (see MDL-22254)

          Later, both 1-activity B&R and duplicate 1-activity (that's one automated B&R) were implemented and in those cases is where the conditions performed to see if "all activities" are being included are failing badly, so completion information is handled incorrectly.

          So the plan to fix this horrible problems is:

          1) Prevent saving (on backup) and loading (on restore) any course-completion information if the backup is not a complete course one.
          2) Add one upgrade step to all 2.x branches, detecting the duplicates in database and cleaning them.

          That should make everything to work ASAP as was originally planned.

          Once done... and working ok, we could try to handle that information activity by activity, so both the 1-activity B&R and the duplicate 1-activity tools will allow to handle that information properly. But that is something to discuss and implement into a different issue, feel free to create it and link to this if there is interest.

          So, for now, let's implement the 1) and 2) above and course completion will stop causing all the mess it's causing on non-course B&R.

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - - edited Hi, course completion backup and restore (B&R) was initially planned to work only when all activities in a course backup were being included in the backup. (see MDL-22254 ) Later, both 1-activity B&R and duplicate 1-activity (that's one automated B&R) were implemented and in those cases is where the conditions performed to see if "all activities" are being included are failing badly, so completion information is handled incorrectly. So the plan to fix this horrible problems is: 1) Prevent saving (on backup) and loading (on restore) any course-completion information if the backup is not a complete course one. 2) Add one upgrade step to all 2.x branches, detecting the duplicates in database and cleaning them. That should make everything to work ASAP as was originally planned. Once done... and working ok, we could try to handle that information activity by activity, so both the 1-activity B&R and the duplicate 1-activity tools will allow to handle that information properly. But that is something to discuss and implement into a different issue, feel free to create it and link to this if there is interest. So, for now, let's implement the 1) and 2) above and course completion will stop causing all the mess it's causing on non-course B&R. Ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Oki, I've cooked 3 commits, here they are, for the 22_STABLE branch:

          https://github.com/stronk7/moodle/compare/MOODLE_22_STABLE...MDL-28180_22

          • ff4a2dd : it just prevents any non-course backup/restore to be considered to include all the activities. That causes course-completion info to be skipped 100%. As commented above, this was the original plan and we are now sticky to it.
          • 9de9515 : upgrade code, simply clean any dupes in the aggr_methd table.
          • ed9c60f : Explicitly look for existing records before inserting a new one on restore. This is needed when restoring complete courses onto existing courses also having course-completion information.

          I've been discussing about these commits with Sam Hemelryk and it seems they are correct, so now we are just:

          A) Applying the same solution to all 2.x versions.
          B) Adding some testing instructions to check that everything goes ok before sending it upstream.
          C) Create one issue about to consider the creation of one unique index over the course and criteriatype columns in that table. Surely this is for future 2.3 and above so does not matter much here.

          And that's all. If, in the mean time, somebody can test the proposed branches (not on production servers, please!) it would be perfect.

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Oki, I've cooked 3 commits, here they are, for the 22_STABLE branch: https://github.com/stronk7/moodle/compare/MOODLE_22_STABLE...MDL-28180_22 ff4a2dd : it just prevents any non-course backup/restore to be considered to include all the activities. That causes course-completion info to be skipped 100%. As commented above, this was the original plan and we are now sticky to it. 9de9515 : upgrade code, simply clean any dupes in the aggr_methd table. ed9c60f : Explicitly look for existing records before inserting a new one on restore. This is needed when restoring complete courses onto existing courses also having course-completion information. I've been discussing about these commits with Sam Hemelryk and it seems they are correct, so now we are just: A) Applying the same solution to all 2.x versions. B) Adding some testing instructions to check that everything goes ok before sending it upstream. C) Create one issue about to consider the creation of one unique index over the course and criteriatype columns in that table. Surely this is for future 2.3 and above so does not matter much here. And that's all. If, in the mean time, somebody can test the proposed branches (not on production servers, please!) it would be perfect. Ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Added patches for all 2.x branches:

          Created issue about the possibility of creating one unique index: MDL-30692

          So, now, completing testing instructions and sending to integration. As said any feedback will be welcome.

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Added patches for all 2.x branches: https://github.com/stronk7/moodle/compare/MOODLE_20_STABLE...MDL-28180_20 https://github.com/stronk7/moodle/compare/MOODLE_21_STABLE...MDL-28180_21 https://github.com/stronk7/moodle/compare/MOODLE_22_STABLE...MDL-28180_22 https://github.com/stronk7/moodle/compare/master...MDL-28180 Created issue about the possibility of creating one unique index: MDL-30692 So, now, completing testing instructions and sending to integration. As said any feedback will be welcome. Ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Testing instructions completed, I hope they cover all the problematic situations detected and all the fixes applied. Sent to integration, ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Testing instructions completed, I hope they cover all the problematic situations detected and all the fixes applied. Sent to integration, ciao
          Hide
          Sam Hemelryk added a comment -

          Thanks Eloy - this has been integrated now

          Show
          Sam Hemelryk added a comment - Thanks Eloy - this has been integrated now
          Hide
          Michael de Raadt added a comment -

          Prior to testing: looks epic.

          Show
          Michael de Raadt added a comment - Prior to testing: looks epic.
          Hide
          Michael de Raadt added a comment -

          Just a note during testing: at step 18, the duplicate activity from step 8 remained in the completion report after the upgrade. The student completion data is not copied but the completion settings for the duplicated activity remain. I think this is the correct system behaviour, but it differs from the test instructions.

          Show
          Michael de Raadt added a comment - Just a note during testing: at step 18, the duplicate activity from step 8 remained in the completion report after the upgrade. The student completion data is not copied but the completion settings for the duplicated activity remain. I think this is the correct system behaviour, but it differs from the test instructions.
          Hide
          Michael de Raadt added a comment -

          Test result: Success! Behaviour was consistent across all 2.x branches.

          Show
          Michael de Raadt added a comment - Test result: Success! Behaviour was consistent across all 2.x branches.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Comment about testing note above: Yes, old code was duplicating course-completion data (step 8) but new code only handles that information if complete courses are being processed. Hence step 16 (duplicate, one 1-activity B&R) does not add any activity to course completion, but step 22 (complete course backup) does it.

          So, to clearly state it, only complete course backups and restores are now handling course completion data (as was planned originally @ MDL-22254).

          If people is interested about B&R handling that information activity by activity, it may be possible, but for sure it's something to develop separately (master) and only once stabilized and tested, we may consider backporting it. As I commented above, feel free to create a new issue about that.

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Comment about testing note above: Yes, old code was duplicating course-completion data (step 8) but new code only handles that information if complete courses are being processed. Hence step 16 (duplicate, one 1-activity B&R) does not add any activity to course completion, but step 22 (complete course backup) does it. So, to clearly state it, only complete course backups and restores are now handling course completion data (as was planned originally @ MDL-22254 ). If people is interested about B&R handling that information activity by activity, it may be possible, but for sure it's something to develop separately (master) and only once stabilized and tested, we may consider backporting it. As I commented above, feel free to create a new issue about that. Ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks!

          Now... disconnect, relax and enjoy the next days, yay!

          Closing...ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks! Now... disconnect, relax and enjoy the next days, yay! Closing...ciao
          Hide
          Alexander Kurakin added a comment -

          But this issue is still actual on my 2.2.1. Can I help?

          Show
          Alexander Kurakin added a comment - But this issue is still actual on my 2.2.1. Can I help?
          Hide
          Michael de Raadt added a comment -

          Hi, Kurkakin.

          If you are still experiencing a problem, then yes, please help by launching a new issue that describes the specific problem you are having.

          Show
          Michael de Raadt added a comment - Hi, Kurkakin. If you are still experiencing a problem, then yes, please help by launching a new issue that describes the specific problem you are having.
          Hide
          Mark Nelson added a comment -

          This fix only works temporarily, as soon as you edit a resource/activity on the course page the duplicated resources/activities are displayed.

          Show
          Mark Nelson added a comment - This fix only works temporarily, as soon as you edit a resource/activity on the course page the duplicated resources/activities are displayed.
          Hide
          Mark Nelson added a comment -

          Sorry, was this fix only to prevent future duplicates from occurring, or will it fix existing issues?

          Show
          Mark Nelson added a comment - Sorry, was this fix only to prevent future duplicates from occurring, or will it fix existing issues?
          Hide
          Michael de Raadt added a comment -

          From the testing I did, I thought the fix repaired existing duplicate entries in the DB and prevent future ones also.

          Could you launch a new issue, Mark?

          Show
          Michael de Raadt added a comment - From the testing I did, I thought the fix repaired existing duplicate entries in the DB and prevent future ones also. Could you launch a new issue, Mark?
          Hide
          wangd added a comment - - edited

          os: ubuntu x64 10.04 LTS
          version: Moodle 2.1.2+

          We had the same issue where teachers that duplicated assignments with course completion enabled would not be able to get into the 'Completion tracking' settings. It would return 'Found more than one record in fetch()' at that screen.

          We had duplication in several tables mdl_course_completion_*. The most egregious duplication occurred in mdl_course_completion_aggr_methd with millions of duplicated records. This seems like it was due to the /admin/cron.php job never finishing and subsequent scheduled running of the cron.php creating more and more duplication.

          While I manually cleaned up the duplicate records in mdl_course_completion_aggr_methd, I still received the 'Found more than one record in fetch()' in the 'Completion tracking' settings AND also when running the cron.php job.

          Next, I tried upgrading to 2.1.5+ in hopes that not only would it fix the bug but also clean up the duplicate entries but I still got the 'Found more than one record in fetch()' in both Completion tracking settings and when the cron.php job runs.

          The Completion tracking settings debug returned:

          Found more than one record in fetch() !
          More information about this error
          Stack trace:
          line 429 of /lib/setuplib.php: moodle_exception thrown
          line 130 of /lib/completion/data_object.php: call to print_error()
          line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper()
          line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch()
          line 374 of /lib/completionlib.php: call to data_object->__construct()
          line 65 of /course/completion_form.php: call to completion_info->get_aggregation_method()
          line 154 of /lib/formslib.php: call to course_completion_form->definition()
          line 73 of /course/completion.php: call to moodleform->moodleform()
          

          I tried using the sql select (only) part of the query in the previous post (http://tracker.moodle.org/browse/MDL-28180?focusedCommentId=126182&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-126182) but that didn't find any duplications since it focused on the mdl_course_completions table.

          What I finally found out was that the main duplication outside of the mdl_course_completion_aggr_methd table was the mdl_course_completion_criteria table. This table had several courses that had duplicate lines.

          In our case it was only 6 courses that had duplication, so I manually removed the duplicate entries. Once this was done, this fixed the problem.

          If you wanted to see which course numbers have duplicates you can do the following:

                  SELECT course, count(id)
                  FROM moodle.mdl_course_completion_criteria
                  GROUP BY course, criteriatype, module, moduleinstance, courseinstance, enrolperiod, timeend, gradepass, role
                  HAVING COUNT(id) > 1
          

          ADDENDUM:

          I just wanted to add that it seems like the 2.1.5+ update cleaned up duplication in all the mdl_course_completion_* tables except for the mdl_course_completion_criteria. FYI, I note this because in our production moodle install, I tried first cleaning up manually the mdl_course_completion_criteria table before installing the 2.1.5+ update and I still got the Found more than one record in fetch() in both Completion tracking setting and cron.php. Only with the cleanup and the 2.1.5+ update did we finally resolve the issue with the error.

          Show
          wangd added a comment - - edited os: ubuntu x64 10.04 LTS version: Moodle 2.1.2+ We had the same issue where teachers that duplicated assignments with course completion enabled would not be able to get into the 'Completion tracking' settings. It would return 'Found more than one record in fetch()' at that screen. We had duplication in several tables mdl_course_completion_*. The most egregious duplication occurred in mdl_course_completion_aggr_methd with millions of duplicated records. This seems like it was due to the /admin/cron.php job never finishing and subsequent scheduled running of the cron.php creating more and more duplication. While I manually cleaned up the duplicate records in mdl_course_completion_aggr_methd, I still received the 'Found more than one record in fetch()' in the 'Completion tracking' settings AND also when running the cron.php job. Next, I tried upgrading to 2.1.5+ in hopes that not only would it fix the bug but also clean up the duplicate entries but I still got the 'Found more than one record in fetch()' in both Completion tracking settings and when the cron.php job runs. The Completion tracking settings debug returned: Found more than one record in fetch() ! More information about this error Stack trace: line 429 of /lib/setuplib.php: moodle_exception thrown line 130 of /lib/completion/data_object.php: call to print_error() line 83 of /lib/completion/completion_aggregation.php: call to data_object::fetch_helper() line 65 of /lib/completion/data_object.php: call to completion_aggregation::fetch() line 374 of /lib/completionlib.php: call to data_object->__construct() line 65 of /course/completion_form.php: call to completion_info->get_aggregation_method() line 154 of /lib/formslib.php: call to course_completion_form->definition() line 73 of /course/completion.php: call to moodleform->moodleform() I tried using the sql select (only) part of the query in the previous post ( http://tracker.moodle.org/browse/MDL-28180?focusedCommentId=126182&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-126182 ) but that didn't find any duplications since it focused on the mdl_course_completions table. What I finally found out was that the main duplication outside of the mdl_course_completion_aggr_methd table was the mdl_course_completion_criteria table. This table had several courses that had duplicate lines. In our case it was only 6 courses that had duplication, so I manually removed the duplicate entries. Once this was done, this fixed the problem. If you wanted to see which course numbers have duplicates you can do the following: SELECT course, count(id) FROM moodle.mdl_course_completion_criteria GROUP BY course, criteriatype, module, moduleinstance, courseinstance, enrolperiod, timeend, gradepass, role HAVING COUNT(id) > 1 — ADDENDUM: I just wanted to add that it seems like the 2.1.5+ update cleaned up duplication in all the mdl_course_completion_* tables except for the mdl_course_completion_criteria. FYI, I note this because in our production moodle install, I tried first cleaning up manually the mdl_course_completion_criteria table before installing the 2.1.5+ update and I still got the Found more than one record in fetch() in both Completion tracking setting and cron.php. Only with the cleanup and the 2.1.5+ update did we finally resolve the issue with the error.

            People

            • Votes:
              35 Vote for this issue
              Watchers:
              32 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: