MDL-61667 analytics: Remove duplicated capability checks
authorDavid Monllaó <davidm@moodle.com>
Mon, 1 Apr 2019 09:57:14 +0000 (11:57 +0200)
committerDavid Mudrák <david@moodle.com>
Mon, 1 Apr 2019 12:57:57 +0000 (14:57 +0200)
\core_analytics\model::create and \core_analytics\model::enable methods
are called from install/upgrade scripts. Therefore, they should not
include any capability check. Their capability checks are actually
redundant, as the user capabilities are already checked in the
entry-point scripts.

analytics/classes/model.php

index 5583535..c0da4c0 100644 (file)
@@ -346,8 +346,6 @@ class model {
                                   $timesplittingid = false, $processor = null) {
         global $USER, $DB;
 
-        \core_analytics\manager::check_can_manage_models();
-
         $indicatorclasses = self::indicator_classes($indicators);
 
         $now = time();
@@ -360,6 +358,10 @@ class model {
         $modelobj->timemodified = $now;
         $modelobj->usermodified = $USER->id;
 
+        if ($target->based_on_assumptions()) {
+            $modelobj->trained = 1;
+        }
+
         if ($timesplittingid) {
             if (!\core_analytics\manager::is_valid($timesplittingid, '\core_analytics\local\time_splitting\base')) {
                 throw new \moodle_exception('errorinvalidtimesplitting', 'analytics');
@@ -385,10 +387,6 @@ class model {
 
         $model = new static($modelobj);
 
-        if ($model->is_static()) {
-            $model->mark_as_trained();
-        }
-
         return $model;
     }
 
@@ -1059,8 +1057,6 @@ class model {
     public function enable($timesplittingid = false) {
         global $DB, $USER;
 
-        \core_analytics\manager::check_can_manage_models();
-
         $now = time();
 
         if ($timesplittingid && $timesplittingid !== $this->model->timesplitting) {