From 39a927de18417a2aeb15415d46bbd0239e213f5c Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 15 Jul 2021 00:06:55 -0300 Subject: [PATCH] Clean attachment table Clean code Clean attachment table Signed-off-by: Vitor Mattos --- lib/Service/ABoardImportService.php | 16 ++++++------ lib/Service/BoardImportCommandService.php | 1 - lib/Service/BoardImportService.php | 16 +++++++++--- lib/Service/BoardImportTrelloService.php | 32 +++-------------------- tests/unit/Command/BoardImportTest.php | 1 - 5 files changed, 24 insertions(+), 42 deletions(-) diff --git a/lib/Service/ABoardImportService.php b/lib/Service/ABoardImportService.php index 6bdd4b1f3..d085e0e8f 100644 --- a/lib/Service/ABoardImportService.php +++ b/lib/Service/ABoardImportService.php @@ -21,25 +21,25 @@ abstract class ABoardImportService { /** * @return Stack[] */ - abstract function getStacks(): array; + abstract public function getStacks(): array; /** * @return Card[] */ - abstract function getCards(): array; + abstract public function getCards(): array; - abstract function updateStack(string $id, Stack $stack): self; + abstract public function updateStack(string $id, Stack $stack): self; - abstract function updateCard(string $id, Card $card): self; + abstract public function updateCard(string $id, Card $card): self; - abstract function assignCardsToLabels(): self; + abstract public function importParticipants(): self; - abstract function importParticipants(): self; - - abstract function importComments(): self; + abstract public function importComments(): self; abstract public function importLabels(): self; + abstract public function assignCardsToLabels(): self; + abstract public function validateUsers(): self; public function setImportService($service): self { diff --git a/lib/Service/BoardImportCommandService.php b/lib/Service/BoardImportCommandService.php index b210e9b5e..4a4b92096 100644 --- a/lib/Service/BoardImportCommandService.php +++ b/lib/Service/BoardImportCommandService.php @@ -5,7 +5,6 @@ namespace OCA\Deck\Service; use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; use OCA\Deck\Command\BoardImport; -use OCA\Deck\Service\BoardImportService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/lib/Service/BoardImportService.php b/lib/Service/BoardImportService.php index 38bae3155..fec0f707d 100644 --- a/lib/Service/BoardImportService.php +++ b/lib/Service/BoardImportService.php @@ -28,9 +28,9 @@ use JsonSchema\Validator; use OCA\Deck\AppInfo\Application; use OCA\Deck\BadRequestException; use OCA\Deck\Db\AclMapper; +use OCA\Deck\Db\AssignmentMapper; use OCA\Deck\Db\Board; use OCA\Deck\Db\BoardMapper; -use OCA\Deck\Db\Card; use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\Label; use OCA\Deck\Db\LabelMapper; @@ -38,7 +38,6 @@ use OCA\Deck\Db\StackMapper; use OCA\Deck\NotFoundException; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; -use OCP\Comments\MessageTooLongException; use OCP\Comments\NotFoundException as CommentNotFoundException; use OCP\IDBConnection; use OCP\IUserManager; @@ -58,6 +57,8 @@ class BoardImportService { private $stackMapper; /** @var CardMapper */ private $cardMapper; + /** @var AssignmentMapper */ + private $assignmentMapper; /** @var ICommentsManager */ private $commentsManager; /** @var string */ @@ -88,6 +89,7 @@ class BoardImportService { AclMapper $aclMapper, LabelMapper $labelMapper, StackMapper $stackMapper, + AssignmentMapper $assignmentMapper, CardMapper $cardMapper, ICommentsManager $commentsManager ) { @@ -98,6 +100,7 @@ class BoardImportService { $this->labelMapper = $labelMapper; $this->stackMapper = $stackMapper; $this->cardMapper = $cardMapper; + $this->assignmentMapper = $assignmentMapper; $this->commentsManager = $commentsManager; } @@ -149,9 +152,9 @@ class BoardImportService { public function getAllowedImportSystems(): array { if (!$this->allowedSystems) { $allowedSystems = glob(__DIR__ . '/BoardImport*Service.php'); - $allowedSystems = array_filter($allowedSystems, function($name) { + $allowedSystems = array_filter($allowedSystems, function ($name) { $name = basename($name); - switch($name) { + switch ($name) { case 'ABoardImportService.php': case 'BoardImportService.php': case 'BoardImportCommandService.php': @@ -177,6 +180,11 @@ class BoardImportService { return $this->systemInstance; } + public function insertAssignment($assignment): self { + $this->assignmentMapper->insert($assignment); + return $this; + } + public function importBoard() { $board = $this->getImportSystem()->getBoard(); if ($board) { diff --git a/lib/Service/BoardImportTrelloService.php b/lib/Service/BoardImportTrelloService.php index 09b96531d..c429f1cd8 100644 --- a/lib/Service/BoardImportTrelloService.php +++ b/lib/Service/BoardImportTrelloService.php @@ -25,33 +25,19 @@ namespace OCA\Deck\Service; use OC\Comments\Comment; use OCA\Deck\Db\Acl; -use OCA\Deck\Db\AclMapper; use OCA\Deck\Db\Assignment; use OCA\Deck\Db\AssignmentMapper; use OCA\Deck\Db\Board; use OCA\Deck\Db\Card; -use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\Label; use OCA\Deck\Db\Stack; -use OCA\Deck\Db\StackMapper; -use OCP\IDBConnection; use OCP\IL10N; use OCP\IUser; use OCP\IUserManager; class BoardImportTrelloService extends ABoardImportService { - /** @var LabelService */ - private $labelService; - /** @var StackMapper */ - private $stackMapper; - /** @var CardMapper */ - private $cardMapper; /** @var AssignmentMapper */ private $assignmentMapper; - /** @var AclMapper */ - private $aclMapper; - /** @var IDBConnection */ - private $connection; /** @var IUserManager */ private $userManager; /** @var IL10N */ @@ -75,22 +61,12 @@ class BoardImportTrelloService extends ABoardImportService { public function __construct( BoardService $boardService, - LabelService $labelService, - StackMapper $stackMapper, - CardMapper $cardMapper, AssignmentMapper $assignmentMapper, - AclMapper $aclMapper, - IDBConnection $connection, IUserManager $userManager, IL10N $l10n ) { $this->boardService = $boardService; - $this->labelService = $labelService; - $this->stackMapper = $stackMapper; - $this->cardMapper = $cardMapper; $this->assignmentMapper = $assignmentMapper; - $this->aclMapper = $aclMapper; - $this->connection = $connection; $this->userManager = $userManager; $this->l10n = $l10n; } @@ -221,11 +197,11 @@ class BoardImportTrelloService extends ABoardImportService { return; } $trelloCard->desc .= "\n\n## {$this->l10n->t('Attachments')}\n"; - $trelloCard->desc .= "| {$this->l10n->t('URL')} | {$this->l10n->t('Name')} | {$this->l10n->t('date')} |\n"; - $trelloCard->desc .= "|---|---|---|\n"; + $trelloCard->desc .= "| {$this->l10n->t('File')} | {$this->l10n->t('date')} |\n"; + $trelloCard->desc .= "|---|---\n"; foreach ($trelloCard->attachments as $attachment) { $name = $attachment->name === $attachment->url ? null : $attachment->name; - $trelloCard->desc .= "| {$attachment->url} | {$name} | {$attachment->date} |\n"; + $trelloCard->desc .= "| [{$name}]({$attachment->url}) | {$attachment->date} |\n"; } return $this; } @@ -237,7 +213,7 @@ class BoardImportTrelloService extends ABoardImportService { $assignment->setCardId($this->cards[$trelloCard->id]->getId()); $assignment->setParticipant($this->members[$idMember]->getUID()); $assignment->setType(Assignment::TYPE_USER); - $assignment = $this->assignmentMapper->insert($assignment); + $this->getImportService()->insertAssignment($assignment); } } return $this; diff --git a/tests/unit/Command/BoardImportTest.php b/tests/unit/Command/BoardImportTest.php index 0d369fbcc..4f36d54bd 100644 --- a/tests/unit/Command/BoardImportTest.php +++ b/tests/unit/Command/BoardImportTest.php @@ -26,7 +26,6 @@ namespace OCA\Deck\Command; use OCA\Deck\Command\ImportHelper\TrelloHelper; use OCA\Deck\Service\AImportService; use OCA\Deck\Service\BoardImportService; -use OCA\Deck\Service\BoardService; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface;