{"id":1751,"date":"2012-08-29T15:44:35","date_gmt":"2012-08-29T15:44:35","guid":{"rendered":"http:\/\/blogs.sussex.ac.uk\/elearningteam\/?p=1751"},"modified":"2012-09-14T15:32:19","modified_gmt":"2012-09-14T15:32:19","slug":"improving-moodle-import-part-1-the-database-schema","status":"publish","type":"post","link":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/2012\/08\/29\/improving-moodle-import-part-1-the-database-schema\/","title":{"rendered":"Improving Moodle import. Part 1: the database schema"},"content":{"rendered":"<p>The Moodle import feature copies resources and activities (mods) from one to course to another. Unfortunately we found the import process rather unintuitive (although better in 2.3), and we wanted to improve its speed, reliability and ease of use.<\/p>\n<p>We found that the Moodle import is based on the Moodle backup feature. Moodle backups create external representations of courses as a zip. It&#8217;s great at keeping packaged archives of Moodle courses, and sharing them. However, incorporating backup into the import process meant\u00a0packaging mods into temporary zip archives and then unpackaging them again, even though all it really needs to do is copy a mod and associated files.<\/p>\n<p>We found that relying on Moodle&#8217;s backup wasn&#8217;t the most\u00a0efficient\u00a0method. \u00a0 Our new import isn&#8217;t based on the Moodle backup functionality and as a result is faster, more robust and easier to use. Unlike the standard Moodle import tool it is also able to copy files linked from html within mods.<\/p>\n<p>In this first of a trilogy of posts we&#8217;ll sketch out the database schema we are copying.<\/p>\n<h2>Database schema for generic course modules<\/h2>\n<p>The generic database schema for course mods looks like this:<\/p>\n<p style=\"text-align: center\">\n<p><a href=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/module_db_schema4.jpg\"><img loading=\"lazy\" class=\"alignleft size-large wp-image-1940\" title=\"module database schema\" src=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/module_db_schema4-600x395.jpg\" alt=\"\" width=\"600\" height=\"395\" srcset=\"https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/module_db_schema4-600x395.jpg 600w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/module_db_schema4-300x197.jpg 300w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/module_db_schema4.jpg 1899w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Some of the Moodle mods have no further data associated with them than this. Others only have user generated data which the import doesn&#8217;t need to copy.<\/p>\n<p>In our Moodle install mods with no further data\u00a0associated\u00a0with them include resources,\u00a0assignments, chat modules, journals, forums, wikis and labels.<\/p>\n<p>Some of the Moodle mods have subtables associated.<\/p>\n<p>For example the choice mods have an associated table with choice options, the database mods have an associated table with database fields, and the feedback mods have an associated table with feedback items.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/choice_db_shema.jpg\"><img loading=\"lazy\" class=\"size-large wp-image-1758 aligncenter\" title=\"choice database schema\" src=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/choice_db_shema-600x139.jpg\" alt=\"\" width=\"384\" height=\"89\" srcset=\"https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/choice_db_shema-600x139.jpg 600w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/choice_db_shema-300x69.jpg 300w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/choice_db_shema.jpg 1161w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/a><\/p>\n<p>The lesson mods have an associated table with lesson pages and these pages have an associated table with lesson answers.<\/p>\n<h2>Database schema for glossary modules<\/h2>\n<p>The glossary was the only mod where we decided it was important to import user data as these included glossary definitions added by the tutors and a glossary without definitions wouldn&#8217;t be worth importing. As a result the database schema was a little more complicated. Glossary mods have associated tables with glossary entries and categories and there is a linking table between entries and categories. Furthermore, entries have an\u00a0associated\u00a0table with aliases.<\/p>\n<h2>Database schema for quiz modules<\/h2>\n<p>By far the most complicated mod was the quiz. The quiz has associated tables quiz feedback and quiz question instances. Quiz question instances joins questions from a Moodle question bank. The questions are in categories which are associated with the quiz itself through the context table.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/quiz_db_schema5.jpg\"><img loading=\"lazy\" class=\"size-large wp-image-1823 aligncenter\" title=\"quiz_db_schema\" src=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/quiz_db_schema5-600x377.jpg\" alt=\"\" width=\"600\" height=\"377\" \/><\/a><\/p>\n<p>There are number of questions types all using their own database schema. Most\u00a0of the question types use the question answers table.<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/question_db_schema.jpg\"><img loading=\"lazy\" class=\"alignleft size-large wp-image-1938\" title=\"question database schema\" src=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/question_db_schema-600x1307.jpg\" alt=\"\" width=\"600\" height=\"1307\" srcset=\"https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/question_db_schema-600x1307.jpg 600w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/question_db_schema-300x653.jpg 300w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/question_db_schema.jpg 1500w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p style=\"text-align: left\">\n<p style=\"text-align: left\">There are a number of question types which randomly pick questions. The random short answer matching (slickly named!) picks any short answer question in the category that is not currently in use to make a matching question by pairing the question and answers of the short answer questions. \u00a0The random question will pick any question currently not in use in the quiz that is in the same category or a subcategory.<\/p>\n<p style=\"text-align: center\">\n<p style=\"text-align: center\"><a href=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/random_question_db_schema2.jpg\"><img loading=\"lazy\" class=\"size-large wp-image-1812 aligncenter\" title=\"random question database schema\" src=\"http:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/random_question_db_schema2-600x683.jpg\" alt=\"\" width=\"600\" height=\"683\" srcset=\"https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/random_question_db_schema2-600x683.jpg 600w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/random_question_db_schema2-300x341.jpg 300w, https:\/\/blogs.sussex.ac.uk\/elearningteam\/files\/2012\/08\/random_question_db_schema2.jpg 1500w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p style=\"text-align: left\">We hope this approach will be useful to others who have problems with import in moodle.<\/p>\n<p style=\"text-align: left\">In the next posts we will talk about the\u00a0unit testing we did to establish that import was working and finally\u00a0the Sussex import feature in its working form.<\/p>\n<p style=\"text-align: left\">As always, comments very welcome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Moodle import feature copies resources and activities (mods) from one to course to another. Unfortunately we found the import process rather unintuitive (although better in 2.3), and we wanted to improve its speed, reliability and ease of use. We found that the Moodle import is based on the Moodle backup feature. Moodle backups create [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[64],"tags":[187,191],"_links":{"self":[{"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/posts\/1751"}],"collection":[{"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/comments?post=1751"}],"version-history":[{"count":70,"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/posts\/1751\/revisions"}],"predecessor-version":[{"id":1852,"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/posts\/1751\/revisions\/1852"}],"wp:attachment":[{"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/media?parent=1751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/categories?post=1751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sussex.ac.uk\/elearningteam\/wp-json\/wp\/v2\/tags?post=1751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}