From 4536d9aae78a73e80bc626f1a7003be3f4d2ab3e Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 26 Jan 2020 12:02:20 +0100 Subject: [PATCH] Ignore validation errors for existing int columns with larger lengths Close #3139 --- .../AbstractIntDatabaseTableColumn.class.php | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/database/table/column/AbstractIntDatabaseTableColumn.class.php b/wcfsetup/install/files/lib/system/database/table/column/AbstractIntDatabaseTableColumn.class.php index f0235f3d5b..fe4e9e711e 100644 --- a/wcfsetup/install/files/lib/system/database/table/column/AbstractIntDatabaseTableColumn.class.php +++ b/wcfsetup/install/files/lib/system/database/table/column/AbstractIntDatabaseTableColumn.class.php @@ -5,7 +5,7 @@ namespace wcf\system\database\table\column; * Abstract implementation of an integer database table column. * * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH + * @copyright 2001-2020 WoltLab GmbH * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System\Database\Table\Column * @since 5.2 @@ -20,4 +20,39 @@ abstract class AbstractIntDatabaseTableColumn extends AbstractDatabaseTableColum public function getMinimumLength() { return 1; } + + /** + * @inheritDoc + */ + public static function createFromData($name, array $data) { + $length = $data['length'] ?? null; + + // Unset `length` so that `parent::createFromData()` does not validate the length + // which is done below. + $data['length'] = null; + + /** @var static $column */ + $column = parent::createFromData($name, $data); + + if ($length) { + try { + $column->length($length); + } + catch (\InvalidArgumentException $e) { + // Ignore exceptions due to the length being to large. + // Such cases can happen when columns were created using the SQL PIP + // where the length (which is just a display length for integer column + // types) is not validated. To update tables with such columns, + // exceptions related to the maximum length must be ignored. + if ($length > $column->getMaximumLength()) { + $column->length = $length; + } + else { + throw $e; + } + } + } + + return $column; + } } -- 2.20.1