@@ -23,94 +23,94 @@ |
||
23 | 23 | */ |
24 | 24 | class StatusService { |
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * @var ILogger |
|
29 | - */ |
|
30 | - private $logger; |
|
26 | + /** |
|
27 | + * |
|
28 | + * @var ILogger |
|
29 | + */ |
|
30 | + private $logger; |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @var String |
|
35 | - */ |
|
36 | - private $userId; |
|
32 | + /** |
|
33 | + * |
|
34 | + * @var String |
|
35 | + */ |
|
36 | + private $userId; |
|
37 | 37 | |
38 | - /** |
|
39 | - * |
|
40 | - * @var IL10N |
|
41 | - */ |
|
42 | - private $l10n; |
|
38 | + /** |
|
39 | + * |
|
40 | + * @var IL10N |
|
41 | + */ |
|
42 | + private $l10n; |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * @var OcrJobMapper |
|
47 | - */ |
|
48 | - private $jobMapper; |
|
44 | + /** |
|
45 | + * |
|
46 | + * @var OcrJobMapper |
|
47 | + */ |
|
48 | + private $jobMapper; |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * @var JobService |
|
53 | - */ |
|
54 | - private $jobService; |
|
50 | + /** |
|
51 | + * |
|
52 | + * @var JobService |
|
53 | + */ |
|
54 | + private $jobService; |
|
55 | 55 | |
56 | - /** |
|
57 | - * StatusService constructor. |
|
58 | - * |
|
59 | - * @param IL10N $l10n |
|
60 | - * @param ILogger $logger |
|
61 | - * @param unknown $userId |
|
62 | - * @param OcrJobMapper $mapper |
|
63 | - * @param JobService $jobService |
|
64 | - */ |
|
65 | - public function __construct(IL10N $l10n, ILogger $logger, $userId, OcrJobMapper $mapper, JobService $jobService) { |
|
66 | - $this->logger = $logger; |
|
67 | - $this->jobMapper = $mapper; |
|
68 | - $this->userId = $userId; |
|
69 | - $this->l10n = $l10n; |
|
70 | - $this->jobService = $jobService; |
|
71 | - } |
|
56 | + /** |
|
57 | + * StatusService constructor. |
|
58 | + * |
|
59 | + * @param IL10N $l10n |
|
60 | + * @param ILogger $logger |
|
61 | + * @param unknown $userId |
|
62 | + * @param OcrJobMapper $mapper |
|
63 | + * @param JobService $jobService |
|
64 | + */ |
|
65 | + public function __construct(IL10N $l10n, ILogger $logger, $userId, OcrJobMapper $mapper, JobService $jobService) { |
|
66 | + $this->logger = $logger; |
|
67 | + $this->jobMapper = $mapper; |
|
68 | + $this->userId = $userId; |
|
69 | + $this->l10n = $l10n; |
|
70 | + $this->jobService = $jobService; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * A function which returns the JSONResponse for all required status checks and tasks. |
|
75 | - * It will check for already processed, pending and failed ocr tasks and return them as needed. |
|
76 | - * @codeCoverageIgnore |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function getStatus() { |
|
81 | - try { |
|
82 | - // TODO: For now this will be placed in the regular check, but in the future this could be done in another |
|
83 | - // way |
|
84 | - $this->jobService->checkForFinishedJobs(); |
|
85 | - // returns user specific processed files |
|
86 | - $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
87 | - $this->jobService->handleProcessed(); |
|
88 | - // return user specific pending state |
|
89 | - $pending = $this->jobMapper->findAllPending($this->userId); |
|
90 | - // return user specific failed state and set up error |
|
91 | - $failed = $this->jobMapper->findAllFailed($this->userId); |
|
92 | - $this->jobService->handleFailed(); |
|
93 | - return [ |
|
94 | - 'processed' => count($processed), |
|
95 | - 'failed' => count($failed), |
|
96 | - 'pending' => count($pending) |
|
97 | - ]; |
|
98 | - } catch (Exception $e) { |
|
99 | - $this->handleException($e); |
|
100 | - } |
|
101 | - } |
|
73 | + /** |
|
74 | + * A function which returns the JSONResponse for all required status checks and tasks. |
|
75 | + * It will check for already processed, pending and failed ocr tasks and return them as needed. |
|
76 | + * @codeCoverageIgnore |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function getStatus() { |
|
81 | + try { |
|
82 | + // TODO: For now this will be placed in the regular check, but in the future this could be done in another |
|
83 | + // way |
|
84 | + $this->jobService->checkForFinishedJobs(); |
|
85 | + // returns user specific processed files |
|
86 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
87 | + $this->jobService->handleProcessed(); |
|
88 | + // return user specific pending state |
|
89 | + $pending = $this->jobMapper->findAllPending($this->userId); |
|
90 | + // return user specific failed state and set up error |
|
91 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
92 | + $this->jobService->handleFailed(); |
|
93 | + return [ |
|
94 | + 'processed' => count($processed), |
|
95 | + 'failed' => count($failed), |
|
96 | + 'pending' => count($pending) |
|
97 | + ]; |
|
98 | + } catch (Exception $e) { |
|
99 | + $this->handleException($e); |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Handle the possible thrown Exceptions from all methods of this class. |
|
105 | - * |
|
106 | - * @param Exception $e |
|
107 | - * @throws Exception |
|
108 | - * @throws NotFoundException |
|
109 | - */ |
|
110 | - private function handleException($e) { |
|
111 | - $this->logger->logException($e, [ |
|
112 | - 'message' => 'Exception during status service function processing' |
|
113 | - ]); |
|
114 | - throw $e; |
|
115 | - } |
|
103 | + /** |
|
104 | + * Handle the possible thrown Exceptions from all methods of this class. |
|
105 | + * |
|
106 | + * @param Exception $e |
|
107 | + * @throws Exception |
|
108 | + * @throws NotFoundException |
|
109 | + */ |
|
110 | + private function handleException($e) { |
|
111 | + $this->logger->logException($e, [ |
|
112 | + 'message' => 'Exception during status service function processing' |
|
113 | + ]); |
|
114 | + throw $e; |
|
115 | + } |
|
116 | 116 | } |
117 | 117 | \ No newline at end of file |
@@ -13,118 +13,118 @@ |
||
13 | 13 | |
14 | 14 | abstract class OcrConstants { |
15 | 15 | |
16 | - /** |
|
17 | - * The pending status. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const STATUS_PENDING = 'PENDING'; |
|
22 | - |
|
23 | - /** |
|
24 | - * The processed status. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const STATUS_PROCESSED = 'PROCESSED'; |
|
29 | - |
|
30 | - /** |
|
31 | - * The failed status. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - const STATUS_FAILED = 'FAILED'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Supported MIME types for OCR processing. |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - const ALLOWED_MIME_TYPES = [ |
|
43 | - 'application/pdf', |
|
44 | - 'image/png', |
|
45 | - 'image/jpeg', |
|
46 | - 'image/tiff', |
|
47 | - 'image/jp2', |
|
48 | - 'image/jpm', |
|
49 | - 'image/jpx', |
|
50 | - 'image/webp', |
|
51 | - 'image/gif' |
|
52 | - ]; |
|
53 | - |
|
54 | - /** |
|
55 | - * The correct MIME type for a PDF file. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - const MIME_TYPE_PDF = 'application/pdf'; |
|
60 | - |
|
61 | - /** |
|
62 | - * The type of a job (OCRmyPDF). |
|
63 | - * |
|
64 | - * @var integer |
|
65 | - */ |
|
66 | - const OCRmyPDF = 1; |
|
67 | - |
|
68 | - /** |
|
69 | - * The type of a job (Tesseract). |
|
70 | - * |
|
71 | - * @var integer |
|
72 | - */ |
|
73 | - const TESSERACT = 0; |
|
74 | - |
|
75 | - /** |
|
76 | - * The name of the message queue that waits for now jobs. |
|
77 | - * |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - const REDIS_NEW_JOBS_QUEUE = 'incoming'; |
|
81 | - |
|
82 | - /** |
|
83 | - * The name of the message queue that waits for finished jobs. |
|
84 | - * |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - const REDIS_FINISHED_JOBS_QUEUE = 'finished'; |
|
88 | - |
|
89 | - /** |
|
90 | - * The name of the languages config key. |
|
91 | - * |
|
92 | - * @var string |
|
93 | - */ |
|
94 | - const LANGUAGES_CONFIG_KEY = 'languages'; |
|
95 | - |
|
96 | - /** |
|
97 | - * The name of the redis host config key. |
|
98 | - * |
|
99 | - * @var string |
|
100 | - */ |
|
101 | - const REDIS_CONFIG_KEY_HOST = 'redisHost'; |
|
102 | - |
|
103 | - /** |
|
104 | - * The name of the redis port config key. |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - const REDIS_CONFIG_KEY_PORT = 'redisPort'; |
|
109 | - |
|
110 | - /** |
|
111 | - * The name of the redis db config key. |
|
112 | - * |
|
113 | - * @var string |
|
114 | - */ |
|
115 | - const REDIS_CONFIG_KEY_DB = 'redisDb'; |
|
116 | - |
|
117 | - /** |
|
118 | - * The prefix for the redis key. |
|
119 | - * |
|
120 | - * @var string |
|
121 | - */ |
|
122 | - const REDIS_KEY_PREFIX = 'ocr:'; |
|
123 | - |
|
124 | - /** |
|
125 | - * The prefix for the tempfiles that are created. |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - const TEMPFILE_PREFIX = 'ocr_'; |
|
16 | + /** |
|
17 | + * The pending status. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const STATUS_PENDING = 'PENDING'; |
|
22 | + |
|
23 | + /** |
|
24 | + * The processed status. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const STATUS_PROCESSED = 'PROCESSED'; |
|
29 | + |
|
30 | + /** |
|
31 | + * The failed status. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + const STATUS_FAILED = 'FAILED'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Supported MIME types for OCR processing. |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + const ALLOWED_MIME_TYPES = [ |
|
43 | + 'application/pdf', |
|
44 | + 'image/png', |
|
45 | + 'image/jpeg', |
|
46 | + 'image/tiff', |
|
47 | + 'image/jp2', |
|
48 | + 'image/jpm', |
|
49 | + 'image/jpx', |
|
50 | + 'image/webp', |
|
51 | + 'image/gif' |
|
52 | + ]; |
|
53 | + |
|
54 | + /** |
|
55 | + * The correct MIME type for a PDF file. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + const MIME_TYPE_PDF = 'application/pdf'; |
|
60 | + |
|
61 | + /** |
|
62 | + * The type of a job (OCRmyPDF). |
|
63 | + * |
|
64 | + * @var integer |
|
65 | + */ |
|
66 | + const OCRmyPDF = 1; |
|
67 | + |
|
68 | + /** |
|
69 | + * The type of a job (Tesseract). |
|
70 | + * |
|
71 | + * @var integer |
|
72 | + */ |
|
73 | + const TESSERACT = 0; |
|
74 | + |
|
75 | + /** |
|
76 | + * The name of the message queue that waits for now jobs. |
|
77 | + * |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + const REDIS_NEW_JOBS_QUEUE = 'incoming'; |
|
81 | + |
|
82 | + /** |
|
83 | + * The name of the message queue that waits for finished jobs. |
|
84 | + * |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + const REDIS_FINISHED_JOBS_QUEUE = 'finished'; |
|
88 | + |
|
89 | + /** |
|
90 | + * The name of the languages config key. |
|
91 | + * |
|
92 | + * @var string |
|
93 | + */ |
|
94 | + const LANGUAGES_CONFIG_KEY = 'languages'; |
|
95 | + |
|
96 | + /** |
|
97 | + * The name of the redis host config key. |
|
98 | + * |
|
99 | + * @var string |
|
100 | + */ |
|
101 | + const REDIS_CONFIG_KEY_HOST = 'redisHost'; |
|
102 | + |
|
103 | + /** |
|
104 | + * The name of the redis port config key. |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + const REDIS_CONFIG_KEY_PORT = 'redisPort'; |
|
109 | + |
|
110 | + /** |
|
111 | + * The name of the redis db config key. |
|
112 | + * |
|
113 | + * @var string |
|
114 | + */ |
|
115 | + const REDIS_CONFIG_KEY_DB = 'redisDb'; |
|
116 | + |
|
117 | + /** |
|
118 | + * The prefix for the redis key. |
|
119 | + * |
|
120 | + * @var string |
|
121 | + */ |
|
122 | + const REDIS_KEY_PREFIX = 'ocr:'; |
|
123 | + |
|
124 | + /** |
|
125 | + * The prefix for the tempfiles that are created. |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + const TEMPFILE_PREFIX = 'ocr_'; |
|
130 | 130 | } |
131 | 131 | \ No newline at end of file |
@@ -18,51 +18,51 @@ |
||
18 | 18 | |
19 | 19 | class Admin implements ISettings { |
20 | 20 | |
21 | - /** @var IConfig */ |
|
22 | - private $config; |
|
21 | + /** @var IConfig */ |
|
22 | + private $config; |
|
23 | 23 | |
24 | - /** |
|
25 | - * |
|
26 | - * @param IConfig $config |
|
27 | - */ |
|
28 | - public function __construct(IConfig $config) { |
|
29 | - $this->config = $config; |
|
30 | - } |
|
24 | + /** |
|
25 | + * |
|
26 | + * @param IConfig $config |
|
27 | + */ |
|
28 | + public function __construct(IConfig $config) { |
|
29 | + $this->config = $config; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @return TemplateResponse |
|
35 | - */ |
|
36 | - public function getForm() { |
|
37 | - return new TemplateResponse('ocr', 'settings-admin', |
|
38 | - [ |
|
39 | - OcrConstants::LANGUAGES_CONFIG_KEY => $this->config->getAppValue('ocr', |
|
40 | - OcrConstants::LANGUAGES_CONFIG_KEY), |
|
41 | - OcrConstants::REDIS_CONFIG_KEY_HOST => $this->config->getAppValue('ocr', |
|
42 | - OcrConstants::REDIS_CONFIG_KEY_HOST), |
|
43 | - OcrConstants::REDIS_CONFIG_KEY_PORT => $this->config->getAppValue('ocr', |
|
44 | - OcrConstants::REDIS_CONFIG_KEY_PORT), |
|
45 | - OcrConstants::REDIS_CONFIG_KEY_DB => $this->config->getAppValue('ocr', |
|
46 | - OcrConstants::REDIS_CONFIG_KEY_DB) |
|
47 | - ], 'blank'); |
|
48 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * @return TemplateResponse |
|
35 | + */ |
|
36 | + public function getForm() { |
|
37 | + return new TemplateResponse('ocr', 'settings-admin', |
|
38 | + [ |
|
39 | + OcrConstants::LANGUAGES_CONFIG_KEY => $this->config->getAppValue('ocr', |
|
40 | + OcrConstants::LANGUAGES_CONFIG_KEY), |
|
41 | + OcrConstants::REDIS_CONFIG_KEY_HOST => $this->config->getAppValue('ocr', |
|
42 | + OcrConstants::REDIS_CONFIG_KEY_HOST), |
|
43 | + OcrConstants::REDIS_CONFIG_KEY_PORT => $this->config->getAppValue('ocr', |
|
44 | + OcrConstants::REDIS_CONFIG_KEY_PORT), |
|
45 | + OcrConstants::REDIS_CONFIG_KEY_DB => $this->config->getAppValue('ocr', |
|
46 | + OcrConstants::REDIS_CONFIG_KEY_DB) |
|
47 | + ], 'blank'); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * @return string the section ID, e.g. 'sharing' |
|
53 | - */ |
|
54 | - public function getSection() { |
|
55 | - return 'ocr'; |
|
56 | - } |
|
50 | + /** |
|
51 | + * |
|
52 | + * @return string the section ID, e.g. 'sharing' |
|
53 | + */ |
|
54 | + public function getSection() { |
|
55 | + return 'ocr'; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * |
|
60 | - * @return int whether the form should be rather on the top or bottom of |
|
61 | - * the admin section. The forms are arranged in ascending order of the |
|
62 | - * priority values. It is required to return a value between 0 and 100. |
|
63 | - * keep the server setting at the top, right after "server settings" |
|
64 | - */ |
|
65 | - public function getPriority() { |
|
66 | - return 0; |
|
67 | - } |
|
58 | + /** |
|
59 | + * |
|
60 | + * @return int whether the form should be rather on the top or bottom of |
|
61 | + * the admin section. The forms are arranged in ascending order of the |
|
62 | + * priority values. It is required to return a value between 0 and 100. |
|
63 | + * keep the server setting at the top, right after "server settings" |
|
64 | + */ |
|
65 | + public function getPriority() { |
|
66 | + return 0; |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | \ No newline at end of file |
@@ -16,50 +16,50 @@ |
||
16 | 16 | |
17 | 17 | class Section implements IIconSection { |
18 | 18 | |
19 | - /** @var IL10N */ |
|
20 | - private $l; |
|
19 | + /** @var IL10N */ |
|
20 | + private $l; |
|
21 | 21 | |
22 | - /** |
|
23 | - * |
|
24 | - * @param IL10N $l |
|
25 | - */ |
|
26 | - public function __construct(IL10N $l) { |
|
27 | - $this->l = $l; |
|
28 | - } |
|
22 | + /** |
|
23 | + * |
|
24 | + * @param IL10N $l |
|
25 | + */ |
|
26 | + public function __construct(IL10N $l) { |
|
27 | + $this->l = $l; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * |
|
32 | - * {@inheritdoc} |
|
33 | - * |
|
34 | - */ |
|
35 | - public function getID() { |
|
36 | - return 'ocr'; |
|
37 | - } |
|
30 | + /** |
|
31 | + * |
|
32 | + * {@inheritdoc} |
|
33 | + * |
|
34 | + */ |
|
35 | + public function getID() { |
|
36 | + return 'ocr'; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * |
|
41 | - * {@inheritdoc} |
|
42 | - * |
|
43 | - */ |
|
44 | - public function getName() { |
|
45 | - return $this->l->t('OCR'); |
|
46 | - } |
|
39 | + /** |
|
40 | + * |
|
41 | + * {@inheritdoc} |
|
42 | + * |
|
43 | + */ |
|
44 | + public function getName() { |
|
45 | + return $this->l->t('OCR'); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * |
|
50 | - * {@inheritdoc} |
|
51 | - * |
|
52 | - */ |
|
53 | - public function getPriority() { |
|
54 | - return 75; |
|
55 | - } |
|
48 | + /** |
|
49 | + * |
|
50 | + * {@inheritdoc} |
|
51 | + * |
|
52 | + */ |
|
53 | + public function getPriority() { |
|
54 | + return 75; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * |
|
59 | - * {@inheritdoc} |
|
60 | - * |
|
61 | - */ |
|
62 | - public function getIcon() { |
|
63 | - return '/apps/ocr/img/icon/ocr.svg'; |
|
64 | - } |
|
57 | + /** |
|
58 | + * |
|
59 | + * {@inheritdoc} |
|
60 | + * |
|
61 | + */ |
|
62 | + public function getIcon() { |
|
63 | + return '/apps/ocr/img/icon/ocr.svg'; |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | \ No newline at end of file |