Show
We need to test the upgrade process, so you'll need to revert the patch and its DB changes
Revert this patch. This will allow duplicate stamps to be created when moving question categories around after a restore.
Using your favourite DB tool, remove the unique index (contextid, stamp) from question_categories.
Setting up the courses and duplication of contextid, stamp
Create a new course under the 'Miscellaneous' category and navigate to course home
Create a new question category at course-level (Course admin > Question bank > Categories)
Under the 'Add category' form (bottom of page) set parent category to 'Top', under the bold section 'Course: YOUR COURSE NAME'
Enter a name and save
Confirm that you see the new question category listed under the section titles 'Question cateogories for course: YOUR COURSE NAME'
From the course admin menu select 'Question bank > Questions'
Select the category you just created from the list and click 'Create new question'
Click 'True/false'
Enter a name and description and click save changes
Click 'Question bank > Categories' from the course admin block
Confirm that* you see a'(1)' next to the category you just created, indicating that one question has been created within it.
Go to course home and add a quiz
Name it and click 'save and display'
Click 'Edit quiz' button to add questions
Click 'Add' and select 'a question from question bank'
Select the question category you created earlier and add the question by checking the box and clicking 'Add selected .. to quiz'
Confirm that you see the question listed
From the admin menu, select 'Course admin > Backup'
Backup the course, using all default settings (You can use 'Jump to final step')
When the backup finishes, click 'Continue'
Click the restore link to restore the course
Continue to restore as a new course, with category = 'Miscellaneous'. Change the name slightly so you can differentiate.
When the restore completes, click continue.
Now, using your preferred DB tool inspect the question_categories table.
For the category you created earlier, confirm that:
There are 2 entries
Both entries share the same stamp value
The 2 entries have different contextid values
Copy this stamp and remember it!
Leave your DB tool open
Now, in the original course you created, click 'Question bank > Categories'
Edit the category you created earlier and change its parent to 'Top' under the 'Category: Miscellaneous' header. Save.
Confirm that you see the category listed under the 'Question categories for category: Miscellaneous' section
Do the same for the restored course. You may wish to rename the category as you move it.
Now, back in your DB tool, refresh and confirm that:
There are still 2 records for the question category you created
Both records have the same stamp value
Both records have the same contextid
Again, leave the DB tool open
Testing the upgrade script
Apply the patch
Click 'dashboard' and run through the upgrade process
Confirm that the upgrade completes and that no errors/warnings are present.
Now, in your DB tool, Confirm that
There are still 2 records for the question category you created earlier
The record with the higher ID (from the restore) has a new stamp (compare it to the stamp you copied from the original earlier)
Both records have the same contextid
Testing the question category form changes:
Navigate back to the course home of the original course
Restore the course into a new course, make sure to change the name
Using your DB tool, Confirm that
You now see 3 entries for the question category you created earlier
The stamp of the newest record matches the stamp of the original, albeit in a different context.
Within the restored course move the question category from the course-level to the miscellaneous level, as before
Again, with your DB tool, confirm that
You now see 3 entries for the question category you created earlier
Of those 3, the stamp for the newest entry doesn't match the stamp of the original
The 2 entries share the same context id.