Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Db/BoardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,9 @@ public function flushCache(?int $boardId = null, ?string $userId = null) {
$this->userBoardCache = new CappedMemoryCache();
}
}

public function getDbConnection() {

return $this->db;
}
}
28 changes: 28 additions & 0 deletions lib/Service/AssignmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
use Symfony\Component\CssSelector\Exception\InternalErrorException;

class AssignmentService {

Expand Down Expand Up @@ -64,6 +66,10 @@
* @var AssignmentServiceValidator
*/
private $assignmentServiceValidator;
/**
* @var LoggerInterface
*/
private $logger;


public function __construct(
Expand All @@ -77,6 +83,7 @@
IEventDispatcher $eventDispatcher,
AssignmentServiceValidator $assignmentServiceValidator,
$userId,
LoggerInterface $logger,
) {
$this->assignmentServiceValidator = $assignmentServiceValidator;
$this->permissionService = $permissionService;
Expand All @@ -88,6 +95,7 @@
$this->activityManager = $activityManager;
$this->eventDispatcher = $eventDispatcher;
$this->currentUser = $userId;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -169,4 +177,24 @@
}
throw new NotFoundException('No assignment for ' . $userId . 'found.');
}

/**
* @param int $cardId
* @param array $assignedUser
*
* @return void
*/
public function importAssignedUser(int $cardId, array $assignedUser): void {
$newAssignedUser = new Assignment();
$newAssignedUser->setCardId($cardId);
$newAssignedUser->setParticipant($assignedUser['participant']['uid']);
$newAssignedUser->setType($assignedUser['type']);

try {
$this->assignedUsersMapper->insert($newAssignedUser);
} catch (\Exception $e) {
$this->logger->error('importAssignedUser insert error: ' . $e->getMessage());
throw new InternalErrorException('importAssignedUser insert error: ' . $e->getMessage());

Check failure on line 197 in lib/Service/AssignmentService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/AssignmentService.php:197:14: UndefinedClass: Class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/019)
}
}
}
50 changes: 50 additions & 0 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\CssSelector\Exception\InternalErrorException;

class BoardService {
private ?array $boardsCacheFull = null;
Expand Down Expand Up @@ -83,6 +85,7 @@
private ISecureRandom $random,
private ConfigService $configService,
private ?string $userId,
private LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -836,4 +839,51 @@

$board->setStacks($stacks);
}

/**
* @param array $board
* @param string $userId
*
* @return Board
*
* @throws InternalErrorException

Check failure on line 849 in lib/Service/BoardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedDocblockClass

lib/Service/BoardService.php:849:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/200)
*/
public function importBoard(array $board, string $userId): Board {
$item = new Board();
$item->setTitle($board['title']);
$item->setOwner($userId);
$item->setColor($board['color']);
$item->setArchived((bool)$board['archived']);
$item->setDeletedAt($board['deletedAt']);
$item->setLastModified($board['lastModified']);
try {
$newBoard = $this->boardMapper->insert($item);
} catch (\Exception $e) {
$this->logger->error('importBoard insert error: ' . $e->getMessage());
throw new InternalErrorException('importBoard insert error: ' . $e->getMessage());

Check failure on line 863 in lib/Service/BoardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/BoardService.php:863:14: UndefinedClass: Class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/019)
}
return $newBoard;
}

/**
* @param Board $board
* @param array $acl
*
* @return void
*/
public function importAcl(Board $board, array $acl): void {
$aclEntity = new Acl();
$aclEntity->setBoardId($board->getId());
$aclEntity->setType((int)$acl['type']);
$aclEntity->setParticipant($acl['participant']);
$aclEntity->setPermissionEdit((bool)$acl['permissionEdit']);
$aclEntity->setPermissionShare((bool)$acl['permissionShare']);
$aclEntity->setPermissionManage((bool)$acl['permissionManage']);
try {
$this->aclMapper->insert($aclEntity);
} catch (\Exception $e) {
$this->logger->error('importAcl insert error: ' . $e->getMessage());
throw new InternalErrorException('importAcl insert error: ' . $e->getMessage());

Check failure on line 886 in lib/Service/BoardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/BoardService.php:886:14: UndefinedClass: Class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/019)
}
}
}
54 changes: 54 additions & 0 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\IURLGenerator;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\CssSelector\Exception\InternalErrorException;

