1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* nextCloud - ocr |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Janis Koehr <[email protected]> |
9
|
|
|
* @copyright Janis Koehr 2017 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Ocr\Command; |
13
|
|
|
|
14
|
|
|
use Exception; |
15
|
|
|
use OCA\Ocr\Service\OcrService; |
16
|
|
|
use OCA\Ocr\Service\ServiceException; |
17
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
18
|
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException; |
19
|
|
|
use OCP\ILogger; |
20
|
|
|
use Symfony\Component\Console\Command\Command; |
21
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
22
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class CompleteOCR |
27
|
|
|
* |
28
|
|
|
* @package OCA\Ocr\Command |
29
|
|
|
*/ |
30
|
|
|
class CompleteOCR extends Command { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var OcrService |
34
|
|
|
*/ |
35
|
|
|
private $ocrService; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* UpdateStatus constructor. |
39
|
|
|
*/ |
40
|
3 |
|
public function __construct(OcrService $ocrService) { |
41
|
3 |
|
parent::__construct(); |
42
|
3 |
|
$this->ocrService = $ocrService; |
43
|
3 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Required Arguments configuration |
47
|
|
|
*/ |
48
|
3 |
|
protected function configure() { |
49
|
3 |
|
$this->setName('ocr:complete') |
50
|
3 |
|
->addArgument( |
51
|
3 |
|
'status-id', |
52
|
3 |
|
InputArgument::REQUIRED, |
53
|
|
|
'status id, integer' |
54
|
3 |
|
) |
55
|
3 |
|
->addArgument( |
56
|
3 |
|
'failed', |
57
|
3 |
|
InputArgument::REQUIRED, |
58
|
|
|
'failed, boolean' |
59
|
3 |
|
) |
60
|
3 |
|
->addArgument( |
61
|
3 |
|
'error-message', |
62
|
3 |
|
InputArgument::OPTIONAL, |
63
|
|
|
'error message, string' |
64
|
3 |
|
) |
65
|
3 |
|
->setDescription('Console API for completion of the ocr processing of a file'); |
66
|
3 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Executes the complete function of the OCRService |
70
|
|
|
* |
71
|
|
|
* @param InputInterface $input |
72
|
|
|
* @param OutputInterface $output |
73
|
|
|
* @return int|null|void |
74
|
|
|
*/ |
75
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
76
|
|
|
$statusId = $input->getArgument('status-id'); |
77
|
|
|
$failed = $input->getArgument('failed'); |
78
|
|
|
$errorMessage = $input->getArgument('error-message'); |
79
|
|
|
try { |
80
|
|
|
if ($failed === 'false') { |
81
|
|
|
$failed = false; |
82
|
|
|
} elseif ($failed === 'true') { |
83
|
|
|
$failed = true; |
84
|
|
|
$errorMessage = null; |
85
|
|
|
} else { |
86
|
|
|
throw new ServiceException('Wrong Arguments.'); |
87
|
|
|
} |
88
|
|
|
$this->ocrService->complete($statusId, $failed, $errorMessage); |
89
|
|
|
} catch (Exception $e) { |
90
|
|
|
if ($e instanceof MultipleObjectsReturnedException || $e instanceof DoesNotExistException) { |
91
|
|
|
$output->writeln('<error>Could not complete ocr for status id ' . $statusId . |
92
|
|
|
': ' . $e->getMessage() . |
93
|
|
|
'</error> '); |
94
|
|
|
} else { |
95
|
|
|
$output->writeln('<error>Unexpected error for status id ' . $statusId . |
96
|
|
|
': ' . $e->getMessage() . |
97
|
|
|
'</error> '); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |