fix(entity): Do not call getId when inserting and $id is null

Otherwise this breaks some existing code, in particular PublicKeyToken

Signed-off-by: Carl Schwan <carlschwan@kde.org>
This commit is contained in:
Carl Schwan 2026-01-06 15:42:03 +01:00
parent 7c1a8a4060
commit 693a2263cc
No known key found for this signature in database
GPG key ID: 02325448204E452A
2 changed files with 6 additions and 2 deletions

View file

@ -102,7 +102,8 @@ class PublicKeyToken extends Entity implements INamedToken, IWipeableToken {
}
public function getId(): int {
return (int)$this->id;
assert(!is_string($this->id) && $this->id !== null);
return $this->id;
}
public function getUID(): string {

View file

@ -108,6 +108,9 @@ abstract class QBMapper {
$getter = 'get' . ucfirst($property);
$value = $entity->$getter();
if ($property === 'id' && $entity->id === null) {
continue;
}
$type = $this->getParameterTypeForProperty($entity, $property);
$qb->setValue($column, $qb->createNamedParameter($value, $type));
}
@ -116,7 +119,7 @@ abstract class QBMapper {
/** @psalm-suppress DocblockTypeContradiction */
$entity->generateId();
$qb->executeStatement();
} elseif ($entity->getId() === null) {
} elseif ($entity->id === null) {
$qb->executeStatement();
// When autoincrement is used id is always an int
$entity->setId($qb->getLastInsertId());