class CardService {
public function __construct(
Expand Down Expand Up @@ -638,4 +639,57 @@
public function getRedirectUrlForCard(int $cardId): string {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.redirectToCard', ['cardId' => $cardId]);
}

/**
* @param int $stackId
* @param array $card
*
* @return Card
*
* @throws InternalErrorException

Check failure on line 649 in lib/Service/CardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedDocblockClass

lib/Service/CardService.php:649:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/200)
*/
public function importCard (int $stackId, array $card): Card {
$item = new Card();
$item->setStackId($stackId);
$item->setTitle($card['title']);
$item->setType($card['type']);
$item->setOrder($card['order']);
$item->setOwner($card['owner']);
$item->setDescription($card['description']);
$item->setDuedate($card['duedate']);
$item->setLastModified($card['lastModified']);
$item->setLastEditor($card['lastEditor']);
$item->setCreatedAt($card['createdAt']);
$item->isArchived($card['archived']);
$item->setDeletedAt($card['deletedAt']);
$item->setDone($card['done']);
$item->setNotified($card['notified']);

try {
$newCard = $this->cardMapper->insert($item);
} catch (\Exception $e) {
$this->logger->error('importCard insert error: ' . $e->getMessage());
throw new InternalErrorException('importCard insert error: ' . $e->getMessage());

Check failure on line 672 in lib/Service/CardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/CardService.php:672:14: UndefinedClass: Class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/019)
}

return $newCard;
}

/**
* @param int $cardId
* @param int $boardId
* @param array $importedLabel
*
* @return void
*/
public function importLabels(int $cardId, int $boardId, array $importedLabel): void {
$labels = $this->labelMapper->findAll($boardId);

foreach ($labels as $label) {
if ($label->getTitle() === $importedLabel['title'] && $label->getColor() === $importedLabel['color']) {
$this->cardMapper->assignLabel($cardId, $label->getId());
}
}
$this->changeHelper->cardChanged($cardId);
}
}
47 changes: 47 additions & 0 deletions lib/Service/CommentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\Deck\Service;

use OC\Comments\Comment;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\Acl;
Expand All @@ -21,6 +22,7 @@
use OCP\IUserManager;
use OutOfBoundsException;
use Psr\Log\LoggerInterface;
use Symfony\Component\CssSelector\Exception\InternalErrorException;

class CommentService {

Expand Down Expand Up @@ -188,4 +190,49 @@
}
return $formattedComment;
}

public function exportAllForCard(int $cardId, int $limit = 1000, int $offset = 0): array {
$comments = $this->commentsManager->getForObject(
Application::COMMENT_ENTITY_TYPE,
(string)$cardId,
$limit,
$offset
);
$allComments = [];
foreach ($comments as $comment) {
$formattedComment = $this->formatComment($comment);
try {
if ($comment->getParentId() !== '0' && $replyTo = $this->commentsManager->get($comment->getParentId())) {
$formattedComment['replyTo'] = $this->formatComment($replyTo);
}
} catch (CommentNotFoundException $e) {
}
$allComments[] = $formattedComment;
}
return $allComments;
}

