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>
pull/56795/head
Carl Schwan 5 months ago
parent 7c1a8a4060
commit 693a2263cc
No known key found for this signature in database
GPG Key ID: 02325448204E452A
  1. 3
      lib/private/Authentication/Token/PublicKeyToken.php
  2. 5
      lib/public/AppFramework/Db/QBMapper.php

@ -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 {

@ -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());

Loading…
Cancel
Save