refactor: Fix psalm issues

- Add typing for most of the services, controllers and mappers
- Add api doc for mappers
- Use vendor-bin for psalm
- Use attributes for controllers
- Fix upload of attachments

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
This commit is contained in:
Carl Schwan
2025-09-23 16:59:09 +02:00
parent 64741e455d
commit 5cf486150a
77 changed files with 4257 additions and 1393 deletions

View File

@@ -7,6 +7,20 @@
namespace OCA\Deck\Db;
/**
* @method int getBoardId()
* @method bool isPermissionEdit()
* @method void setPermissionEdit(bool $permissionEdit)
* @method bool isPermissionShare()
* @method void setPermissionShare(bool $permissionShare)
* @method bool isPermissionManage()
* @method void setPermissionManage(bool $permissionManage)
* @method int getType()
* @method void setType(int $type)
* @method bool isOwner()
* @method void setOwner(int $owner)
*
*/
class Acl extends RelationalEntity {
public const PERMISSION_READ = 0;
public const PERMISSION_EDIT = 1;
@@ -37,17 +51,13 @@ class Acl extends RelationalEntity {
$this->addResolvable('participant');
}
public function getPermission($permission) {
switch ($permission) {
case self::PERMISSION_READ:
return true;
case self::PERMISSION_EDIT:
return $this->getPermissionEdit();
case self::PERMISSION_SHARE:
return $this->getPermissionShare();
case self::PERMISSION_MANAGE:
return $this->getPermissionManage();
}
return false;
public function getPermission(int $permission): bool {
return match ($permission) {
self::PERMISSION_READ => true,
self::PERMISSION_EDIT => $this->getPermissionEdit(),
self::PERMISSION_SHARE => $this->getPermissionShare(),
self::PERMISSION_MANAGE => $this->getPermissionManage(),
default => false,
};
}
}

View File

@@ -19,13 +19,10 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $boardId
* @param int|null $limit
* @param int|null $offset
* @return Acl[]
* @throws \OCP\DB\Exception
*/
public function findAll($boardId, $limit = null, $offset = null) {
public function findAll(int $boardId, ?int $limit = null, ?int $offset = null) {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'board_id', 'type', 'participant', 'permission_edit', 'permission_share', 'permission_manage')
->from('deck_board_acl')
@@ -51,12 +48,9 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $userId
* @param numeric $id
* @return bool
* @throws \OCP\DB\Exception
*/
public function isOwner($userId, $id): bool {
public function isOwner(string $userId, int $id): bool {
$aclId = $id;
$qb = $this->db->getQueryBuilder();
$qb->select('acl.id')
@@ -68,11 +62,7 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
return count($qb->executeQuery()->fetchAll()) > 0;
}
/**
* @param numeric $id
* @return int|null
*/
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
try {
$entity = $this->find($id);
return $entity->getBoardId();
@@ -87,7 +77,7 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
* @return Acl[]
* @throws \OCP\DB\Exception
*/
public function findByParticipant($type, $participant): array {
public function findByParticipant(int $type, string $participant): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')

View File

@@ -107,11 +107,11 @@ class AssignmentMapper extends DeckMapper implements IPermissionMapper {
}
public function isOwner($userId, $id): bool {
public function isOwner(string $userId, int $id): bool {
return $this->cardMapper->isOwner($userId, $id);
}
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
return $this->cardMapper->findBoardId($id);
}
@@ -123,6 +123,9 @@ class AssignmentMapper extends DeckMapper implements IPermissionMapper {
* @throws NotFoundException
*/
public function insert(Entity $entity): Entity {
if (!($entity instanceof Assignment)) {
throw new \LogicException('Trying to insert a ' . get_class($entity) . ' in the assignment mapper');
}
$origin = $this->getOrigin($entity);
if ($origin === null) {
throw new NotFoundException('No origin found for assignment');
@@ -141,7 +144,7 @@ class AssignmentMapper extends DeckMapper implements IPermissionMapper {
});
}
public function isUserAssigned($cardId, $userId): bool {
public function isUserAssigned(int $cardId, string $userId): bool {
$assignments = $this->findAll($cardId);
foreach ($assignments as $assignment) {
$origin = $this->getOrigin($assignment);

View File

@@ -36,13 +36,11 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param int $id
* @return Attachment
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws \OCP\DB\Exception
*/
public function find($id) {
public function find(int $id): Attachment {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -52,14 +50,11 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param int $cardId
* @param string $data
* @return Attachment
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws \OCP\DB\Exception
*/
public function findByData($cardId, $data) {
public function findByData(int $cardId, string $data): Attachment {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -70,11 +65,10 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param $cardId
* @return Entity[]
* @throws \OCP\DB\Exception
*/
public function findAll($cardId) {
public function findAll(int $cardId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -86,11 +80,9 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param null $cardId
* @param bool $withOffset
* @return array
* @return Attachment[]
*/
public function findToDelete($cardId = null, $withOffset = true) {
public function findToDelete(?int $cardId = null, bool $withOffset = true): array {
// add buffer of 5 min
$timeLimit = time() - (60 * 5);
$qb = $this->db->getQueryBuilder();
@@ -112,12 +104,8 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
/**
* Check if $userId is owner of Entity with $id
*
* @param $userId string userId
* @param $id int|string unique entity identifier
* @return boolean
*/
public function isOwner($userId, $id): bool {
public function isOwner(string $userId, int $id): bool {
try {
$attachment = $this->find($id);
return $this->cardMapper->isOwner($userId, $attachment->getCardId());
@@ -130,10 +118,10 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
/**
* Query boardId for Entity of given $id
*
* @param $id int|string unique entity identifier
* @param $id int unique entity identifier
* @return int|null id of Board
*/
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
try {
$attachment = $this->find($id);
} catch (\Exception $e) {

View File

@@ -10,10 +10,20 @@ namespace OCA\Deck\Db;
/**
* @method int getId()
* @method string getTitle()
* @method void setTitle(string $title)
* @method int getShared()
* @method void setShared(int $shared)
* @method bool isArchived()
* @method bool getArchived()
* @method void setArchived(bool $archived)
* @method int getDeletedAt()
* @method void setDeletedAt(int $deletedAt)
* @method int getLastModified()
* @method void setLastModified(int $lastModified)
* @method string getOwner()
* @method void setOwner(string $owner)
* @method string getColor()
* @method void setColor(string $color)
*/
class Board extends RelationalEntity {
protected $title;

View File

@@ -469,16 +469,16 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
return parent::delete($entity);
}
public function isOwner($userId, $id): bool {
public function isOwner(string $userId, int $id): bool {
$board = $this->find($id);
return ($board->getOwner() === $userId);
}
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
return $id;
}
public function mapAcl(Acl &$acl) {
public function mapAcl(Acl &$acl): void {
$acl->resolveRelation('participant', function ($participant) use (&$acl) {
if ($acl->getType() === Acl::PERMISSION_TYPE_USER) {
if ($this->userManager->userExists($acl->getParticipant())) {

View File

@@ -15,13 +15,18 @@ use Sabre\VObject\Component\VCalendar;
/**
* @method string getTitle()
* @method void setTitle(string $title)
* @method string getDescription()
* @method string getDescriptionPrev()
* @method int getStackId()
* @method void setStackId(int $stackId)
* @method int getOrder()
* @method void setOrder(int $order)
* @method int getLastModified()
* @method int getCreatedAt()
* @method bool getArchived()
* @method string getType()
* @method void setType(string $type)
* @method int getDeletedAt()
* @method void setDeletedAt(int $deletedAt)
* @method bool getNotified()
@@ -68,8 +73,8 @@ class Card extends RelationalEntity {
protected $createdAt;
protected $labels;
protected $assignedUsers;
protected $attachments;
protected $attachmentCount;
protected array $attachments = [];
protected int $attachmentCount = 0;
protected $owner;
protected $order;
protected $archived = false;

View File

@@ -86,16 +86,15 @@ class CardMapper extends QBMapper implements IPermissionMapper {
$updatedFields = $entity->getUpdatedFields();
if (isset($updatedFields['duedate']) && $updatedFields['duedate']) {
try {
/** @var Card $existing */
$existing = $this->find($entity->getId());
if ($existing && $entity->getDuedate() !== $existing->getDuedate()) {
if ($entity->getDueDate() !== $existing->getDueDate()) {
$entity->setNotified(false);
}
// remove pending notifications
$notification = $this->notificationManager->createNotification();
$notification
->setApp('deck')
->setObject('card', $entity->getId());
->setObject('card', (string)$entity->getId());
$this->notificationManager->markProcessed($notification);
} catch (Exception $e) {
}
@@ -135,7 +134,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
* @return Card[]
* @throws \OCP\DB\Exception
*/
public function findAll($stackId, ?int $limit = null, ?int $offset = null, int $since = -1) {
public function findAll($stackId, ?int $limit = null, int $offset = 0, int $since = -1) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('deck_cards')
@@ -155,7 +154,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
* @return array<int, null|Card[]>
* @throws \OCP\DB\Exception
*/
public function findAllForStacks(array $stackIds, ?int $limit = null, ?int $offset = null, int $since = -1): array {
public function findAllForStacks(array $stackIds, ?int $limit = null, int $offset = 0, int $since = -1): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('deck_cards')
@@ -194,7 +193,10 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $qb;
}
public function findToDelete($timeLimit, $limit = null) {
/**
* @return Card[]
*/
public function findToDelete(int $timeLimit, ?int $limit = null): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'title', 'owner', 'archived', 'deleted_at', 'last_modified')
->from('deck_cards')
@@ -205,7 +207,10 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
public function findDeleted($boardId, $limit = null, $offset = null) {
/**
* @return Card[]
*/
public function findDeleted(int $boardId, ?int $limit = null, int $offset = 0): array {
$qb = $this->queryCardsByBoard($boardId);
$qb->andWhere($qb->expr()->neq('c.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->setMaxResults($limit)
@@ -215,7 +220,10 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
public function findCalendarEntries($boardId, $limit = null, $offset = null) {
/**
* @return Card[]
*/
public function findCalendarEntries(int $boardId, ?int $limit = null, $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('c.*')
->from('deck_cards', 'c')
@@ -270,7 +278,11 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
public function findAllWithDue(array $boardIds) {
/**
* @param int[] $boardIds
* @return Card[]
*/
public function findAllWithDue(array $boardIds): array {
$qb = $this->db->getQueryBuilder();
$qb->select('c.*')
->from('deck_cards', 'c')
@@ -287,7 +299,11 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
public function findToMeOrNotAssignedCards(array $boardIds, string $username) {
/**
* @param int[] $boardIds
* @return Card[]
*/
public function findToMeOrNotAssignedCards(array $boardIds, string $username): array {
$qb = $this->db->getQueryBuilder();
$qb->select('c.*')
->from('deck_cards', 'c')
@@ -309,7 +325,10 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
public function findOverdue() {
/**
* @return Card[]
*/
public function findOverdue(): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'title', 'duedate', 'notified')
->from('deck_cards')
@@ -321,6 +340,9 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
/**
* @return Card[]
*/
public function findUnexposedDescriptionChances() {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'title', 'duedate', 'notified', 'description_prev', 'last_editor', 'description')
@@ -329,6 +351,9 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
/**
* @return Card[]
*/
public function search(array $boardIds, SearchQuery $query, ?int $limit = null, ?int $offset = null): array {
$qb = $this->queryCardsByBoards($boardIds);
$this->extendQueryByFilter($qb, $query);
@@ -363,7 +388,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
$qb->andWhere($qb->expr()->lt('c.last_modified', $qb->createNamedParameter($offset, IQueryBuilder::PARAM_INT)));
}
$result = $qb->execute();
$result = $qb->executeQuery();
$entities = [];
while ($row = $result->fetch()) {
$entities[] = Card::fromRow($row);
@@ -406,7 +431,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
$qb->andWhere($qb->expr()->lt('comments.id', $qb->createNamedParameter($offset, IQueryBuilder::PARAM_INT)));
}
$result = $qb->execute();
$result = $qb->executeQuery();
$entities = $result->fetchAll();
$result->closeCursor();
return $entities;
@@ -502,7 +527,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
});
$groups = $this->groupManager->search($assignment->getValue());
foreach ($searchUsers as $user) {
$groups = array_merge($groups, $this->groupManager->getUserIdGroups($user->getUID()));
$groups = array_merge($groups, $this->groupManager->getUserGroups($user));
}
$assignmentSearches = [];
@@ -555,7 +580,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
if ($offset !== null) {
$qb->setFirstResult($offset);
}
$result = $qb->execute();
$result = $qb->executeQuery();
$all = $result->fetchAll();
$result->closeCursor();
return $all;
@@ -567,32 +592,32 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return parent::delete($entity);
}
public function deleteByStack($stackId) {
public function deleteByStack($stackId): void {
$cards = $this->findAllByStack($stackId);
foreach ($cards as $card) {
$this->delete($card);
}
}
public function assignLabel($card, $label) {
public function assignLabel(int $card, int $label): void {
$qb = $this->db->getQueryBuilder();
$qb->insert('deck_assigned_labels')
->values([
'label_id' => $qb->createNamedParameter($label, IQueryBuilder::PARAM_INT),
'card_id' => $qb->createNamedParameter($card, IQueryBuilder::PARAM_INT),
]);
$qb->execute();
$qb->executeStatement();
}
public function removeLabel($card, $label) {
public function removeLabel(int $card, int $label): void {
$qb = $this->db->getQueryBuilder();
$qb->delete('deck_assigned_labels')
->where($qb->expr()->eq('card_id', $qb->createNamedParameter($card, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('label_id', $qb->createNamedParameter($label, IQueryBuilder::PARAM_INT)));
$qb->execute();
$qb->executeStatement();
}
public function isOwner($userId, $id): bool {
public function isOwner(string $userId, int $id): bool {
$qb = $this->db->getQueryBuilder();
$qb->select('c.id')
->from($this->getTableName(), 'c')
@@ -604,7 +629,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return count($qb->executeQuery()->fetchAll()) > 0;
}
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
$result = $this->cache->get('findBoardId:' . $id);
if ($result === null) {
try {
@@ -634,13 +659,11 @@ class CardMapper extends QBMapper implements IPermissionMapper {
}
public function transferOwnership(string $ownerId, string $newOwnerId, ?int $boardId = null): void {
$params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId
];
$sql = "UPDATE `*PREFIX*{$this->tableName}` SET `owner` = :newOwner WHERE `owner` = :owner";
$stmt = $this->db->executeQuery($sql, $params);
$stmt->closeCursor();
$qb = $this->db->getQueryBuilder();
$qb->update($this->getTableName())
->set('owner', $qb->createNamedParameter($newOwnerId, IQueryBuilder::PARAM_STR))
->where('owner', $qb->createNamedParameter($ownerId, IQueryBuilder::PARAM_STR))
->executeStatement();
}
public function remapCardOwner(int $boardId, string $userId, string $newUserId): void {

View File

@@ -19,12 +19,11 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
abstract class DeckMapper extends QBMapper {
/**
* @param $id
* @return T
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws \OCP\AppFramework\Db\DoesNotExistException
*/
public function find($id) {
public function find(int $id): Entity {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -37,7 +36,7 @@ abstract class DeckMapper extends QBMapper {
* Helper function to split passed array into chunks of 1000 elements and
* call a given callback for fetching query results
*
* Can be useful to limit to 1000 results per query for oracle compatiblity
* Can be useful to limit to 1000 results per query for oracle compatibility
* but still iterate over all results
*/
public function chunkQuery(array $ids, callable $callback): Generator {

View File

@@ -8,22 +8,25 @@
namespace OCA\Deck\Db;
/**
*
*/
interface IPermissionMapper {
/**
* Check if $userId is owner of Entity with $id
*
* @param $userId string userId
* @param $id int|string unique entity identifier
* @param $id int unique entity identifier
* @return boolean
*/
public function isOwner($userId, $id): bool;
public function isOwner(string $userId, int $id): bool;
/**
* Query boardId for Entity of given $id
*
* @param $id int|string unique entity identifier
* @return int|null id of Board
* @param $id int unique entity identifier
* @return ?int id of Board
*/
public function findBoardId($id): ?int;
public function findBoardId(int $id): ?int;
}

View File

@@ -8,7 +8,16 @@
namespace OCA\Deck\Db;
/**
* @method getTitle(): string
* @method string getTitle()
* @method void setTitle(string $title)
* @method string getColor()
* @method void setColor(string $color)
* @method int getBoardId()
* @method void setBoardId(int $boardId)
* @method int getCardId()
* @method void setCardId(int $cardId)
* @method int getLastModified()
* @method void setLastModified(int $lastModified)
*/
class Label extends RelationalEntity {
protected $title;
@@ -24,7 +33,7 @@ class Label extends RelationalEntity {
$this->addType('lastModified', 'integer');
}
public function getETag() {
public function getETag(): string {
return md5((string)$this->getLastModified());
}
}

View File

@@ -20,13 +20,10 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $boardId
* @param int|null $limit
* @param int|null $offset
* @return Label[]
* @throws \OCP\DB\Exception
*/
public function findAll($boardId, $limit = null, $offset = null): array {
public function findAll(int $boardId, ?int $limit = null, int $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -44,13 +41,10 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $cardId
* @param int|null $limit
* @param int|null $offset
* @return Label[]
* @throws \OCP\DB\Exception
*/
public function findAssignedLabelsForCard($cardId, $limit = null, $offset = null): array {
public function findAssignedLabelsForCard(int $cardId, ?int $limit = null, int $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('l.*', 'card_id')
->from($this->getTableName(), 'l')
@@ -63,7 +57,7 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
return $this->findEntities($qb);
}
public function findAssignedLabelsForCards($cardIds, $limit = null, $offset = null): array {
public function findAssignedLabelsForCards(array $cardIds, ?int $limit = null, int $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('l.*', 'card_id')
->from($this->getTableName(), 'l')
@@ -77,13 +71,10 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $boardId
* @param int|null $limit
* @param int|null $offset
* @return Label[]
* @throws \OCP\DB\Exception
*/
public function findAssignedLabelsForBoard($boardId, $limit = null, $offset = null): array {
public function findAssignedLabelsForBoard(int $boardId, ?int $limit = null, int $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('l.id as id', 'l.title as title', 'l.color as color')
->selectAlias('c.id', 'card_id')
@@ -113,11 +104,10 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $boardId
* @return array
* @return array<int, list<Label>>
* @throws \OCP\DB\Exception
*/
public function getAssignedLabelsForBoard($boardId) {
public function getAssignedLabelsForBoard(int $boardId): array {
$labels = $this->findAssignedLabelsForBoard($boardId);
$result = [];
foreach ($labels as $label) {
@@ -130,11 +120,9 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $labelId
* @return void
* @throws \OCP\DB\Exception
*/
public function deleteLabelAssignments($labelId) {
public function deleteLabelAssignments(int $labelId): void {
$qb = $this->db->getQueryBuilder();
$qb->delete('deck_assigned_labels')
->where($qb->expr()->eq('label_id', $qb->createNamedParameter($labelId, IQueryBuilder::PARAM_INT)));
@@ -142,11 +130,9 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $cardId
* @return void
* @throws \OCP\DB\Exception
*/
public function deleteLabelAssignmentsForCard($cardId) {
public function deleteLabelAssignmentsForCard(int $cardId): void {
$qb = $this->db->getQueryBuilder();
$qb->delete('deck_assigned_labels')
->where($qb->expr()->eq('card_id', $qb->createNamedParameter($cardId, IQueryBuilder::PARAM_INT)));
@@ -154,33 +140,25 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param string $userId
* @param numeric $labelId
* @return bool
* @throws \OCP\DB\Exception
*/
public function isOwner($userId, $labelId): bool {
public function isOwner(string $userId, int $id): bool {
$qb = $this->db->getQueryBuilder();
$qb->select('l.id')
->from($this->getTableName(), 'l')
->innerJoin('l', 'deck_boards', 'b', 'l.board_id = b.id')
->where($qb->expr()->eq('l.id', $qb->createNamedParameter($labelId, IQueryBuilder::PARAM_INT)))
->where($qb->expr()->eq('l.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('b.owner', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)));
return count($qb->executeQuery()->fetchAll()) > 0;
}
/**
* @param numeric $id
* @return int|null
*/
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
try {
$entity = $this->find($id);
return $entity->getBoardId();
} catch (DoesNotExistException $e) {
} catch (MultipleObjectsReturnedException $e) {
} catch (DoesNotExistException|MultipleObjectsReturnedException) {
return null;
}
return null;
}
}

View File

@@ -11,10 +11,16 @@ use Sabre\VObject\Component\VCalendar;
/**
* @method int getId()
* @method string getTitle()
* @method void setTitle(string $title)
* @method int getBoardId()
* @method void setBoardId(int $boardId)
* @method int getDeletedAt()
* @method void setDeletedAt(int $deletedAt)
* @method int getLastModified()
* @method int getOrder()
* @method void setLastModified(int $lastModified)
* @method \int getOrder()
* @method void setOrder(int $order)
* @method Card[] getCards()
*/
class Stack extends RelationalEntity {

View File

@@ -35,13 +35,11 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
/**
* @param numeric $id
* @return Stack
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws \OCP\DB\Exception
*/
public function find($id): Stack {
public function find(int $id): Stack {
if (isset($this->stackCache[(string)$id])) {
return $this->stackCache[(string)$id];
}
@@ -56,11 +54,9 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param $cardId
* @return Stack|null
* @throws \OCP\DB\Exception
*/
public function findStackFromCardId($cardId): ?Stack {
public function findStackFromCardId(int $cardId): ?Stack {
$qb = $this->db->getQueryBuilder();
$qb->select('s.*')
->from($this->getTableName(), 's')
@@ -76,11 +72,10 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $boardId
* @return Stack[]
* @throws \OCP\DB\Exception
*/
public function findAll($boardId, ?int $limit = null, ?int $offset = null): array {
public function findAll(int $boardId, ?int $limit = null, int $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -93,13 +88,9 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $boardId
* @param int|null $limit
* @param int|null $offset
* @return Stack[]
* @throws \OCP\DB\Exception
*/
public function findDeleted($boardId, $limit = null, $offset = null) {
public function findDeleted(int $boardId, ?int $limit = null, int $offset = 0): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
@@ -125,12 +116,9 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $userId
* @param numeric $stackId
* @return bool
* @throws \OCP\DB\Exception
*/
public function isOwner($userId, $id): bool {
public function isOwner(string $userId, int $id): bool {
$qb = $this->db->getQueryBuilder();
$qb->select('s.id')
->from($this->getTableName(), 's')
@@ -142,11 +130,9 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
}
/**
* @param numeric $id
* @return int|null
* @throws \OCP\DB\Exception
*/
public function findBoardId($id): ?int {
public function findBoardId(int $id): ?int {
$result = $this->cache->get('findBoardId:' . $id);
if ($result !== null) {
return $result !== false ? $result : null;
@@ -163,6 +149,10 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
return $result !== false ? $result : null;
}
/**
* @return array<Stack>
* @throws \OCP\DB\Exception
*/
public function findToDelete(): array {
// add buffer of 5 min
$timeLimit = time() - (60 * 5);