MDL-67038 analytics: Remove null strings from the DB
authorDavid Monllaó <davidm@moodle.com>
Mon, 28 Oct 2019 08:38:35 +0000 (16:38 +0800)
committerDavid Monllaó <davidm@moodle.com>
Wed, 30 Oct 2019 04:40:32 +0000 (12:40 +0800)
admin/tool/analytics/model.php
analytics/classes/model.php
lib/db/upgrade.php
version.php

index 6b7511b..ab9f304 100644 (file)
@@ -159,6 +159,10 @@ switch ($action) {
                 $predictionsprocessor = false;
             }
 
+            if (!isset($data->contexts)) {
+                $data->contexts = null;
+            }
+
             $model->update($data->enabled, $indicators, $timesplitting, $predictionsprocessor, $data->contexts);
             redirect($returnurl);
         }
index cc92516..9e484b1 100644 (file)
@@ -493,13 +493,15 @@ class model {
             $predictionsprocessor = $this->model->predictionsprocessor;
         }
 
-        if ($contextids !== false) {
+        if ($contextids === false) {
+            $contextsstr = $this->model->contextids;
+        } else if (!$contextids) {
+            $contextsstr = null;
+        } else {
             $contextsstr = json_encode($contextids);
 
             // Reset the internal cache.
             $this->contexts = null;
-        } else {
-            $contextsstr = $this->model->contextids;
         }
 
         if ($this->model->timesplitting !== $timesplittingid ||
index aac3464..ee6b58a 100644 (file)
@@ -3754,5 +3754,14 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2019102500.04);
     }
 
+    if ($oldversion < 2019103000.13) {
+
+        $DB->execute("UPDATE {analytics_models} set contextids = null
+                       WHERE contextids = :zero or contextids = :null", ['zero' => '0', 'null' => 'null']);
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2019103000.13);
+    }
+
     return true;
 }
index 7293cec..a310d95 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2019103000.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2019103000.13;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.