From e261f1ed9b369011fbc747b9bbed66d871f52c52 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 4 Feb 2020 18:57:02 +0100 Subject: [PATCH] Require length before setting decimals of DecimalDatabaseTableColumn --- .../column/AbstractDatabaseTableColumn.class.php | 8 ++++---- .../table/column/DecimalDatabaseTableColumn.class.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php b/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php index 3c84ac5e7f..d712eeeabd 100644 --- a/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php +++ b/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php @@ -176,6 +176,10 @@ abstract class AbstractDatabaseTableColumn implements IDatabaseTableColumn { $column->autoIncrement($data['autoIncrement'] ?: null); } + if ($column instanceof ILengthDatabaseTableColumn) { + $column->length($data['length'] ?: null); + } + if ($column instanceof IDecimalsDatabaseTableColumn) { $column->decimals($data['decimals'] ?: null); } @@ -193,10 +197,6 @@ abstract class AbstractDatabaseTableColumn implements IDatabaseTableColumn { $column->enumValues($values); } - if ($column instanceof ILengthDatabaseTableColumn) { - $column->length($data['length'] ?: null); - } - return $column; } } diff --git a/wcfsetup/install/files/lib/system/database/table/column/DecimalDatabaseTableColumn.class.php b/wcfsetup/install/files/lib/system/database/table/column/DecimalDatabaseTableColumn.class.php index 6a4f408426..5195d75a94 100644 --- a/wcfsetup/install/files/lib/system/database/table/column/DecimalDatabaseTableColumn.class.php +++ b/wcfsetup/install/files/lib/system/database/table/column/DecimalDatabaseTableColumn.class.php @@ -16,6 +16,17 @@ class DecimalDatabaseTableColumn extends AbstractDecimalDatabaseTableColumn { */ protected $type = 'decimal'; + /** + * @inheritDoc + */ + public function decimals($decimals) { + if ($this->getLength() === null) { + throw new \BadMethodCallException("Before setting the decimals, the length has to be set."); + } + + return parent::decimals($decimals); + } + /** * @inheritDoc */ -- 2.20.1