From: Matthias Schmidt Date: Sat, 22 Feb 2020 16:13:54 +0000 (+0100) Subject: Fix int length handling during DB updates for MySQL >= 8.0.19 X-Git-Tag: 5.2.3~8^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=77d58141b15dab6b171f67e5bcc6057aedc32c6f;p=GitHub%2FWoltLab%2FWCF.git Fix int length handling during DB updates for MySQL >= 8.0.19 Close #3160 --- diff --git a/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php b/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php index dad7e2b17b..bae400b4bf 100644 --- a/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php +++ b/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php @@ -7,7 +7,7 @@ use wcf\system\exception\NotImplementedException; * Abstract implementation of a database editor. * * @author Marcel Werk - * @copyright 2001-2019 WoltLab GmbH + * @copyright 2001-2020 WoltLab GmbH * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System\Database\Editor */ @@ -27,6 +27,16 @@ abstract class DatabaseEditor { $this->dbObj = $dbObj; } + /** + * Returns the database object the editor works with. + * + * @return Database + * @since 5.2.3 + */ + public function getDatabase() { + return $this->dbObj; + } + /** * Returns all existing table names. * diff --git a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php index 9f6fc5484d..28f6f8519b 100644 --- a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php @@ -2,7 +2,9 @@ namespace wcf\system\database\table; use wcf\data\package\Package; use wcf\system\database\editor\DatabaseEditor; +use wcf\system\database\table\column\AbstractIntDatabaseTableColumn; use wcf\system\database\table\column\IDatabaseTableColumn; +use wcf\system\database\table\column\TinyintDatabaseTableColumn; use wcf\system\database\table\index\DatabaseTableForeignKey; use wcf\system\database\table\index\DatabaseTableIndex; use wcf\system\database\util\PreparedStatementConditionBuilder; @@ -13,7 +15,7 @@ use wcf\system\WCF; * Processes a given set of changes to database tables. * * @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 * @since 5.2 @@ -102,6 +104,14 @@ class DatabaseTableChangeProcessor { */ protected $foreignKeysToDrop = []; + /** + * indicates if lengths of integer columns are ignored when comparing the columns + * @var boolean + * @see https://github.com/WoltLab/WCF/issues/3160 + * @since 5.2.3 + */ + protected $ignoreIntLengths = false; + /** * package that wants to apply the changes * @var Package @@ -186,6 +196,14 @@ class DatabaseTableChangeProcessor { $this->indexPackageIDs[$row['sqlTable']][$row['sqlIndex']] = $row['packageID']; } } + + $sqlVersion = $dbEditor->getDatabase()->getVersion(); + $compareSQLVersion = preg_replace('/^(\d+\.\d+\.\d+).*$/', '\\1', $sqlVersion); + if (!stripos($sqlVersion, 'MariaDB')) { + if (version_compare($compareSQLVersion, '8.0.19') >= 0) { + $this->ignoreIntLengths = true; + } + } } /** @@ -714,8 +732,23 @@ class DatabaseTableChangeProcessor { * @return bool */ protected function diffColumns(IDatabaseTableColumn $oldColumn, IDatabaseTableColumn $newColumn) { - if (!empty(array_diff($oldColumn->getData(), $newColumn->getData()))) { - return true; + $diff = array_diff($oldColumn->getData(), $newColumn->getData()); + if (!empty($diff)) { + if ( + $this->ignoreIntLengths + && array_key_exists('length', $diff) + && $oldColumn instanceof AbstractIntDatabaseTableColumn + && ( + !($oldColumn instanceof TinyintDatabaseTableColumn) + || $oldColumn->getLength() != 1 + ) + ) { + unset($diff['length']); + } + + if (!empty($diff)) { + return true; + } } // default type has to be checked explicitly for `null` to properly detect changing