/**
* @param int $cardId
* @param array $comment
* @param string $parentId
*
* @return int
*/
public function importComment(int $cardId, array $comment, string $parentId = '0'): int {
try {
$newComment = new Comment();
$newComment->setMessage($comment['message']);
$newComment->setObject(Application::COMMENT_ENTITY_TYPE, (string)$cardId);
$newComment->setVerb('comment');
$newComment->setParentId($parentId);
$newComment->setActor($comment['actorType'], $comment['actorId']);
$newComment->setCreationDateTime(new \DateTime($comment['creationDateTime']));
$this->commentsManager->save($newComment);

Check failure on line 231 in lib/Service/CommentService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidArgument

lib/Service/CommentService.php:231:33: InvalidArgument: Argument 1 of OCP\Comments\ICommentsManager::save expects OCP\Comments\IComment, but OC\Comments\Comment provided (see https://psalm.dev/004)
} catch (\Exception $e) {
$this->logger->error('importComment insert error: ' . $e->getMessage());
throw new InternalErrorException('importComment insert error: ' . $e->getMessage());

Check failure on line 234 in lib/Service/CommentService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/CommentService.php:234:14: UndefinedClass: Class, interface or enum named Symfony\Component\CssSelector\Exception\InternalErrorException does not exist (see https://psalm.dev/019)
}
return (int)$newComment->getId();
}
}
66 changes: 66 additions & 0 deletions lib/Service/FilesAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\Share\IManager;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Symfony\Component\CssSelector\Exception\InternalErrorException;

class FilesAppService implements IAttachmentService, ICustomAttachmentService {
/**
Expand Down Expand Up @@ -339,4 +340,69 @@
throw new BadRequestException($errorMessage);
}
}

/**
* @param int[] $cardIds
* @return array
*/
public function getAllDeckSharesForCards(array $cardIds): array {
$qb = $this->connection->getQueryBuilder();
$qb->select('*')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(12)))
->andWhere($qb->expr()->in('share_with', $qb->createParameter('cardIds')));
$qb->setParameter('cardIds', $cardIds, Connection::PARAM_STR_ARRAY);

Check failure on line 354 in lib/Service/FilesAppService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/FilesAppService.php:354:42: UndefinedClass: Class, interface or enum named OCA\Deck\Service\Connection does not exist (see https://psalm.dev/019)

$sql = $qb->getSQL();
$params = $qb->getParameters();
$shares = $qb->executeQuery()->fetchAllAssociative();
return $shares;
}

/**
* @param int $cardId
* @param array $shareData
* @param string $userId
* @return bool

Check failure on line 366 in lib/Service/FilesAppService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MismatchingDocblockReturnType

lib/Service/FilesAppService.php:366:13: MismatchingDocblockReturnType: Docblock has incorrect return type 'bool', should be 'void' (see https://psalm.dev/142)
*/
public function importDeckSharesForCard(int $cardId, array $shareData, int $fileId, string $userId): void {
try {
$insert = [
'share_type' => $shareData['share_type'] ?? 12,
'share_with' => (string)$cardId,
'uid_owner' => $userId,
'uid_initiator' => $userId,
'file_source' => $fileId,
'file_target' => $shareData['file_target'],
'permissions' => $shareData['permissions'] ?? 1,
'stime' => $shareData['stime'] ?? time(),
'parent' => $shareData['parent'],
'item_type' => $shareData['item_type'] ?? 'file',
'item_source' => $fileId,
'item_target' => $shareData['item_target'],
'token' => $shareData['token'],
'mail_send' => $shareData['mail_send'],
'share_name' => $shareData['share_name'],
'note' => $shareData['note'],
'label' => $shareData['label'],
'hide_download' => $shareData['hide_download'],
'expiration' => $shareData['expiration'],
'accepted' => $shareData['accepted'],
'password' => $shareData['password'],
'password_by_talk' => $shareData['password_by_talk'],
'attributes' => $shareData['attributes'],
'password_expiration_time' => $shareData['password_expiration_time'],
'reminder_sent' => $shareData['reminder_sent'],
];
$qb = $this->connection->getQueryBuilder();
$qb->insert('share');
foreach ($insert as $key => $value) {
$qb->setValue($key, $qb->createNamedParameter($value));
}
$qb->executeStatement();
} catch (\Throwable $e) {
$this->logger->error('importDeckSharesForCard insert error: ' . $e->getMessage());
throw new InternalErrorException('importDeckSharesForCard insert error: ' . $e->getMessage());
}
}
}
Loading
Loading