Merge branch 'MDL-77417_400' of https://github.com/stronk7/moodle into MOODLE_400_STABLE
[moodle.git] / question / upgrade.txt
blob61090bed1e2cd2d4382c401880061d813e89316e
1 This files describes API changes for code that uses the question API.
3 === 4.0.5 ===
5 1) Question bank plugins can now define more than one bulk action. Therefore, plugin_features_base::get_bulk_actions has been
6    changed to return an array, rather than a single bulk action class. Please update the plugin_features class in your plugin if necessary.
8 === 4.0 ===
10 Moodle 4.0 included the results of a major project to re-work the question bank.
12 1) Database changes (as usual, all existing data is updated automatically).
13    * Previously there was a single {question} table. This has now been split into three to handle versionning questions:
14      - question              - This now has a row for each version of each question. Therefore, some of the metadata
15                                (e.g. category) is moved to the next table. However, data that defines how a question works
16                                is unchanged, so question type plugins will mostly keep working.
17      - question_bank_entries - Each question bank entry is a question that appears in the question bank, which can
18                                have many versions.
19      - question_versions     - This joins all the versions of a question in the {question} table to the
20                                {question_bank_entries} row they belong to.
21    * Also, how other parts of the code refer to questions they want to to has changed, to be managed by the core
22      API in two new tables.
23       - question_references -> Records where a specific question is used.
24       - question_set_references -> Records where groups of questions are used (for example random questions in quizzes).
25      As a result of this, data from the two quiz tables {quiz_slot} and {quiz_slot_tags} was moved to these new tables.
27 2) There is a new plugin type 'qbank' for adding features to the question bank. See question/bank/upgrade.txt.
29 3) Many previously core features have been moved into new plugins, meaning that many old functionsand classes in
30    lib/questionlib.php and other locations have been deprecated and moved:
31     * Moved to qbank_previewquestion:
32        - question_preview_url() is moved to qbank_previewquestion\helper::question_preview_url()
33        - question_preview_popup_params() is moved to qbank_previewquestion\helper::question_preview_popup_params()
34       the following were really part of the internal implementation of preview, so should not have been used elsewhere,
35       but they were also moved (from previewlib.php).
36        - restart_preview() => qbank_previewquestion\helper::restart_preview(),
37        - question_preview_form_url() => qbank_previewquestion\helper::question_preview_form_url(),
38        - question_preview_action_url() => qbank_previewquestion\helper::question_preview_action_url(),
39        - question_preview_question_pluginfile() => qbank_previewquestion\helper::question_preview_question_pluginfile(),
40        - class preview_options_form => 'qbank_previewquestion\form\preview_options_form',
41        - class question_preview_options => 'qbank_previewquestion\output\question_preview_options',
42     * Moved to qbank_managecategories:
43        - qbank_managecategories\helper::question_remove_stale_questions_from_category()
44        - flatten_category_tree() => qbank_managecategories\helper::flatten_category_tree()
45        - add_indented_names() => qbank_managecategories\helper::add_indented_names()
46        - question_category_select_menu() => qbank_managecategories\helper::question_category_select_menu()
47        - get_categories_for_contexts() => qbank_managecategories\helper::get_categories_for_contexts()
48        - question_category_options() => qbank_managecategories\helper::question_category_options()
49        - question_add_context_in_key() => qbank_managecategories\helper::question_add_context_in_key()
50        - question_fix_top_names() => qbank_managecategories\helper::question_fix_top_names()
51        - class category_form => qbank_managecategories\form\category_form
52        - class question_category_list => qbank_managecategories\question_category_list
53        - class question_category_list_item => 'bank_managecategories\question_category_list_item
54        - class question_category_object => qbank_managecategories\question_category_object
55        - class question_category_edit_form => qbank_managecategories\form\category_form
56        - class question_move_form => qbank_managecategories\form\question_move_form
57     * Moved to qbank_exporttoxml:
58        - question_get_export_single_question_url() -> qbank_exporttoxml\helper::question_get_export_single_question_url().
59     * Moved to qbank_exportquestions:
60        - class question_export_form => qbank_exportquestions\form\export_form
61        - class export_form => qbank_exportquestions\form\export_form
62     * Moved to qbank_importquestions:
63        - class question_import_form => qbank_importquestions\form\question_import_form
64     * Moved to qbank_tagquestion:
65        - submit_tags_form and associated external services for question tag,
66        - tags_form in question/type,
67        - core_question_output_fragment_tags_form() => /question/bank/qbank_tagquestion/lib.php.
69 4) The following functions in questionlib.php now using type hinting. So, if you call them with the wrong types,
70    you will now get fatal errors.
71     - is_latest()
72     - get_next_version()
73     - get_question_version()
74     - get_question_bank_entry()
75     - core_question_find_next_unused_idnumber()
76     - question_module_uses_questions()
77     - question_page_type_list()
78     - core_question_question_preview_pluginfile()
79     - question_rewrite_question_preview_urls()
80     - question_rewrite_question_urls()
81     - question_get_all_capabilities()
82     - question_get_question_capabilities()
83     - question_require_capability_on()
84     - question_has_capability_on()
85     - question_default_export_filename()
86     - get_import_export_formats()
87     - question_categorylist_parents()
88     - question_categorylist()
89     - question_make_default_categories()
90     - question_get_top_categories_for_contexts()
91     - sort_categories_by_tree()
92     - print_question_icon()
93     - question_sort_tags()
94     - _tidy_question()
95     - question_preload_questions()
96     - question_move_category_to_context()
97     - move_question_set_references()
98     - question_move_questions_to_category()
99     - idnumber_exist_in_question_category()
100     - question_move_question_tags_to_new_context()
101     - question_delete_activity()
102     - question_delete_course_category()
103     - question_delete_course()
104     - question_delete_context()
105     - question_delete_question()
106     - delete_question_bank_entry()
107     - question_category_in_use()
108     - question_category_delete_safe()
109     - question_context_has_any_questions()
110     - questions_in_use()
111     - question_save_qtype_order()
112     - question_reorder_qtypes()
114 5) Function question_hash() from questionlib.php is deprecated without replacement.
116 6) The following classes have been moved, to better follow Moodle's name-space usage rules:
117    'core_question\bank\action_column_base' => 'core_question\local\bank\action_column_base',
118    'core_question\bank\checkbox_column' => 'core_question\local\bank\checkbox_column',
119    'core_question\bank\column_base' => 'core_question\local\bank\column_base',
120    'core_question\bank\edit_menu_column' => 'core_question\local\bank\edit_menu_column',
121    'core_question\bank\menu_action_column_base' => 'core_question\local\bank\menu_action_column_base',
122    'core_question\bank\menuable_action' => 'core_question\local\bank\menuable_action',
123    'core_question\bank\random_question_loader' => 'core_question\local\bank\random_question_loader',
124    'core_question\bank\row_base' => 'core_question\local\bank\row_base',
125    'core_question\bank\view' => 'core_question\local\bank\view',
126    'core_question\bank\copy_action_column' => 'qbank_editquestion\copy_action_column',
127    'core_question\bank\edit_action_column' => 'qbank_editquestion\edit_action_column',
128    'core_question\bank\creator_name_column' => 'qbank_viewcreator\creator_name_column',
129    'core_question\bank\question_name_column' => 'qbank_viewquestionname\viewquestionname_column_helper',
130    'core_question\bank\question_name_idnumber_tags_column' => 'qbank_viewquestionname\question_name_idnumber_tags_column',
131    'core_question\bank\delete_action_column' => 'qbank_deletequestion\delete_action_column',
132    'core_question\bank\export_xml_action_column' => 'qbank_exporttoxml\export_xml_action_column',
133    'core_question\bank\preview_action_column' => 'qbank_previewquestion\preview_action_column',
134    'core_question\bank\question_text_row' => 'qbank_viewquestiontext\question_text_row',
135    'core_question\bank\question_type_column' => 'qbank_viewquestiontype\question_type_column',
136    'core_question\bank\tags_action_column' => 'qbank_tagquestion\tags_action_column',
137    'core_question\form\tags' => '\qbank_tagquestion\form\tags_form',
138    'core_question\output\qbank_chooser' => 'qbank_editquestion\qbank_chooser',
139    'core_question\output\qbank_chooser_item' => 'qbank_editquestion\qbank_chooser_item',
141 7) The Behat class for question-related steps has been renamed to behat_core_question
142     to match the expected naming convention. In the unlikely event that you are directly
143     referring to the behat_question class name (nothing in the standard Moodle code was)
144     then you will have to update your reference.
147 === 3.9 ===
149 1) For years, the ..._questions_in_use callback has been the right way for plugins to
150    tell the core question system if questions are required. Previously this callback
151    only worked in mods. Now it works in all plugins.
153    At the same time, if you are still relying on the legacy ..._question_list_instances
154    callback for this, you will now get a debugging warning telling you to upgrade.
156 2) Previously, the functions question_delete_activity, question_delete_course and
157    question_delete_course_category would echo output. This was not correct behaviour for
158    a low-level API function. Now, they no longer output. Related to this, the helper
159    function they use, question_delete_context, now always returns an empty array.
161    This probably won't acutally cause you any problems. However, you may previously
162    have had to add expectOutputRegex calls to your unit tests to avoid warnings about
163    risky tests. If you have done that, those tests will now fail until you delete that expectation.
166 === 3.8 ===
168 If you have customised the display of the question bank (using $CFG->questionbankcolumns)
169 then be aware that the default configuration has changed, and you may wish to make
170 equivalent changes in your customised version. The old column question_name_column
171 has been replaced by question_name_idnumber_tags_column. The old question_name_column
172 still exists, so it is safe to continue using it.
174 There is a new question bank column edit_menu_column which displays all actions
175 in a drop-down menu, instead of as separate icons. This is now used by default.
176 Specifically, it gathers all other columns which implement the new interface
177 menuable_action. If you have made a custom subclasses of action_column_base,
178 you probably want to implement the new interface. If your column is a simple action,
179 the easiest way to do this will be to subclass menu_action_column_base. If your action
180 is more complex, and does not follow the simple pattern that menu_action_column_base
181 uses, then you will need to implement menuable_action yourself. The commit for
182 MDL-66816 updates all the core action columns. Looking at that change should make
183 it clearly the changes you need to make to your columns.
186 === 3.7 ===
188 The code for the is_valid_number function that was duplicated in the
189 qtype_numerical and qtype_multianswer plugins in the qtype_numerical_edit_form
190 and qtype_multianswer_edit_form classes has been moved to a static function
191 in the qtype_numerical class of the qtype_numerical plugin.
193 The exportprocess function of the qformat_default class doesn't output a blank line
194 if the result of the writequestion function is null. This permit to qformat plugins
195 to ignore some questions without the need to overwrite this function.
197 * The question_preview_cron() has been deleted. Please use \core\task\question_cron_task::execute().
198 * The question_usage_statistics_cron() has been deleted. Please use \core\task\question_cron_task::execute().
199 * The method question_bank::cron() has been deleted, please use question related scheduled tasks.
201 === 3.5 ===
203 1) The question format exportprocess function now adds a
204    $checkcapabilities boolean to allow questions to be exported in
205    certain circumstances.
207 === 3.2 ===
209 1) The following renderers have been deprecated in favour of the renderable
210    core_question\output\qbank_chooser and associated render_* method.
211     * qbank_chooser
212     * qbank_chooser_types
213     * qbank_chooser_qtype
214     * qbank_chooser_title
216 === 3.1 ===
218 1) The argument $requirecourseid was removed from question_edit_setup() and
219    is no longer respected. The behaviour was found to be buggy and now throws
220    debugging notices if passed.
222 === 2.9 ===
224 1) Some functions in questionlib.php which were deprecated in the past have now
225    been deleted:
227    Deprecated since 2.1
228     * question_list_instances
229     * get_grade_options
230     * question_category_isused
231     * save_question_options
232     * question_get_real_state
234    Deprecated since 2.6
235     * question_rewrite_questiontext_preview_urls
236     * question_send_questiontext_file
237     * question_pluginfile no longer falls back to using the old
238       {$previewcomponent}_questiontext_preview_pluginfile callback if the new
239       {$previewcomponent}_question_preview_pluginfile callback is missing.
242 === 2.8 ===
244 1) This is just a warning that some methods of the question_engine_data_mapper
245    class have changed. All these methods are ones that you should not have been
246    calling directly from your code, so this should not cause any problems.
247    The changed methods are:
248     * insert_question_attempt
249     * insert_step_data
250     * update_question_attempt_step
253 === 2.7 ===
255 1)  Changes to class question_bank_view:
257     Filters, including $recurse and $showhidden, are now implemented as
258     pluggable \core_question\bank\search\condition classes.
260     Therefore $recurse and $showhidden are no longer passed to the following functions:
261         protected function display_options [deprecated, use display_options_form()]
262         protected function build_query_sql [deprecated, use build_query()]
264     protected function display_category_form() is deprecated. Use \core_question\bank\search\category_condition
266     protected function display_category_form_checkbox deprecated use html_writer::checkbox and separate JavaScript
268 To add filters, local plugins can now implement the function local_[pluginname]_get_question_bank_search_conditions,
270 2) To make columns available to question_bank_view, plugins can extend core_question\bank\column_base.
271    Users may choose to display additional columns by setting $CFG->questionbankcolumns to a comma-delimited list of columns.
273 3) The subsort separator has changed from _ to - in order to distinuguish subsorts vs frankenstyle component separators.
275 4) Because of the move to autoloading, $knowncolumntypes and known_field_types() are no longer used.
277 5) question_bank_column_base and it's derived classes have been namespaced to core_question\bank\column_base.
280 === 2.6 ===
282 1) Modules using the question bank MUST now declare their use of it with the xxx_supports()
283    flag FEATURE_USES_QUESTIONS. question_module_uses_questions() should be used to determine
284    if a module uses questions.
286 2) It is sometimes necessary to display bits of question content without having
287    and attempt (question_usage) in progress. Two examples of this are the option
288    in the question bank to display the questiontext, and in the quiz statistics
289    report, where it displays the question text above the report.
291    Previously, this display was done using a special method that only worked for
292    the question text, but which would not work for other parts of the question.
293    That old mechanism has been deprecated, and there is a new method that you
294    should use.
296    To display the question, replace calls to question_rewrite_questiontext_preview_urls
297    with calls to question_rewrite_question_preview_urls. Because the new function
298    is more flexibile, you have to pass more arguments.
300    To perform the necessary permission checks when the file is downloaded, you need
301    to implement the callback [component name]_question_preview_pluginfile.
302    (Previously you implemented [component name]_questiontext_preview_pluginfile.)
303    quiz_statistics_question_preview_pluginfile is an example of what to do.
305    question_send_questiontext_file has been deprecated. It is no longer necessary.
307    To ensure you are no longer using or defining any deprecated functions,
308    search for the regular expression:
309    question_rewrite_questiontext_preview_urls|_questiontext_preview_pluginfile|question_send_questiontext_file
311 3) The argument list for core_question_renderer::mark_summary has changed.
312    Please update your calls. (The most likely scenario for this is if you have
313    overridden core_question_renderer::info in your own renderer.) You need to
314    make a change like:
315    - $this->mark_summary($qa, $options);
316    + $this->mark_summary($qa, $behaviouroutput, $options);