MDL-63252 tool_xmldb: convert default to float to avoid false positives
authorSam Marshall <s.marshall@open.ac.uk>
Mon, 20 Jul 2020 04:29:32 +0000 (12:29 +0800)
committerSimey Lameze <simey@moodle.com>
Thu, 23 Jul 2020 23:53:19 +0000 (07:53 +0800)
admin/tool/xmldb/actions/check_defaults/check_defaults.class.php

index c37ab36..ea21a12 100644 (file)
@@ -93,6 +93,17 @@ class check_defaults extends XMLDBCheckAction {
                     $physicaldefault = null;
                 }
 
+                // For number fields there are issues with type differences, so let's convert
+                // everything to a float.
+                if ($xmldbfield->getType() === XMLDB_TYPE_NUMBER) {
+                    if ($physicaldefault !== null) {
+                        $physicaldefault = (float) $physicaldefault;
+                    }
+                    if ($xmldbdefault !== null) {
+                        $xmldbdefault = (float) $xmldbdefault;
+                    }
+                }
+
                 // There *is* a default and it's wrong.
                 if ($physicaldefault !== $xmldbdefault) {
                     $xmldbtext = self::display_default($xmldbdefault);