Skip to content

Commit 8810d78

Browse files
committed
fix(entity): Fix mapping of old/sub-types to actually supported database types
Signed-off-by: Joas Schilling <[email protected]>
1 parent 582af10 commit 8810d78

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/public/AppFramework/Db/Entity.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ protected function setter(string $name, array $args): void {
112112
}
113113

114114
switch ($type) {
115+
case Types::BIGINT:
116+
case Types::SMALLINT:
117+
settype($args[0], Types::INTEGER);
118+
break;
119+
case Types::BINARY:
120+
case Types::DECIMAL:
121+
case Types::TEXT:
122+
settype($args[0], Types::STRING);
123+
break;
115124
case Types::TIME:
116125
case Types::DATE:
117126
case Types::DATETIME:
@@ -260,9 +269,22 @@ public function getUpdatedFields(): array {
260269
*
261270
* @param string $fieldName the name of the attribute
262271
* @param \OCP\DB\Types::* $type the type which will be used to match a cast
272+
* @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.
263273
* @since 7.0.0
264274
*/
265275
protected function addType(string $fieldName, string $type): void {
276+
/** @psalm-suppress TypeDoesNotContainType */
277+
if (in_array($type, ['bool', 'double', 'int', 'array', 'object'], true)) {
278+
// Mapping legacy strings to the actual types
279+
$type = match ($type) {
280+
'int' => Types::INTEGER,
281+
'bool' => Types::BOOLEAN,
282+
'double' => Types::FLOAT,
283+
'array',
284+
'object' => Types::STRING,
285+
};
286+
}
287+
266288
$this->_fieldTypes[$fieldName] = $type;
267289
}
268290

0 commit comments

Comments
 (0)