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
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use OCA\Deck\Sharing\DeckShareProvider;
use OCA\Deck\Sharing\Listener;
use OCA\Deck\Teams\DeckTeamResourceProvider;
use OCA\Deck\UserMigration\DeckMigrator;
use OCA\Text\Event\LoadEditor;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
Expand Down Expand Up @@ -181,6 +182,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, ResourceAdditionalScriptsListener::class);

$context->registerTeamResourceProvider(DeckTeamResourceProvider::class);
$context->registerUserMigrator(DeckMigrator::class);
}

public function registerCommentsEntity(IEventDispatcher $eventDispatcher): void {
Expand Down
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;
}
}
14 changes: 14 additions & 0 deletions lib/Errors/InternalError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Deck\Errors;

class InternalError extends \Exception {

}
30 changes: 30 additions & 0 deletions lib/Service/AssignmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCA\Deck\Db\AssignmentMapper;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Errors\InternalError;
use OCA\Deck\Event\CardUpdatedEvent;
use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException;
Expand All @@ -23,6 +24,7 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;

class AssignmentService {

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


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

/**
Expand Down Expand Up @@ -169,4 +177,26 @@ public function unassignUser(int $cardId, string $userId, int $type = 0): Assign
}
throw new NotFoundException('No assignment for ' . $userId . 'found.');
}

/**
* @param int $cardId
* @param array $assignedUser
*
* @return void
*
* @throws InternalError
*/
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 InternalError('importAssignedUser insert error: ' . $e->getMessage());
}
}
}
52 changes: 52 additions & 0 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Deck\Db\SessionMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Errors\InternalError;
use OCA\Deck\Event\AclCreatedEvent;
use OCA\Deck\Event\AclDeletedEvent;
use OCA\Deck\Event\AclUpdatedEvent;
Expand All @@ -52,6 +53,7 @@
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;

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

Expand Down Expand Up @@ -848,4 +851,53 @@ private function enrichWithCards(Board $board): void {

$board->setStacks($stacks);
}

/**
* @param array $board
* @param string $userId
*
* @return Board
*
* @throws InternalError
*/
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 InternalError('importBoard insert error: ' . $e->getMessage());
}
return $newBoard;
}

/**
* @param Board $board
* @param array $acl
*
* @return void
*
* @throws InternalError
*/
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 InternalError('importAcl insert error: ' . $e->getMessage());
}
}
}
54 changes: 54 additions & 0 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Errors\InternalError;
use OCA\Deck\Event\CardCreatedEvent;
use OCA\Deck\Event\CardDeletedEvent;
use OCA\Deck\Event\CardUpdatedEvent;
Expand Down Expand Up @@ -640,4 +641,57 @@ public function getCardUrl(int $cardId): string {
public function getRedirectUrlForCard(int $cardId): string {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.redirectToCard', ['cardId' => $cardId]);
}

/**
* @param int $stackId
* @param array $card
*
* @return int
*
* @throws InternalError
*/
public function importCard(int $stackId, array $card): int {
$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->setArchived($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 InternalError('importCard insert error: ' . $e->getMessage());
}

return $newCard->getId();
}

/**
* @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);
}
}
52 changes: 52 additions & 0 deletions lib/Service/CommentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace OCA\Deck\Service;

use OC\Comments\Comment;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Errors\InternalError;
use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException;
use OCP\AppFramework\Http\DataResponse;
Expand Down Expand Up @@ -188,4 +190,54 @@ private function formatComment(IComment $comment, bool $addReplyTo = false): arr
}
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 = $this->commentsManager->create(
$comment['actorType'],
$comment['actorId'],
Application::COMMENT_ENTITY_TYPE,
(string)$cardId
);
$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);
} catch (\Exception $e) {
$this->logger->error('importComment insert error: ' . $e->getMessage());
throw new InternalError('importComment insert error: ' . $e->getMessage());
}
return (int)$newComment->getId();
}
}
Loading
Loading