Skip to content

Commit

Permalink
export json data of commments
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Aug 1, 2024
1 parent 5439304 commit 655a922
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/Command/UserExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Model\CardDetails;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CommentService;
use OCP\App\IAppManager;
use OCP\DB\Exception;
use Symfony\Component\Console\Command\Command;
Expand All @@ -27,6 +28,7 @@ public function __construct(
private StackMapper $stackMapper,
private CardMapper $cardMapper,
private AssignmentMapper $assignedUsersMapper,
private CommentService $commentService,
) {
parent::__construct();
}
Expand Down Expand Up @@ -56,6 +58,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$data = [];
foreach ($boards as $board) {
if ($board->getDeletedAt() > 0) {
continue;
}
$fullBoard = $this->boardMapper->find($board->getId(), true, true);
$data[$board->getId()] = $fullBoard->jsonSerialize();
$stacks = $this->stackMapper->findAll($board->getId());
Expand All @@ -68,7 +73,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$fullCard->setAssignedUsers($assignedUsers);

$cardDetails = new CardDetails($fullCard, $fullBoard);
$data[$board->getId()]['stacks'][$stack->getId()]['cards'][] = $cardDetails->jsonSerialize();
$comments = $this->commentService->list($card->getId());

$cardDetails->setCommentsCount(count($comments->getData()));

$cardJson = $cardDetails->jsonSerialize();
$cardJson['comments'] = $comments->getData();
$data[$board->getId()]['stacks'][$stack->getId()]['cards'][] = $cardJson;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Listeners/CommentEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(Event $event): void {
private function activityHandler(CommentsEvent $event): void {
$comment = $event->getComment();
$card = $this->cardMapper->find($comment->getObjectId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => $comment]);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => $comment], $comment->getActorId());
}

private function notificationHandler(CommentsEvent $event): void {
Expand Down
17 changes: 15 additions & 2 deletions lib/Service/Importer/Systems/DeckJsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OCA\Deck\Service\Importer\Systems;

use OC\Comments\Comment;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Assignment;
Expand Down Expand Up @@ -103,8 +104,20 @@ public function getCardAssignments(): array {
}

public function getComments(): array {
// Comments are not implemented in export
return [];
$comments = [];
foreach ($this->tmpCards as $sourceCard) {
if (!property_exists($sourceCard, "comments")) {
continue;
}
$commentsOriginal = $sourceCard->comments;
foreach ($commentsOriginal as $commentOriginal) {
$comment = new Comment();
$comment->setActor($commentOriginal->actorType, $commentOriginal->actorId)
->setMessage($commentOriginal->message)->setCreationDateTime(\DateTime::createFromFormat('Y-m-d\TH:i:sP', $commentOriginal->creationDateTime));
$comments[$this->cards[$sourceCard->id]->getId()][$commentOriginal->id] = $comment;
}
}
return $comments;
}

public function getCardLabelAssignment(): array {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/import/ImportExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Deck\Command\UserExport;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\CommentService;
use OCA\Deck\Service\Importer\BoardImportService;
use OCA\Deck\Service\Importer\Systems\DeckJsonService;
use OCA\Deck\Service\PermissionService;
Expand Down Expand Up @@ -194,6 +195,7 @@ private function exportToTemp(): string {
self::getFreshService(StackMapper::class),
self::getFreshService(CardMapper::class),
self::getFreshService(AssignmentMapper::class),
self::getFreshService(CommentService::class)
);
$exporter->setApplication($application);
$exporter->run($input, $output);
Expand Down
21 changes: 20 additions & 1 deletion tests/unit/Command/UserExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Deck\Command;

use OC\Comments\Comment;
use OCA\Deck\Db\AssignmentMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
Expand All @@ -31,7 +32,9 @@
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CommentService;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\IGroupManager;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -46,6 +49,7 @@ class UserExportTest extends \Test\TestCase {
protected $assignedUserMapper;
protected $userManager;
protected $groupManager;
protected $commentService;

private UserExport $userExport;

Expand All @@ -59,7 +63,8 @@ public function setUp(): void {
$this->assignedUserMapper = $this->createMock(AssignmentMapper::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userExport = new UserExport($this->appManager, $this->boardMapper, $this->boardService, $this->stackMapper, $this->cardMapper, $this->assignedUserMapper, $this->userManager, $this->groupManager);
$this->commentService = $this->createMock(CommentService::class);
$this->userExport = new UserExport($this->appManager, $this->boardMapper, $this->boardService, $this->stackMapper, $this->cardMapper, $this->assignedUserMapper, $this->commentService);
}

public function getBoard($id) {
Expand All @@ -80,6 +85,13 @@ public function getCard($id) {
$card->setTitle('Card ' . $id);
return $card;
}

public function getComment($id) {
$comment = new Comment();
$comment->setActor("users", "admin");
$comment->setMessage("fake comment" . $id);
return $comment;
}
public function testExecute() {
$input = $this->createMock(InputInterface::class);
$input->expects($this->once())->method('getArgument')->with('user-id')->willReturn('admin');
Expand Down Expand Up @@ -107,6 +119,13 @@ public function testExecute() {
$this->getCard(2),
$this->getCard(3),
];

$comments = [
$this->getComment(1),
$this->getComment(2),
$this->getComment(3),
];
$this->commentService->expects($this->exactly(count($cards) * count($stacks) * count($boards)))->method('list')->willReturn(new DataResponse($comments));
$this->cardMapper->expects($this->exactly(count($boards) * count($stacks)))
->method('findAllByStack')
->willReturn($cards);
Expand Down

0 comments on commit 655a922

Please sign in to comment.