1 | <?php |
||
32 | class JobService { |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | * @var ILogger |
||
37 | */ |
||
38 | private $logger; |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @var RedisService |
||
43 | */ |
||
44 | private $redisService; |
||
45 | |||
46 | /** |
||
47 | * |
||
48 | * @var OcrJobMapper |
||
49 | */ |
||
50 | private $jobMapper; |
||
51 | |||
52 | /** |
||
53 | * |
||
54 | * @var View |
||
55 | */ |
||
56 | private $view; |
||
57 | |||
58 | /** |
||
59 | * |
||
60 | * @var String |
||
61 | */ |
||
62 | private $userId; |
||
63 | |||
64 | /** |
||
65 | * |
||
66 | * @var IL10N |
||
67 | */ |
||
68 | private $l10n; |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | * @var FileService |
||
73 | */ |
||
74 | private $fileService; |
||
75 | |||
76 | /** |
||
77 | * |
||
78 | * @var ITempManager |
||
79 | */ |
||
80 | private $tempM; |
||
81 | |||
82 | /** |
||
83 | * |
||
84 | * @var AppConfigService |
||
85 | */ |
||
86 | private $appConfigService; |
||
87 | |||
88 | /** |
||
89 | * |
||
90 | * @var PHPUtil |
||
91 | */ |
||
92 | private $phpUtil; |
||
93 | |||
94 | /** |
||
95 | * |
||
96 | * @var FileUtil |
||
97 | */ |
||
98 | private $fileUtil; |
||
99 | |||
100 | /** |
||
101 | * JobService constructor. |
||
102 | * |
||
103 | * @param IL10N $l10n |
||
104 | * @param ILogger $logger |
||
105 | * @param string $userId |
||
106 | * @param View $view |
||
107 | * @param RedisService $queueService |
||
108 | * @param OcrJobMapper $mapper |
||
109 | * @param FileService $fileService |
||
110 | * @param AppConfigService $appConfigService |
||
111 | * @param PHPUtil $phpUtil |
||
112 | * @param FileUtil $fileUtil |
||
113 | */ |
||
114 | 22 | public function __construct(IL10N $l10n, ILogger $logger, $userId, View $view, ITempManager $tempManager, |
|
129 | |||
130 | /** |
||
131 | * Processes and prepares the files for OCR. |
||
132 | * Sends the stuff to the client in order to OCR async. |
||
133 | * |
||
134 | * @param string[] $languages |
||
135 | * @param array $files |
||
136 | * @return string |
||
137 | */ |
||
138 | 9 | public function process($languages, $files) { |
|
178 | |||
179 | /** |
||
180 | * Delete an ocr job for a given id and userId. |
||
181 | * |
||
182 | * @param |
||
183 | * $jobId |
||
184 | * @param string $userId |
||
185 | * @return OcrJob |
||
186 | */ |
||
187 | 3 | public function deleteJob($jobId, $userId) { |
|
213 | |||
214 | /** |
||
215 | * Gets all job objects for a specific user. |
||
216 | * |
||
217 | * @param string $userId |
||
218 | * @return OcrJob[] |
||
219 | */ |
||
220 | 1 | public function getAllJobsForUser($userId) { |
|
238 | |||
239 | /** |
||
240 | * The function checks if there are finished jobs to process finally. |
||
241 | * |
||
242 | * @throws NotFoundException |
||
243 | */ |
||
244 | 2 | public function checkForFinishedJobs() { |
|
259 | |||
260 | /** |
||
261 | * Finishes all Processed files by copying them to the right path and deleteing the temp files. |
||
262 | * Returns the number of processed files. |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | 2 | public function handleProcessed() { |
|
289 | |||
290 | /** |
||
291 | * Handles all failed orders of ocr processing queue and returns the job objects. |
||
292 | * |
||
293 | * @return array |
||
294 | */ |
||
295 | 1 | public function handleFailed() { |
|
314 | |||
315 | /** |
||
316 | * The function the worker will call in order to set the jobs status. |
||
317 | * The worker should call it automatically after each processing step. |
||
318 | * |
||
319 | * @param integer $jobId |
||
320 | * @param boolean $error |
||
321 | * @param string $log |
||
322 | */ |
||
323 | 1 | private function jobFinished($jobId, $error, $log) { |
|
339 | |||
340 | /** |
||
341 | * Gives a temp file name back depending on the type of the OCR. |
||
342 | * Later in the worker this file is used as an output. |
||
343 | * |
||
344 | * @param integer $type |
||
345 | * @return string |
||
346 | */ |
||
347 | 6 | private function getTempFile($type) { |
|
359 | |||
360 | /** |
||
361 | * Takes care of transforming an incoming finished job into a php readable object. |
||
362 | * |
||
363 | * @param string $job |
||
364 | * @throws NotFoundException |
||
365 | * @return mixed |
||
366 | */ |
||
367 | 1 | private function transformJob($job) { |
|
376 | |||
377 | /** |
||
378 | * Checks if the given languages are supported or not. |
||
379 | * |
||
380 | * @param string[] $languages |
||
381 | * @return boolean |
||
382 | */ |
||
383 | 8 | private function checkForAcceptedLanguages($languages) { |
|
391 | |||
392 | /** |
||
393 | * Checks if the process should be initiated without any language specified. |
||
394 | * |
||
395 | * @param string[] $languages |
||
396 | * @return boolean |
||
397 | */ |
||
398 | 9 | private function noLanguage($languages) { |
|
405 | |||
406 | /** |
||
407 | * Handle the possible thrown Exceptions from all methods of this class. |
||
408 | * |
||
409 | * @param Exception $e |
||
410 | * @throws Exception |
||
411 | * @throws NotFoundException |
||
412 | */ |
||
413 | 10 | private function handleException($e) { |
|
420 | } |