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 ab8d4b8432
commit e2ac4df537
7 changed files with 146 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ namespace OCA\Deck\Command;
use OCA\Deck\Service\Importer\BoardImportCommandService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -41,7 +42,9 @@ class BoardImport extends Command {
*/
protected function configure() {
$allowedSystems = $this->boardImportCommandService->getAllowedImportSystems();
$names = array_column($allowedSystems, 'name');
$names = array_map(function ($name) {
return '"' . $name . '"';
}, array_column($allowedSystems, 'internalName'));
$this
->setName('deck:import')
->setDescription('Import data')
@@ -50,7 +53,7 @@ class BoardImport extends Command {
null,
InputOption::VALUE_REQUIRED,
'Source system for import. Available options: ' . implode(', ', $names) . '.',
null
'DeckJson',
)
->addOption(
'config',
@@ -66,6 +69,11 @@ class BoardImport extends Command {
'Data file to import.',
'data.json'
)
->addArgument(
'file',
InputArgument::OPTIONAL,
'File to import',
)
;
}

View File

@@ -138,7 +138,7 @@ class RelationalEntity extends Entity implements \JsonSerializable {
$attr = lcfirst(substr($methodName, 3));
if (array_key_exists($attr, $this->_resolvedProperties) && str_starts_with($methodName, 'set')) {
if (!is_scalar($args[0])) {
if ($args[0] !== null && !is_scalar($args[0])) {
$args[0] = $args[0]['primaryKey'];
}
parent::setter($attr, $args);

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());