|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Deck\Command; |
|
25
|
|
|
|
|
26
|
|
|
use OCA\Deck\Db\AssignedUsersMapper; |
|
27
|
|
|
use OCA\Deck\Db\BoardMapper; |
|
28
|
|
|
use OCA\Deck\Db\CardMapper; |
|
29
|
|
|
use OCA\Deck\Db\StackMapper; |
|
30
|
|
|
use OCA\Deck\Service\BoardService; |
|
31
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
|
32
|
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException; |
|
33
|
|
|
use OCP\IGroupManager; |
|
34
|
|
|
use OCP\IUserManager; |
|
35
|
|
|
use Symfony\Component\Console\Command\Command; |
|
36
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
37
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
38
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
39
|
|
|
|
|
40
|
|
|
class UserExport extends Command { |
|
41
|
|
|
|
|
42
|
|
|
protected $boardService; |
|
43
|
|
|
protected $cardMapper; |
|
44
|
|
|
private $userManager; |
|
45
|
|
|
private $groupManager; |
|
46
|
|
|
private $assignedUsersMapper; |
|
47
|
|
|
|
|
48
|
|
|
public function __construct(BoardMapper $boardMapper, |
|
49
|
|
|
BoardService $boardService, |
|
50
|
|
|
StackMapper $stackMapper, |
|
51
|
|
|
CardMapper $cardMapper, |
|
52
|
|
|
AssignedUsersMapper $assignedUsersMapper, |
|
53
|
|
|
IUserManager $userManager, |
|
54
|
|
|
IGroupManager $groupManager) { |
|
55
|
|
|
parent::__construct(); |
|
56
|
|
|
|
|
57
|
|
|
$this->cardMapper = $cardMapper; |
|
58
|
|
|
$this->boardService = $boardService; |
|
59
|
|
|
$this->stackMapper = $stackMapper; |
|
60
|
|
|
$this->assignedUsersMapper = $assignedUsersMapper; |
|
61
|
|
|
$this->boardMapper = $boardMapper; |
|
62
|
|
|
|
|
63
|
|
|
$this->userManager = $userManager; |
|
64
|
|
|
$this->groupManager = $groupManager; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function configure() { |
|
68
|
|
|
$this |
|
69
|
|
|
->setName('deck:export') |
|
70
|
|
|
->setDescription('Export a JSON dump of user data') |
|
71
|
|
|
->addArgument( |
|
72
|
|
|
'user-id', |
|
73
|
|
|
InputArgument::REQUIRED, |
|
74
|
|
|
'User ID of the user' |
|
75
|
|
|
) |
|
76
|
|
|
; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param InputInterface $input |
|
81
|
|
|
* @param OutputInterface $output |
|
82
|
|
|
* @return void |
|
83
|
|
|
* @throws DoesNotExistException |
|
84
|
|
|
* @throws MultipleObjectsReturnedException |
|
85
|
|
|
* @throws \ReflectionException |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
88
|
|
|
|
|
89
|
|
|
$userId = $input->getArgument('user-id'); |
|
90
|
|
|
|
|
91
|
|
|
$this->boardService->setUserId($userId); |
|
92
|
|
|
$boards = $this->boardService->findAll(); |
|
93
|
|
|
|
|
94
|
|
|
$data = []; |
|
95
|
|
|
foreach ($boards as $board) { |
|
96
|
|
|
$fullBoard = $this->boardMapper->find($board->getId(), true, true); |
|
97
|
|
|
$data[$board->getId()] = (array)$fullBoard->jsonSerialize(); |
|
98
|
|
|
$stacks = $this->stackMapper->findAll($board->getId()); |
|
99
|
|
|
foreach ($stacks as $stack) { |
|
100
|
|
|
$data[$board->getId()]['stacks'][] = (array)$stack->jsonSerialize(); |
|
101
|
|
|
$cards = $this->cardMapper->findAllByStack($stack->getId()); |
|
102
|
|
|
foreach ($cards as $card) { |
|
103
|
|
|
$fullCard = $this->cardMapper->find($card->getId()); |
|
104
|
|
|
$assignedUsers = $this->assignedUsersMapper->find($card->getId()); |
|
105
|
|
|
$fullCard->setAssignedUsers($assignedUsers); |
|
106
|
|
|
$data[$board->getId()]['stacks'][$stack->getId()]['cards'][] = (array)$fullCard->jsonSerialize(); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
$output->writeln(json_encode($data, JSON_PRETTY_PRINT)); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
|