From d0d65b498cf30d46db795ca716407426a5630f6d Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 16 Dec 2019 14:57:01 +0800 Subject: [PATCH] MDL-65835 plagiarism: Initial deprecation of old functions. This is the initial deprecation of: * plagiarism_save_form_elements * plagiarism_get_form_elements_module * plagiarism_plugin::get_form_elements_module * plagiarism_plugin::save_form_elements --- course/modlib.php | 2 ++ lib/plagiarismlib.php | 20 ++++++++++++++++++++ lib/upgrade.txt | 2 ++ mod/assign/mod_form.php | 2 +- mod/forum/mod_form.php | 1 + mod/workshop/mod_form.php | 1 + plagiarism/lib.php | 7 ++++++- plagiarism/upgrade.txt | 6 ++++++ 8 files changed, 39 insertions(+), 2 deletions(-) diff --git a/course/modlib.php b/course/modlib.php index c9e12408813..979e6cb453b 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -363,6 +363,8 @@ function edit_module_post_actions($moduleinfo, $course) { if ($hasgrades) { grade_regrade_final_grades($course->id); } + + // To be removed (deprecated) with MDL-67526 (both lines). require_once($CFG->libdir.'/plagiarismlib.php'); plagiarism_save_form_elements($moduleinfo); diff --git a/lib/plagiarismlib.php b/lib/plagiarismlib.php index 5f6207f96f0..26322503b87 100644 --- a/lib/plagiarismlib.php +++ b/lib/plagiarismlib.php @@ -81,6 +81,8 @@ function plagiarism_get_file_results($cmid, $userid, $file) { /** * saves/updates plagiarism settings from a modules config page - called by course/modedit.php * + * @deprecated Since Moodle 3.9. MDL-65835 Please use {plugin name}_coursemodule_edit_post_actions() instead. + * @todo MDL-67526 This is to be moved from here to deprecatedlib.php in Moodle 4.3 * @param object $data - form data */ function plagiarism_save_form_elements($data) { @@ -93,6 +95,14 @@ function plagiarism_save_form_elements($data) { require_once($dir.'/lib.php'); $plagiarismclass = "plagiarism_plugin_$plugin"; $plagiarismplugin = new $plagiarismclass; + + $reflectionmethod = new ReflectionMethod($plagiarismplugin, 'save_form_elements'); + if ($reflectionmethod->getDeclaringClass()->getName() == get_class($plagiarismplugin)) { + $text = 'plagiarism_plugin::save_form_elements() is deprecated.'; + $text .= ' Use plagiarism_' . $plugin . '_coursemodule_edit_post_actions() instead'; + debugging($text, DEBUG_DEVELOPER); + } + $plagiarismplugin->save_form_elements($data); } } @@ -100,6 +110,8 @@ function plagiarism_save_form_elements($data) { /** * adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism * + * @deprecated Since Moodle 3.9. MDL-65835 Please use {plugin name}_coursemodule_standard_elements() instead. + * @todo MDL-67526 This is to be moved from here to deprecatedlib.php in Moodle 4.3 * @param object $mform - Moodle form object * @param object $context - context object * @param string $modulename - Name of the module @@ -114,6 +126,14 @@ function plagiarism_get_form_elements_module($mform, $context, $modulename = "") require_once($dir.'/lib.php'); $plagiarismclass = "plagiarism_plugin_$plugin"; $plagiarismplugin = new $plagiarismclass; + + $reflectionmethod = new ReflectionMethod($plagiarismplugin, 'get_form_elements_module'); + if ($reflectionmethod->getDeclaringClass()->getName() == get_class($plagiarismplugin)) { + $text = 'plagiarism_plugin::get_form_elements_module() is deprecated.'; + $text .= ' Use plagiarism_' . $plugin . '_coursemodule_standard_elements() instead'; + debugging($text, DEBUG_DEVELOPER); + } + $plagiarismplugin->get_form_elements_module($mform, $context, $modulename); } } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 533b6c5929f..65cac74a973 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -9,6 +9,8 @@ information provided here is intended especially for developers. - question_is_only_toplevel_category_in_context * format_float() now accepts a special value (-1) as the $decimalpoints parameter which means auto-detecting number of decimal points. +* plagiarism_save_form_elements() has been deprecated. Please use {plugin name}_coursemodule_edit_post_actions() instead. +* plagiarism_get_form_elements_module() has been deprecated. Please use {plugin name}_coursemodule_standard_elements() instead. === 3.8 === * Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index bb20b268a1c..5494366ee77 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -186,7 +186,7 @@ class mod_assign_mod_form extends moodleform_mod { $mform->addElement('selectyesno', 'sendstudentnotifications', $name); $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign'); - // Plagiarism enabling form. + // Plagiarism enabling form. To be removed (deprecated) with MDL-67526. if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir . '/plagiarismlib.php'); plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign'); diff --git a/mod/forum/mod_form.php b/mod/forum/mod_form.php index 9f66da442e9..935f95aaebd 100644 --- a/mod/forum/mod_form.php +++ b/mod/forum/mod_form.php @@ -206,6 +206,7 @@ class mod_forum_mod_form extends moodleform_mod { $mform->hideIf('warnafter', 'blockperiod', 'eq', 0); $coursecontext = context_course::instance($COURSE->id); + // To be removed (deprecated) with MDL-67526. plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_forum'); //------------------------------------------------------------------------------- diff --git a/mod/workshop/mod_form.php b/mod/workshop/mod_form.php index a13766c1d06..db9a52eaaf6 100644 --- a/mod/workshop/mod_form.php +++ b/mod/workshop/mod_form.php @@ -249,6 +249,7 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true)); $coursecontext = context_course::instance($this->course->id); + // To be removed (deprecated) with MDL-67526. plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_workshop'); // Common module settings, Restrict availability, Activity completion etc. ---- diff --git a/plagiarism/lib.php b/plagiarism/lib.php index c86c5da34bb..364b05e82e0 100644 --- a/plagiarism/lib.php +++ b/plagiarism/lib.php @@ -71,13 +71,18 @@ abstract class plagiarism_plugin { } /** * hook to add plagiarism specific settings to a module settings page + * @deprecated Since Moodle 3.9. MDL-65835 Please use {plugin name}_coursemodule_edit_post_actions() instead. + * @todo MDL-67526 Remove this method. * @param object $mform - Moodle form * @param object $context - current context * @param string $modulename - Name of the module */ public function get_form_elements_module($mform, $context, $modulename = "") { } - /* hook to save plagiarism specific settings on a module settings page + /** + * hook to save plagiarism specific settings on a module settings page + * @deprecated Since Moodle 3.9. MDL-65835 Please use {plugin name}_coursemodule_standard_elements() instead. + * @todo MDL-67526 Remove this method. * @param object $data - data from an mform submission. */ public function save_form_elements($data) { diff --git a/plagiarism/upgrade.txt b/plagiarism/upgrade.txt index e43b51082e8..1a664b82479 100644 --- a/plagiarism/upgrade.txt +++ b/plagiarism/upgrade.txt @@ -1,4 +1,10 @@ This files describes API changes for code that uses the plagiarism API. + +=== 3.9 === + +* The method get_form_elements_module has been deprecated. Please use {plugin name}_coursemodule_edit_post_actions() instead. +* The method save_form_elements has been deprecated. Please use {plugin name}_coursemodule_standard_elements() instead. + === 3.7 === * The plagiarism_cron() function has been deleted, plugins should implement their own scheduled tasks.