feat: Let occ deck:import default to deck json importer

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2023-07-19 09:52:44 +02:00
parent cccc4f2f67
commit e7d5fbff63
7 changed files with 146 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ namespace OCA\Deck\Service\Importer;
use OCA\Deck\Exceptions\ConflictException;
use OCA\Deck\NotFoundException;
use OCA\Deck\Service\Importer\Systems\DeckJsonService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -76,6 +77,10 @@ class BoardImportCommandService extends BoardImportService {
}
protected function validateConfig(): void {
// FIXME: Make config optional for deck plain importer (but use a call on the importer insterad)
if ($this->getImportSystem() instanceof DeckJsonService) {
return;
}
try {
$config = $this->getInput()->getOption('config');
if (is_string($config)) {
@@ -145,6 +150,18 @@ class BoardImportCommandService extends BoardImportService {
if (!$this->getImportSystem()->needValidateData()) {
return;
}
$data = $this->getInput()->getArgument('file');
if (is_string($data)) {
if (!file_exists($data)) {
throw new \OCP\Files\NotFoundException('Could not find file ' . $data);
}
$data = json_decode(file_get_contents($data));
if ($data instanceof \stdClass) {
$this->setData($data);
return;
}
}
$data = $this->getInput()->getOption('data');
if (is_string($data)) {
$data = json_decode(file_get_contents($data));

View File

@@ -84,6 +84,8 @@ class BoardImportService {
) {
$this->board = new Board();
$this->disableCommentsEvents();
$this->config = new \stdClass();
}
private function disableCommentsEvents(): void {
@@ -151,6 +153,11 @@ class BoardImportService {
public function getAllowedImportSystems(): array {
if (!$this->allowedSystems) {
$this->addAllowedImportSystem([
'name' => DeckJsonService::$name,
'class' => DeckJsonService::class,
'internalName' => 'DeckJson'
]);
$this->addAllowedImportSystem([
'name' => TrelloApiService::$name,
'class' => TrelloApiService::class,
@@ -161,11 +168,6 @@ class BoardImportService {
'class' => TrelloJsonService::class,
'internalName' => 'TrelloJson'
]);
$this->addAllowedImportSystem([
'name' => DeckJsonService::$name,
'class' => DeckJsonService::class,
'internalName' => 'DeckJson'
]);
}
$this->eventDispatcher->dispatchTyped(new BoardImportGetAllowedEvent($this));
return $this->allowedSystems;

View File

@@ -31,8 +31,6 @@ use OCA\Deck\Db\Card;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\Stack;
use OCA\Deck\Service\Importer\ABoardImportService;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
@@ -44,8 +42,6 @@ class DeckJsonService extends ABoardImportService {
public function __construct(
private IUserManager $userManager,
private IURLGenerator $urlGenerator,
private IL10N $l10n
) {
}
@@ -86,6 +82,20 @@ class DeckJsonService extends ABoardImportService {
}
}
public function mapMember($uid): ?string {
$uidCandidate = $this->members[$uid]?->getUID() ?? null;
if ($uidCandidate) {
return $uidCandidate;
}
if ($this->userManager->userExists($uid)) {
return $uid;
}
return null;
}
public function getCardAssignments(): array {
$assignments = [];
foreach ($this->tmpCards as $sourceCard) {
@@ -176,6 +186,7 @@ class DeckJsonService extends ABoardImportService {
$card = new Card();
$card->setTitle($cardSource->title);
$card->setLastModified($cardSource->lastModified);
$card->setCreatedAt($cardSource->createdAt);
$card->setArchived($cardSource->archived);
$card->setDescription($cardSource->description);
$card->setStackId($this->stacks[$cardSource->stackId]->getId());