diff --git a/lib/Db/Stack.php b/lib/Db/Stack.php index c414f52a8..0b9ceb8dc 100644 --- a/lib/Db/Stack.php +++ b/lib/Db/Stack.php @@ -25,6 +25,13 @@ namespace OCA\Deck\Db; use Sabre\VObject\Component\VCalendar; +/** + * @method int getId() + * @method int getBoardId() + * @method int getDeletedAt() + * @method int getLastModified() + * @method int getOrder() + */ class Stack extends RelationalEntity { protected $title; protected $boardId; diff --git a/lib/Db/StackMapper.php b/lib/Db/StackMapper.php index 6f900f45f..f1c77d7d7 100644 --- a/lib/Db/StackMapper.php +++ b/lib/Db/StackMapper.php @@ -25,6 +25,7 @@ namespace OCA\Deck\Db; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\IMapperException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\IDBConnection; @@ -48,6 +49,24 @@ class StackMapper extends DeckMapper implements IPermissionMapper { return $this->findEntity($sql, [$id]); } + /** + * @param $cardId + * @return Stack|null + */ + public function findStackFromCardId($cardId): ?Stack { + $sql = <<findEntity($sql, [$cardId]); + } catch (IMapperException $e) { + return null; + } + } + public function findAll($boardId, $limit = null, $offset = null) { $sql = 'SELECT * FROM `*PREFIX*deck_stacks` WHERE `board_id` = ? AND deleted_at = 0 ORDER BY `order`, `id`'; diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index fe2676ef8..dac50bcb2 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -101,15 +101,12 @@ class Notifier implements INotifier { switch ($notification->getSubject()) { case 'card-assigned': $cardId = $notification->getObjectId(); - $boardId = $this->cardMapper->findBoardId($cardId); + $stack = $this->stackMapper->findStackFromCardId($cardId); + $boardId = $stack ? $stack->getBoardId() : null; if (!$boardId) { throw new AlreadyProcessedException(); } - $card = $this->cardMapper->find($cardId); - $stackId = $card->getStackId(); - $stack = $this->stackMapper->find($stackId); - $initiator = $this->userManager->get($params[2]); if ($initiator !== null) { $dn = $initiator->getDisplayName(); @@ -147,15 +144,12 @@ class Notifier implements INotifier { break; case 'card-overdue': $cardId = $notification->getObjectId(); - $boardId = $this->cardMapper->findBoardId($cardId); + $stack = $this->stackMapper->findStackFromCardId($cardId); + $boardId = $stack ? $stack->getBoardId() : null; if (!$boardId) { throw new AlreadyProcessedException(); } - $card = $this->cardMapper->find($cardId); - $stackId = $card->getStackId(); - $stack = $this->stackMapper->find($stackId); - $notification->setParsedSubject( (string) $l->t('The card "%s" on "%s" has reached its due date.', $params) ); @@ -182,15 +176,12 @@ class Notifier implements INotifier { break; case 'card-comment-mentioned': $cardId = $notification->getObjectId(); - $boardId = $this->cardMapper->findBoardId($cardId); + $stack = $this->stackMapper->findStackFromCardId($cardId); + $boardId = $stack ? $stack->getBoardId() : null; if (!$boardId) { throw new AlreadyProcessedException(); } - $card = $this->cardMapper->find($cardId); - $stackId = $card->getStackId(); - $stack = $this->stackMapper->find($stackId); - $initiator = $this->userManager->get($params[2]); if ($initiator !== null) { $dn = $initiator->getDisplayName();