From 3b7c7918f3a4bb03e03816dba0df2506f33d6c3d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mudr=C3=A1k?= Date: Tue, 12 Mar 2019 08:50:47 +0100 Subject: [PATCH] MDL-61667 analytics: Deprecate the add_builtin_models() method The functionality of the \core_analytics\manager::add_builtin_models() method is to be replaced with automatic update of models provided by the core moodle component. There is no need to call this method explicitly any more. Instead, adding new models will be done by updating the lib/db/analytics.php file and bumping the core version. --- analytics/classes/manager.php | 78 +++------------------------------- analytics/tests/model_test.php | 8 ---- analytics/upgrade.txt | 4 ++ lib/db/install.php | 3 -- 4 files changed, 9 insertions(+), 84 deletions(-) diff --git a/analytics/classes/manager.php b/analytics/classes/manager.php index 415784122aa..9ee20f56527 100644 --- a/analytics/classes/manager.php +++ b/analytics/classes/manager.php @@ -507,84 +507,16 @@ class manager { } /** - * Adds the models included with moodle core to the system. + * Used to be used to add models included with the Moodle core. * + * @deprecated Deprecated since Moodle 3.7 (MDL-61667) - Use lib/db/analytics.php instead. + * @todo Remove this method in Moodle 4.1 (MDL-65186). * @return void */ public static function add_builtin_models() { - $target = self::get_target('\core\analytics\target\course_dropout'); - - // Community of inquiry indicators. - $coiindicators = array( - '\mod_assign\analytics\indicator\cognitive_depth', - '\mod_assign\analytics\indicator\social_breadth', - '\mod_book\analytics\indicator\cognitive_depth', - '\mod_book\analytics\indicator\social_breadth', - '\mod_chat\analytics\indicator\cognitive_depth', - '\mod_chat\analytics\indicator\social_breadth', - '\mod_choice\analytics\indicator\cognitive_depth', - '\mod_choice\analytics\indicator\social_breadth', - '\mod_data\analytics\indicator\cognitive_depth', - '\mod_data\analytics\indicator\social_breadth', - '\mod_feedback\analytics\indicator\cognitive_depth', - '\mod_feedback\analytics\indicator\social_breadth', - '\mod_folder\analytics\indicator\cognitive_depth', - '\mod_folder\analytics\indicator\social_breadth', - '\mod_forum\analytics\indicator\cognitive_depth', - '\mod_forum\analytics\indicator\social_breadth', - '\mod_glossary\analytics\indicator\cognitive_depth', - '\mod_glossary\analytics\indicator\social_breadth', - '\mod_imscp\analytics\indicator\cognitive_depth', - '\mod_imscp\analytics\indicator\social_breadth', - '\mod_label\analytics\indicator\cognitive_depth', - '\mod_label\analytics\indicator\social_breadth', - '\mod_lesson\analytics\indicator\cognitive_depth', - '\mod_lesson\analytics\indicator\social_breadth', - '\mod_lti\analytics\indicator\cognitive_depth', - '\mod_lti\analytics\indicator\social_breadth', - '\mod_page\analytics\indicator\cognitive_depth', - '\mod_page\analytics\indicator\social_breadth', - '\mod_quiz\analytics\indicator\cognitive_depth', - '\mod_quiz\analytics\indicator\social_breadth', - '\mod_resource\analytics\indicator\cognitive_depth', - '\mod_resource\analytics\indicator\social_breadth', - '\mod_scorm\analytics\indicator\cognitive_depth', - '\mod_scorm\analytics\indicator\social_breadth', - '\mod_survey\analytics\indicator\cognitive_depth', - '\mod_survey\analytics\indicator\social_breadth', - '\mod_url\analytics\indicator\cognitive_depth', - '\mod_url\analytics\indicator\social_breadth', - '\mod_wiki\analytics\indicator\cognitive_depth', - '\mod_wiki\analytics\indicator\social_breadth', - '\mod_workshop\analytics\indicator\cognitive_depth', - '\mod_workshop\analytics\indicator\social_breadth', - '\core_course\analytics\indicator\completion_enabled', - '\core_course\analytics\indicator\potential_cognitive_depth', - '\core_course\analytics\indicator\potential_social_breadth', - '\core\analytics\indicator\any_access_after_end', - '\core\analytics\indicator\any_access_before_start', - '\core\analytics\indicator\any_write_action_in_course', - '\core\analytics\indicator\read_actions', - ); - $indicators = array(); - foreach ($coiindicators as $coiindicator) { - $indicator = self::get_indicator($coiindicator); - $indicators[$indicator->get_id()] = $indicator; - } - if (!\core_analytics\model::exists($target, $indicators)) { - $model = \core_analytics\model::create($target, $indicators); - } - - // No teaching model. - $target = self::get_target('\core\analytics\target\no_teaching'); - $timesplittingmethod = '\core\analytics\time_splitting\single_range'; - $noteacher = self::get_indicator('\core_course\analytics\indicator\no_teacher'); - $nostudent = self::get_indicator('\core_course\analytics\indicator\no_student'); - $indicators = array($noteacher->get_id() => $noteacher, $nostudent->get_id() => $nostudent); - if (!\core_analytics\model::exists($target, $indicators)) { - \core_analytics\model::create($target, $indicators, $timesplittingmethod); - } + debugging('core_analytics\manager::add_builtin_models() has been deprecated. Core models are now automatically '. + 'updated according to their declaration in the lib/db/analytics.php file.', DEBUG_DEVELOPER); } /** diff --git a/analytics/tests/model_test.php b/analytics/tests/model_test.php index 2fc0fa97c06..8eaac08e786 100644 --- a/analytics/tests/model_test.php +++ b/analytics/tests/model_test.php @@ -272,14 +272,6 @@ class analytics_model_testcase extends advanced_testcase { public function test_exists() { $this->resetAfterTest(true); - global $DB; - - $count = $DB->count_records('analytics_models'); - - // No new models added if the builtin ones already exist. - \core_analytics\manager::add_builtin_models(); - $this->assertCount($count, $DB->get_records('analytics_models')); - $target = \core_analytics\manager::get_target('\core\analytics\target\no_teaching'); $this->assertTrue(\core_analytics\model::exists($target)); } diff --git a/analytics/upgrade.txt b/analytics/upgrade.txt index 31873651154..8d1932e3b0f 100644 --- a/analytics/upgrade.txt +++ b/analytics/upgrade.txt @@ -6,6 +6,10 @@ information provided here is intended especially for developers. * \core_analytics\regressor::evaluate_regression and \core_analytics\classifier::evaluate_classification have been updated to include a new $trainedmodeldir param. This new param will be used to evaluate the existing trained model. +* The method \core_analytics\manager::add_builtin_models() has been deprecated. The functionality + has been replaced with automatic update of models provided by the core moodle component. There + is no need to call this method explicitly any more. Instead, adding new models can be achieved + by updating the lib/db/analytics.php file and bumping the core version. === 3.5 === diff --git a/lib/db/install.php b/lib/db/install.php index ddf0aa26b9d..8719b1337d2 100644 --- a/lib/db/install.php +++ b/lib/db/install.php @@ -319,7 +319,4 @@ function xmldb_main_install() { require_once($CFG->libdir . '/db/upgradelib.php'); make_default_scale(); make_competence_scale(); - - // Add built-in prediction models. - \core_analytics\manager::add_builtin_models(); } -- 2.43.0