Conditions | 1 |
Paths | 1 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 1.1715 |
Changes | 0 |
1 | <?php |
||
18 | 1 | public static function build(): iterable |
|
19 | { |
||
20 | 1 | yield 'import' => fn () => [ |
|
21 | 1 | 'type' => Type::nonNull(_types()->get('ImportResult')), |
|
22 | 1 | 'description' => 'Import a CSV file containing users', |
|
23 | 1 | 'args' => [ |
|
24 | 1 | 'file' => Type::nonNull(_types()->get(UploadType::class)), |
|
25 | 1 | ], |
|
26 | 1 | 'resolve' => function ($root, array $args, SessionInterface $session): array { |
|
27 | // Check ACL |
||
28 | $fakeOrganization = new Organization(); |
||
29 | Helper::throwIfDenied($fakeOrganization, 'create'); |
||
30 | |||
31 | /** @var UploadedFileInterface $file */ |
||
32 | $file = $args['file']; |
||
33 | |||
34 | // Move file to tmp dir |
||
35 | $dir = 'data/tmp/import'; |
||
36 | @mkdir($dir); |
||
37 | $path = $dir . '/' . uniqid() . '.csv'; |
||
38 | $file->moveTo($path); |
||
39 | |||
40 | // Do the thing |
||
41 | $importer = new Importer(); |
||
42 | $result = $importer->import($path); |
||
43 | |||
44 | return $result; |
||
45 | 1 | }, |
|
49 |