Skip to content

Commit

Permalink
fix(entity): Fix mapping of old/sub-types to actually supported datab…
Browse files Browse the repository at this point in the history
…ase types

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 23, 2024
1 parent 582af10 commit 8810d78
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/public/AppFramework/Db/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ protected function setter(string $name, array $args): void {
}

switch ($type) {
case Types::BIGINT:
case Types::SMALLINT:
settype($args[0], Types::INTEGER);
break;
case Types::BINARY:
case Types::DECIMAL:
case Types::TEXT:
settype($args[0], Types::STRING);
break;
case Types::TIME:
case Types::DATE:
case Types::DATETIME:
Expand Down Expand Up @@ -260,9 +269,22 @@ public function getUpdatedFields(): array {
*
* @param string $fieldName the name of the attribute
* @param \OCP\DB\Types::* $type the type which will be used to match a cast
* @since 31.0.0 Parameter $type is now restricted to {@see \OCP\DB\Types} constants. The formerly accidentally supported types 'int'|'bool'|'double' are mapped to Types::INTEGER|Types::BOOLEAN|Types::FLOAT accordingly.
* @since 7.0.0
*/
protected function addType(string $fieldName, string $type): void {
/** @psalm-suppress TypeDoesNotContainType */
if (in_array($type, ['bool', 'double', 'int', 'array', 'object'], true)) {
// Mapping legacy strings to the actual types
$type = match ($type) {
'int' => Types::INTEGER,
'bool' => Types::BOOLEAN,
'double' => Types::FLOAT,
'array',
'object' => Types::STRING,
};
}

$this->_fieldTypes[$fieldName] = $type;
}

Expand Down

0 comments on commit 8810d78

Please sign in to comment.