MDL-61667 analytics: Deprecate the add_builtin_models() method
authorDavid Mudrák <david@moodle.com>
Tue, 12 Mar 2019 07:50:47 +0000 (08:50 +0100)
committerDavid Mudrák <david@moodle.com>
Mon, 1 Apr 2019 12:23:06 +0000 (14:23 +0200)
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
analytics/tests/model_test.php
analytics/upgrade.txt
lib/db/install.php

index 4157841..9ee20f5 100644 (file)
@@ -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);
     }
 
     /**
index 2fc0fa9..8eaac08 100644 (file)
@@ -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));
     }
index 3187365..8d1932e 100644 (file)
@@ -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 ===
 
index ddf0aa2..8719b13 100644 (file)
@@ -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();
 }