Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ExportProject | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
configure | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * Nextcloud - Cospend |
5 | * |
6 | * This file is licensed under the Affero General Public License version 3 or |
7 | * later. See the COPYING file. |
8 | * |
9 | * @author Julien Veyssier <eneiluj@posteo.net> |
10 | * @copyright Julien Veyssier 2019 |
11 | */ |
12 | |
13 | namespace OCA\Cospend\Command; |
14 | |
15 | use Symfony\Component\Console\Command\Command; |
16 | use Symfony\Component\Console\Input\InputArgument; |
17 | use Symfony\Component\Console\Input\InputInterface; |
18 | use Symfony\Component\Console\Output\OutputInterface; |
19 | |
20 | use OCA\Cospend\Service\ProjectService; |
21 | |
22 | class ExportProject extends Command { |
23 | |
24 | /** |
25 | * @var ProjectService |
26 | */ |
27 | private $projectService; |
28 | |
29 | public function __construct(ProjectService $projectService) { |
30 | parent::__construct(); |
31 | $this->projectService = $projectService; |
32 | } |
33 | |
34 | protected function configure() { |
35 | $this->setName('cospend:export-project') |
36 | ->setDescription('Export a project to CSV') |
37 | ->addArgument( |
38 | 'project_id', |
39 | InputArgument::REQUIRED, |
40 | 'The id of the project you want to export' |
41 | ) |
42 | ->addArgument( |
43 | 'filename', |
44 | InputArgument::OPTIONAL, |
45 | 'The name of the exported file' |
46 | ); |
47 | } |
48 | |
49 | protected function execute(InputInterface $input, OutputInterface $output) { |
50 | $projectId = $input->getArgument('project_id'); |
51 | $name = $input->getArgument('filename'); |
52 | $project = $this->projectService->getProjectById($projectId); |
53 | if ($project !== null) { |
54 | $result = $this->projectService->exportCsvProject($projectId, $project['userid'], $name); |
55 | if (array_key_exists('path', $result)) { |
56 | $output->writeln( |
57 | 'Project "'.$projectId.'" exported in "'.$result['path']. |
58 | '" of user "'.$project['userid'].'" storage' |
59 | ); |
60 | } |
61 | else { |
62 | $output->writeln('Error: '.$result['message']); |
63 | } |
64 | } |
65 | else { |
66 | $output->writeln('Project '.$projectId.' not found'); |
67 | } |
68 | return 0; |
69 | } |
70 | } |