From: Matthias Schmidt Date: Sun, 26 Jan 2020 11:02:20 +0000 (+0100) Subject: Ignore validation errors for existing int columns with larger lengths X-Git-Tag: 5.2.2~32 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4536d9aae78a73e80bc626f1a7003be3f4d2ab3e;p=GitHub%2FWoltLab%2FWCF.git Ignore validation errors for existing int columns with larger lengths Close #3139 --- 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; + } }