Fix updating decimal fields with default value (#3382)
authorMatthias Schmidt <gravatronics@live.com>
Wed, 24 Jun 2020 15:12:47 +0000 (17:12 +0200)
committerGitHub <noreply@github.com>
Wed, 24 Jun 2020 15:12:47 +0000 (17:12 +0200)
MySQL stores the default value using the specified number of decimals so that when comparing the existing default value with the new default value, the same format should be used.

wcfsetup/install/files/lib/system/database/table/column/AbstractDecimalDatabaseTableColumn.class.php

index 5ba2b46a4bcbdc343bf3f09bc3c0c8933c871c9a..6bf3ec6992d992d315d51da325b76f2f9d3ff2e2 100644 (file)
@@ -12,4 +12,16 @@ namespace wcf\system\database\table\column;
  */
 abstract class AbstractDecimalDatabaseTableColumn extends AbstractDatabaseTableColumn implements IDecimalsDatabaseTableColumn {
        use TDecimalsDatabaseTableColumn;
+       
+       /**
+        * @inheritDoc
+        */
+       public function getDefaultValue() {
+               $defaultValue = parent::getDefaultValue();
+               if ($defaultValue === null) {
+                       return $defaultValue;
+               }
+               
+               return number_format($defaultValue, $this->getDecimals() ?? 0, '.', '');
+       }
 }