| Conditions | 1 |
| Paths | 1 |
| Total Lines | 30 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 1 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | 1 | public static function build(): array |
|
| 19 | { |
||
| 20 | return [ |
||
| 21 | 1 | 'name' => 'importCamt', |
|
| 22 | 1 | 'type' => Type::nonNull(Type::listOf(Type::nonNull(_types()->getOutput(Transaction::class)))), |
|
| 23 | 1 | 'description' => 'Import a CAMT file containing BVR transactions', |
|
| 24 | 'args' => [ |
||
| 25 | 1 | 'file' => Type::nonNull(_types()->get(UploadType::class)), |
|
| 26 | ], |
||
| 27 | 'resolve' => function ($root, array $args, SessionInterface $session): array { |
||
| 28 | |||
| 29 | // Check ACL |
||
| 30 | 1 | $fakeTransaction = new Transaction(); |
|
| 31 | 1 | Helper::throwIfDenied($fakeTransaction, 'create'); |
|
| 32 | |||
| 33 | /** @var UploadedFileInterface $file */ |
||
| 34 | 1 | $file = $args['file']; |
|
| 35 | |||
| 36 | // Move file to tmp dir |
||
| 37 | 1 | $dir = 'data/tmp/camt'; |
|
| 38 | 1 | @mkdir($dir); |
|
| 39 | 1 | $path = $dir . '/' . uniqid() . '.xml'; |
|
| 40 | 1 | $file->moveTo($path); |
|
| 41 | |||
| 42 | // Do the thing |
||
| 43 | 1 | $importer = new Importer(); |
|
| 44 | 1 | $transactions = $importer->import($path); |
|
| 45 | 1 | _em()->flush(); |
|
| 46 | |||
| 47 | 1 | return $transactions; |
|
| 48 | 1 | }, |
|
| 52 |