export json data of commments
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
This commit is contained in:
@@ -12,6 +12,7 @@ use OCA\Deck\Db\CardMapper;
|
|||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCA\Deck\Model\CardDetails;
|
use OCA\Deck\Model\CardDetails;
|
||||||
use OCA\Deck\Service\BoardService;
|
use OCA\Deck\Service\BoardService;
|
||||||
|
use OCA\Deck\Service\CommentService;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\DB\Exception;
|
use OCP\DB\Exception;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
@@ -27,6 +28,7 @@ class UserExport extends Command {
|
|||||||
private StackMapper $stackMapper,
|
private StackMapper $stackMapper,
|
||||||
private CardMapper $cardMapper,
|
private CardMapper $cardMapper,
|
||||||
private AssignmentMapper $assignedUsersMapper,
|
private AssignmentMapper $assignedUsersMapper,
|
||||||
|
private CommentService $commentService,
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@@ -56,6 +58,9 @@ class UserExport extends Command {
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($boards as $board) {
|
foreach ($boards as $board) {
|
||||||
|
if ($board->getDeletedAt() > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$fullBoard = $this->boardMapper->find($board->getId(), true, true);
|
$fullBoard = $this->boardMapper->find($board->getId(), true, true);
|
||||||
$data[$board->getId()] = $fullBoard->jsonSerialize();
|
$data[$board->getId()] = $fullBoard->jsonSerialize();
|
||||||
$stacks = $this->stackMapper->findAll($board->getId());
|
$stacks = $this->stackMapper->findAll($board->getId());
|
||||||
@@ -68,7 +73,13 @@ class UserExport extends Command {
|
|||||||
$fullCard->setAssignedUsers($assignedUsers);
|
$fullCard->setAssignedUsers($assignedUsers);
|
||||||
|
|
||||||
$cardDetails = new CardDetails($fullCard, $fullBoard);
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class CommentEventListener implements IEventListener {
|
|||||||
private function activityHandler(CommentsEvent $event): void {
|
private function activityHandler(CommentsEvent $event): void {
|
||||||
$comment = $event->getComment();
|
$comment = $event->getComment();
|
||||||
$card = $this->cardMapper->find($comment->getObjectId());
|
$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 {
|
private function notificationHandler(CommentsEvent $event): void {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Service\Importer\Systems;
|
namespace OCA\Deck\Service\Importer\Systems;
|
||||||
|
|
||||||
|
use OC\Comments\Comment;
|
||||||
use OCA\Deck\BadRequestException;
|
use OCA\Deck\BadRequestException;
|
||||||
use OCA\Deck\Db\Acl;
|
use OCA\Deck\Db\Acl;
|
||||||
use OCA\Deck\Db\Assignment;
|
use OCA\Deck\Db\Assignment;
|
||||||
@@ -103,8 +104,20 @@ class DeckJsonService extends ABoardImportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getComments(): array {
|
public function getComments(): array {
|
||||||
// Comments are not implemented in export
|
$comments = [];
|
||||||
return [];
|
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 {
|
public function getCardLabelAssignment(): array {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ use OCA\Deck\Command\BoardImport;
|
|||||||
use OCA\Deck\Command\UserExport;
|
use OCA\Deck\Command\UserExport;
|
||||||
use OCA\Deck\Service\BoardService;
|
use OCA\Deck\Service\BoardService;
|
||||||
use OCA\Deck\Service\CardService;
|
use OCA\Deck\Service\CardService;
|
||||||
|
use OCA\Deck\Service\CommentService;
|
||||||
use OCA\Deck\Service\Importer\BoardImportService;
|
use OCA\Deck\Service\Importer\BoardImportService;
|
||||||
use OCA\Deck\Service\Importer\Systems\DeckJsonService;
|
use OCA\Deck\Service\Importer\Systems\DeckJsonService;
|
||||||
use OCA\Deck\Service\PermissionService;
|
use OCA\Deck\Service\PermissionService;
|
||||||
@@ -194,6 +195,7 @@ class ImportExportTest extends \Test\TestCase {
|
|||||||
self::getFreshService(StackMapper::class),
|
self::getFreshService(StackMapper::class),
|
||||||
self::getFreshService(CardMapper::class),
|
self::getFreshService(CardMapper::class),
|
||||||
self::getFreshService(AssignmentMapper::class),
|
self::getFreshService(AssignmentMapper::class),
|
||||||
|
self::getFreshService(CommentService::class)
|
||||||
);
|
);
|
||||||
$exporter->setApplication($application);
|
$exporter->setApplication($application);
|
||||||
$exporter->run($input, $output);
|
$exporter->run($input, $output);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Command;
|
namespace OCA\Deck\Command;
|
||||||
|
|
||||||
|
use OC\Comments\Comment;
|
||||||
use OCA\Deck\Db\AssignmentMapper;
|
use OCA\Deck\Db\AssignmentMapper;
|
||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\BoardMapper;
|
use OCA\Deck\Db\BoardMapper;
|
||||||
@@ -31,7 +32,9 @@ use OCA\Deck\Db\CardMapper;
|
|||||||
use OCA\Deck\Db\Stack;
|
use OCA\Deck\Db\Stack;
|
||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCA\Deck\Service\BoardService;
|
use OCA\Deck\Service\BoardService;
|
||||||
|
use OCA\Deck\Service\CommentService;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
@@ -46,6 +49,7 @@ class UserExportTest extends \Test\TestCase {
|
|||||||
protected $assignedUserMapper;
|
protected $assignedUserMapper;
|
||||||
protected $userManager;
|
protected $userManager;
|
||||||
protected $groupManager;
|
protected $groupManager;
|
||||||
|
protected $commentService;
|
||||||
|
|
||||||
private UserExport $userExport;
|
private UserExport $userExport;
|
||||||
|
|
||||||
@@ -59,7 +63,8 @@ class UserExportTest extends \Test\TestCase {
|
|||||||
$this->assignedUserMapper = $this->createMock(AssignmentMapper::class);
|
$this->assignedUserMapper = $this->createMock(AssignmentMapper::class);
|
||||||
$this->userManager = $this->createMock(IUserManager::class);
|
$this->userManager = $this->createMock(IUserManager::class);
|
||||||
$this->groupManager = $this->createMock(IGroupManager::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) {
|
public function getBoard($id) {
|
||||||
@@ -80,6 +85,13 @@ class UserExportTest extends \Test\TestCase {
|
|||||||
$card->setTitle('Card ' . $id);
|
$card->setTitle('Card ' . $id);
|
||||||
return $card;
|
return $card;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getComment($id) {
|
||||||
|
$comment = new Comment();
|
||||||
|
$comment->setActor("users", "admin");
|
||||||
|
$comment->setMessage("fake comment" . $id);
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
public function testExecute() {
|
public function testExecute() {
|
||||||
$input = $this->createMock(InputInterface::class);
|
$input = $this->createMock(InputInterface::class);
|
||||||
$input->expects($this->once())->method('getArgument')->with('user-id')->willReturn('admin');
|
$input->expects($this->once())->method('getArgument')->with('user-id')->willReturn('admin');
|
||||||
@@ -107,6 +119,13 @@ class UserExportTest extends \Test\TestCase {
|
|||||||
$this->getCard(2),
|
$this->getCard(2),
|
||||||
$this->getCard(3),
|
$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)))
|
$this->cardMapper->expects($this->exactly(count($boards) * count($stacks)))
|
||||||
->method('findAllByStack')
|
->method('findAllByStack')
|
||||||
->willReturn($cards);
|
->willReturn($cards);
|
||||||
|
|||||||
Reference in New Issue
Block a user