Postponed (maintainer needs more info)
Project:
Quiz
Version:
8.0.x-dev
Component:
Code - Other
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
11 Nov 2020 at 14:53 UTC
Updated:
27 Aug 2026 at 19:02 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dkmishra commentedComment #3
dkmishra commentedComment #4
djdevinThere's currently no migration, I recommend instead of a migration script, you write migrations that can be used with the Drupal 8 migrate system: https://www.drupal.org/docs/drupal-apis/migrate-api/writing-migrations-f...
Comment #5
dkmishra commentedHi @djdevin, thanks for the suggestion, I am trying to write migrations. Thank you!!
Comment #6
chris dartMy team has successfully built a migration for quiz questions. We have four migrations for the
quiz,quiz_answers,quiz_multichoice, andquiz_relationship. These all rely on custom source plugins that query the following tables in the D7 site:quizmigration relies on the D7quiz_node_properties. That's the simplest migration as the database columns match almost 1:1. The source plugin extends DrupalSqlBasequiz_answersmigration queries the D7quiz_multichoice_answerstable. But requires some magic to format theanswer,feedback_if_chosen,feedback_if_not_chosen, andscore_if_chosenproperties. in the prepareRow() method on the migration source plugin. That plugin extends DrupalSqlBasequiz_multichoicemigration uses a Source plugin that extends D7_node, so it doesn't extend the default node query, but does have a prepareRow method that has to get all the for multi choice properties array with a query toquiz_multichoice_propertiestable, an method to get the quiz properties using thequiz_node_propertiestable, and the answers array fromquiz_multichoice_answerstable.quiz_relationshipmigration uses a source plugin that extends DrupalSqlBase. It has a join of the D7nodetable with a leftJoin onquiz_node_relationship.I'd be happy to elaborate further if you need more guidance. Writing migrations is not easy, especially when you first get started. But once you get the hang of it, you begin to see how powerful, robust, and efficient it is.
Comment #7
djdevinThat seems really nice, could you submit a patch or merge request?
Comment #8
chris dartI have written a quiz result migration as well. This doesn't work quite right yet. I haven't determined how to migrate which random questions for a give quiz result were associated with a quiz and which ones weren't. The result pages shows all possible answers instead of just the ones the user actually saw.
The parent migration is
quiz_results. It relies on a custom source plugin that extends DrupalSqlBase and queries the D7 tablequiz_node_results. It's a pretty simple 1:1 relationship and uses amigration_lookupfor ourquiz.quidmigration (mentioned in the previous comment), and amigration_lookupfor theuidbased on ausermigration.The dependent
quiz_results_answersmigration also uses a source plugin that extends DrupalSqlBase. It has a more elaborate query that joinsquiz_node_results_answerstoquiz_multichoice_user_answerswhich is then joined toquiz_multichoice_user_answer_multito get theanswer_idI get all the answers, but the problem is that the quiz results page shows all the possible questions the user could have viewed instead of just the randomly selected ones they were actually offered. What is the error I'm making? What other table or value do I need to incorporate?
Comment #9
chris dartAre you thinking of a quiz_migrate submodule? I'm not sure how to convert my work into a part of the quiz module proper. I can attempt to create a submodule with the plugins and the migrate_plus.migration.*.yml files in a /config directory in the submodule. Is that the best approach?
Comment #10
brooke_heaton commented@chris-dart - I think a submodule with the configuration in a directory under /config/install would make sense. I'm currently needing to do a D7 to D8 migration and would be happy to help with this if you are able to push up a patch or Merge Request.
Comment #11
christian.wiedemann commented@chris-dart could you just post your migration yaml files (Maybe simple as zip). That would help us extreme. Thanks!
Comment #12
chris dartAttached is a "denatured" example of a quiz migration. There may be some elements that are assumed here (such as user migrations and other basic requirements before you start migrating). Some of the attached files would need to be in a module and others you can import directly (after editing) using the config import of your choice.
Comment #13
djdevinThanks! This could probably go directly into a module structured like https://git.drupalcode.org/project/course/-/tree/3.x/modules/course_migrate
By design, the templates should work as-is but are made to be copied into your own modules for any custom processing.
Comment #15
djdevinComment #16
deepak goyal commentedHi All, The quiz_relationship migration is not working anybody has any solution ?
Comment #19
gennadiy commentedHi guys,
Thank you for making this migration. Could someone please provide a bit of guidance as for how to use it?
1) what version of D7 quiz migration supports from, e.g. 7.x-5.7 or both, 7.x-4.x and 7.x-5.x;
2) will it migrate data to any version of D9 quiz, e.g. 6.x.x;
3) how to get quiz_migrate.zip, e.g. download/composer or drush;
4) how to copy and activate;
5) where to look for errors if any.
Thank you!
Comment #20
ram4nd commentedYou use it through https://www.drupal.org/project/migrate_upgrade
But the script is far from ready tough.
Comment #21
gennadiy commentedThank you ram4nd,
I'm not sure about your note - from the last commits I see it is more of migration plugin (to be used with the Drupal 8/9 migrate system) than migration script.
Can't find how to download entire zipped last version of it (from git.drupalcode.org) and if there are any specific requirements for use.
I'm hoping I can just copy those files into quiz 6.0.0-alpha7 file structure and run web based migration: http://d9.website.com/upgrade
Thanks
Comment #22
gennadiy commentedHow to use it?
More specifically:
1) what version of D7 quiz was installed that migration went successfully with? Was it quiz 7.x-5.7?
2) I assume that it should migrate data to any version of D9 quiz 6.x.x as it should have the same database schema;
3) for those who are not experienced with doing this kind of migrations how to do it exactly:
- where to get the latest version of plugin/script;
- how to use it exactly? what are the options and step-by-step instructions?
- where to look for errors if any.
We currently have quiz 7.x-4.0-rc11 installed with only used "Quiz Multichoice" and "True False." Migrating to D9.3.
Thank you!
Comment #23
somersoft commentedWhilst trying these changes, one of the migrations failed as this is the D7 table structure I am working with
And in web/modules/contrib/quiz/modules/quiz_migrate/src/Plugin/migrate/source/QuizResultsAnswers.php there is the line
->condition('result_id', $result_id);inneeds to be changed to
Comment #24
arjenk commented@somersoft: i agree, this should be changed. Although i think also some more changes to quiz_results_answers.yml are needed; not sure about the question_vid as a default value of 0 for vid will probably not find the question:
needs to be changed to
And QuizResultsAnswers.php. For example remove this:
And it needs support for other question types then multiple-choice.
Comment #25
arjenk commented@gennadiy
I consider to add the following text to a README.md; You do not need the zip file, but you must get the module from this merge request somehow and follow the instructions below. Hope this helps. 7.x-4.0-rc11 is not tested by me, it is possible that the database is changed since then, perhaps a migration first to 7.x-5.7 is an option? Maybe someone else has experience here?
Quiz Drupal 7 -> Drupal 8/9 migration
This modules supports migration of quizzes/questions and its user
responses from Drupal 7 to Drupal 9. So far only quiz Drupal version
7.x-5.7 is tested.
The remainder of this readme uses drush, it should in theory be possible to
perform the migration with migration_ui, but drush is preferred.
This module uses core migrate,
[migrate_tools](https://drupal.org/project/migrate_tools) and the
[migrate_plus](https://drupal.org/project/migrate_plus) module. For
installations see the project pages, in short:
```
composer require drupal/migrate_tools
composer require drupal/migrate_plus
drush en migrate, migrate_drupal, migrate_tools, migrate_plus, quiz_migrate
```
After installation the migration config files needs to installed. They locate in the
migrations/ directory.
```
drush config-import --partial --source=/web/modules/contrib/quiz/modules/quiz_migrate/migrations
```
Note: when this is moved to config/install, this step wont be nessecary as they will be installed with the module.
Running the migration
Before running the migration you have to setup the migration source, see ...
Run a `drush migrate-status --group=quizzes` to get a status what will be imported.
```
drush migrate-import --group=quizzes
```
This should migrate all quizzes with its questions. To also import the quizresults use
```
drush migrate-import --group=quiz_results
```
-- And, as noted earlier, this migration is not ready for production yet.
Comment #26
gennadiy commented@arjenk
Hi and thank you so much for providing these instructions, I will let you know if any issues arise.
Comment #27
gennadiy commented@arjenk
> You do not need the zip file, but you must get the module from this merge request somehow
- was able to download the module one file at the time by this url:
https://git.drupalcode.org/issue/quiz-3181926/-/tree/1124067b86ed73805b7...
Then followed your instructions and got all those quizzes and questions migrated successfully.
Thank you so very much for your help!
P.S. I got errors while migrating and then found out db for D7 was pointing to the original one with quiz 7.x-4.0-rc11. After changing it to the one with upgraded quiz 7.x-5.7 everything went well.
UPDATE 1:
- the migrated quizzes/questions are not in place of the nodes from D7 with the same node IDs like with most migrations, but as an additional data available from /admin/quiz/quizzes instead of content menu, so the links to take quizzes are different and need to be replaced;
- also results are not migrated properly as arjenk was cautioning about.
UPDATE 2:
- after removing these extra records from D7 db:
# remove anonymous results:
DELETE FROM quiz_node_results WHERE uid = 0;
# remove unfinished results:
DELETE FROM quiz_node_results WHERE time_end IS NULL
and replacing line 49 in QuizResultsAnswers.php (was getting an error 1054 Unknown column "result_id" in "where clause"):
- ->condition('result_id', $result_id);
+ ->condition('result_answer_id', $result_id);
results were migrated successfully - same number of records in db and verified a few in both D7 and D9.
Comment #28
gennadiy commentedHere is a zipped module from @arjenk - see previous post. All those files together - you need to unzip it into your \web\modules\contrib\quiz\modules\, then follow instructions from #25.
Comment #29
arjenk commentedThis now works for me, would be great if more people could use their testset to test the migration process.
Comment #30
bohemier commentedHere is a patch with a rebase of the above MR with the current 6.x-dev
Comment #31
somersoft commentedExample JSON to use the 'plain diff' link from the issue fork to patch the quiz package in a composer.json file with the "cweagans/composer-patches" package installed.
Comment #32
erwangel commentedInstallation with #31 and migration steps from #25 worked for me going from D7 to D10.
However I got some errors with quiz_results_answers. I had 189 items in d7_quiz_result which were all migrated, but only 1516 items from the 1869 processed by quiz_results_answers were migrated. Perhaps the non migrated items are unfinished quizzes but there is nothing in migrate:messages that could help to debug. Also while rolling back quiz_results_answers , I got this error:
The other problem I got is with custom fields (I have a media_field in D7 quiz and question nodes) and usual drupal node fields like published y/n, author/date display, promoted, comments, etc or fields added by modules like metatag (essential for SEO), Any idea how to migrate these fields ? It is impossible to recreate all them as they are not accessible by "Re-use an existing field" and not available in the "Create a new field" options list. But perhaps this is not a migration problem but a limitation of the new quiz module concept. In such case, it is preferable to go the old way with quizzes and questions as nodes rather than trying to recreate a whole distinct entity.
Comment #33
johngonole commentedJust a general comment. Is drupal quiz going to have a migration built in when updating from Drupal 7 to Drupal 8,9,10 ?
When is Drupal quiz 6.0 series expected to get out of alpha and beta testing?
Drupal 7 is end of life soon. Is their an ETA for a production release?
Comment #34
smustgrave commentedLets update for 7.0.x please
Comment #35
anaconda777 commentedWhat is the process of migrating custom fields? Do I need to modify the quiz_migrate module files or just the migrate files?
Comment #36
somersoft commented@anaconda777
If you need to migrate more fields in the fieldable content, then copy the migration configuration file, rename the file and id and add the fields. in the process mapping. The source plugin should add the registered fields to the row. For example code see Drupal\node\Plugin\migrate\source\d7\Node.
If not then copy the used source plugin class and extend the SQL query to add the field.
I have a module which has all the custom migration configuration files and plugins so it is a part of that.
Comment #37
smustgrave commentedWanted to ask if this was still desired with D12 coming out later this year?
Comment #38
anaconda777 commentedwould be useful for me, if it would work with D11
this patch does not
https://www.drupal.org/files/issues/2023-06-29/3181926-quiz-migrate.patch