@@ -22,88 +22,88 @@ |
||
22 | 22 | */ |
23 | 23 | class PHPUtil { |
24 | 24 | |
25 | - /** |
|
26 | - * |
|
27 | - * @var ILogger |
|
28 | - */ |
|
29 | - private $logger; |
|
25 | + /** |
|
26 | + * |
|
27 | + * @var ILogger |
|
28 | + */ |
|
29 | + private $logger; |
|
30 | 30 | |
31 | - /** |
|
32 | - * |
|
33 | - * @var IL10N |
|
34 | - */ |
|
35 | - private $l10n; |
|
31 | + /** |
|
32 | + * |
|
33 | + * @var IL10N |
|
34 | + */ |
|
35 | + private $l10n; |
|
36 | 36 | |
37 | - public function __construct(IL10N $l10n, ILogger $logger) { |
|
38 | - $this->l10n = $l10n; |
|
39 | - $this->logger = $logger; |
|
40 | - } |
|
37 | + public function __construct(IL10N $l10n, ILogger $logger) { |
|
38 | + $this->l10n = $l10n; |
|
39 | + $this->logger = $logger; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Wraps the php native function tempnam() |
|
44 | - * @codeCoverageIgnore |
|
45 | - * |
|
46 | - * @param string $dir |
|
47 | - * @param string $prefix |
|
48 | - * @throws NotFoundException |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function tempnamWrapper($dir, $prefix) { |
|
52 | - $tempFile = tempnam($dir, $prefix); |
|
53 | - if ($tempFile === false) { |
|
54 | - throw new NotFoundException($this->l10n->t('Temp file cannot be created.')); |
|
55 | - } else { |
|
56 | - return $tempFile; |
|
57 | - } |
|
58 | - } |
|
42 | + /** |
|
43 | + * Wraps the php native function tempnam() |
|
44 | + * @codeCoverageIgnore |
|
45 | + * |
|
46 | + * @param string $dir |
|
47 | + * @param string $prefix |
|
48 | + * @throws NotFoundException |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function tempnamWrapper($dir, $prefix) { |
|
52 | + $tempFile = tempnam($dir, $prefix); |
|
53 | + if ($tempFile === false) { |
|
54 | + throw new NotFoundException($this->l10n->t('Temp file cannot be created.')); |
|
55 | + } else { |
|
56 | + return $tempFile; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Wraps the php native function unlink() |
|
62 | - * @codeCoverageIgnore |
|
63 | - * |
|
64 | - * @param string $fileName |
|
65 | - * @throws NotFoundException |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function unlinkWrapper($fileName) { |
|
69 | - if (unlink($fileName)) { |
|
70 | - return true; |
|
71 | - } else { |
|
72 | - throw new NotFoundException( |
|
73 | - $this->l10n->t('Cannot delete temporary file during temp file creation for tesseract.')); |
|
74 | - } |
|
75 | - } |
|
60 | + /** |
|
61 | + * Wraps the php native function unlink() |
|
62 | + * @codeCoverageIgnore |
|
63 | + * |
|
64 | + * @param string $fileName |
|
65 | + * @throws NotFoundException |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function unlinkWrapper($fileName) { |
|
69 | + if (unlink($fileName)) { |
|
70 | + return true; |
|
71 | + } else { |
|
72 | + throw new NotFoundException( |
|
73 | + $this->l10n->t('Cannot delete temporary file during temp file creation for tesseract.')); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Wraps the php native function touch() |
|
79 | - * @codeCoverageIgnore |
|
80 | - * |
|
81 | - * @param string $fileName |
|
82 | - * @throws NotFoundException |
|
83 | - * @return boolean |
|
84 | - */ |
|
85 | - public function touchWrapper($fileName) { |
|
86 | - if (touch($fileName)) { |
|
87 | - return true; |
|
88 | - } else { |
|
89 | - throw new NotFoundException($this->l10n->t('Cannot create temporary file for tesseract.')); |
|
90 | - } |
|
91 | - } |
|
77 | + /** |
|
78 | + * Wraps the php native function touch() |
|
79 | + * @codeCoverageIgnore |
|
80 | + * |
|
81 | + * @param string $fileName |
|
82 | + * @throws NotFoundException |
|
83 | + * @return boolean |
|
84 | + */ |
|
85 | + public function touchWrapper($fileName) { |
|
86 | + if (touch($fileName)) { |
|
87 | + return true; |
|
88 | + } else { |
|
89 | + throw new NotFoundException($this->l10n->t('Cannot create temporary file for tesseract.')); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Wraps the php native function chmod() |
|
95 | - * @codeCoverageIgnore |
|
96 | - * |
|
97 | - * @param string $fileName |
|
98 | - * @param integer $mode |
|
99 | - * @throws NotFoundException |
|
100 | - * @return boolean |
|
101 | - */ |
|
102 | - public function chmodWrapper($fileName, $mode) { |
|
103 | - if (chmod($fileName, $mode)) { |
|
104 | - return true; |
|
105 | - } else { |
|
106 | - throw new NotFoundException($this->l10n->t('Cannot set permissions to temporary file for tesseract.')); |
|
107 | - } |
|
108 | - } |
|
93 | + /** |
|
94 | + * Wraps the php native function chmod() |
|
95 | + * @codeCoverageIgnore |
|
96 | + * |
|
97 | + * @param string $fileName |
|
98 | + * @param integer $mode |
|
99 | + * @throws NotFoundException |
|
100 | + * @return boolean |
|
101 | + */ |
|
102 | + public function chmodWrapper($fileName, $mode) { |
|
103 | + if (chmod($fileName, $mode)) { |
|
104 | + return true; |
|
105 | + } else { |
|
106 | + throw new NotFoundException($this->l10n->t('Cannot set permissions to temporary file for tesseract.')); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -17,42 +17,42 @@ |
||
17 | 17 | |
18 | 18 | class DropOldTable implements IRepairStep { |
19 | 19 | |
20 | - /** @var IDBConnection */ |
|
21 | - protected $connection; |
|
22 | - |
|
23 | - /** |
|
24 | - * |
|
25 | - * @param IDBConnection $connection |
|
26 | - */ |
|
27 | - public function __construct(IDBConnection $connection) { |
|
28 | - $this->connection = $connection; |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Returns the step's name |
|
33 | - * |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getName() { |
|
37 | - return 'Drop old database table'; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Run repair step. |
|
42 | - * Must throw exception on error. |
|
43 | - * |
|
44 | - * @throws \Exception in case of failure |
|
45 | - */ |
|
46 | - public function run(IOutput $output) { |
|
47 | - $output->startProgress(1); |
|
48 | - if ($this->connection->tableExists('ocr_jobs')) { |
|
49 | - $this->connection->dropTable('ocr_jobs'); |
|
50 | - } |
|
51 | - // still needed for downwards compatibility |
|
52 | - if ($this->connection->tableExists('ocr_status')) { |
|
53 | - $this->connection->dropTable('ocr_status'); |
|
54 | - } |
|
55 | - $output->advance(1, "Drop old database table: ocr_jobs"); |
|
56 | - $output->finishProgress(); |
|
57 | - } |
|
20 | + /** @var IDBConnection */ |
|
21 | + protected $connection; |
|
22 | + |
|
23 | + /** |
|
24 | + * |
|
25 | + * @param IDBConnection $connection |
|
26 | + */ |
|
27 | + public function __construct(IDBConnection $connection) { |
|
28 | + $this->connection = $connection; |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Returns the step's name |
|
33 | + * |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getName() { |
|
37 | + return 'Drop old database table'; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Run repair step. |
|
42 | + * Must throw exception on error. |
|
43 | + * |
|
44 | + * @throws \Exception in case of failure |
|
45 | + */ |
|
46 | + public function run(IOutput $output) { |
|
47 | + $output->startProgress(1); |
|
48 | + if ($this->connection->tableExists('ocr_jobs')) { |
|
49 | + $this->connection->dropTable('ocr_jobs'); |
|
50 | + } |
|
51 | + // still needed for downwards compatibility |
|
52 | + if ($this->connection->tableExists('ocr_status')) { |
|
53 | + $this->connection->dropTable('ocr_status'); |
|
54 | + } |
|
55 | + $output->advance(1, "Drop old database table: ocr_jobs"); |
|
56 | + $output->finishProgress(); |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -17,23 +17,23 @@ |
||
17 | 17 | |
18 | 18 | class PersonalSettingsController extends Controller { |
19 | 19 | |
20 | - /** |
|
21 | - * PersonalSettingsController constructor. |
|
22 | - * |
|
23 | - * @param string $AppName |
|
24 | - * @param IRequest $request |
|
25 | - */ |
|
26 | - public function __construct($AppName, IRequest $request) { |
|
27 | - parent::__construct($AppName, $request); |
|
28 | - } |
|
20 | + /** |
|
21 | + * PersonalSettingsController constructor. |
|
22 | + * |
|
23 | + * @param string $AppName |
|
24 | + * @param IRequest $request |
|
25 | + */ |
|
26 | + public function __construct($AppName, IRequest $request) { |
|
27 | + parent::__construct($AppName, $request); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @NoAdminRequired |
|
32 | - * |
|
33 | - * @return Template |
|
34 | - */ |
|
35 | - public function displayPanel() { |
|
36 | - $tmpl = new Template('ocr', 'settings-personal'); |
|
37 | - return $tmpl; |
|
38 | - } |
|
30 | + /** |
|
31 | + * @NoAdminRequired |
|
32 | + * |
|
33 | + * @return Template |
|
34 | + */ |
|
35 | + public function displayPanel() { |
|
36 | + $tmpl = new Template('ocr', 'settings-personal'); |
|
37 | + return $tmpl; |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -23,18 +23,18 @@ |
||
23 | 23 | */ |
24 | 24 | trait Errors { |
25 | 25 | |
26 | - /** |
|
27 | - * handles the thrown Errors for all Controllers |
|
28 | - * and sends a DataResponse with the ErrorMessage of the service |
|
29 | - * |
|
30 | - * @param Closure $callback |
|
31 | - * @return DataResponse |
|
32 | - */ |
|
33 | - protected function handleNotFound(Closure $callback) { |
|
34 | - try { |
|
35 | - return new DataResponse($callback()); |
|
36 | - } catch (NotFoundException $e) { |
|
37 | - return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); |
|
38 | - } |
|
39 | - } |
|
26 | + /** |
|
27 | + * handles the thrown Errors for all Controllers |
|
28 | + * and sends a DataResponse with the ErrorMessage of the service |
|
29 | + * |
|
30 | + * @param Closure $callback |
|
31 | + * @return DataResponse |
|
32 | + */ |
|
33 | + protected function handleNotFound(Closure $callback) { |
|
34 | + try { |
|
35 | + return new DataResponse($callback()); |
|
36 | + } catch (NotFoundException $e) { |
|
37 | + return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | \ No newline at end of file |
@@ -22,95 +22,95 @@ |
||
22 | 22 | |
23 | 23 | class AdminSettingsController extends Controller { |
24 | 24 | |
25 | - /** @var IL10N */ |
|
26 | - private $l10n; |
|
25 | + /** @var IL10N */ |
|
26 | + private $l10n; |
|
27 | 27 | |
28 | - /** @var AppConfigService */ |
|
29 | - private $appConfig; |
|
30 | - use Errors; |
|
28 | + /** @var AppConfigService */ |
|
29 | + private $appConfig; |
|
30 | + use Errors; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param string $appName |
|
36 | - * @param IRequest $request |
|
37 | - * @param IL10N $l10n |
|
38 | - * @param AppConfigService $appConfig |
|
39 | - * @param string $userId |
|
40 | - */ |
|
41 | - public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) { |
|
42 | - parent::__construct($appName, $request); |
|
43 | - $this->l10n = $l10n; |
|
44 | - $this->appConfig = $appConfig; |
|
45 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param string $appName |
|
36 | + * @param IRequest $request |
|
37 | + * @param IL10N $l10n |
|
38 | + * @param AppConfigService $appConfig |
|
39 | + * @param string $userId |
|
40 | + */ |
|
41 | + public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) { |
|
42 | + parent::__construct($appName, $request); |
|
43 | + $this->l10n = $l10n; |
|
44 | + $this->appConfig = $appConfig; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @NoAdminRequired |
|
49 | - * |
|
50 | - * @return DataResponse |
|
51 | - */ |
|
52 | - public function getLanguages() { |
|
53 | - return $this->handleNotFound( |
|
54 | - function () { |
|
55 | - return [ |
|
56 | - 'languages' => $this->appConfig->getAppValue(OcrConstants::LANGUAGES_CONFIG_KEY) |
|
57 | - ]; |
|
58 | - }); |
|
59 | - } |
|
47 | + /** |
|
48 | + * @NoAdminRequired |
|
49 | + * |
|
50 | + * @return DataResponse |
|
51 | + */ |
|
52 | + public function getLanguages() { |
|
53 | + return $this->handleNotFound( |
|
54 | + function () { |
|
55 | + return [ |
|
56 | + 'languages' => $this->appConfig->getAppValue(OcrConstants::LANGUAGES_CONFIG_KEY) |
|
57 | + ]; |
|
58 | + }); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @NoAdminRequired |
|
63 | - * |
|
64 | - * @return DataResponse |
|
65 | - */ |
|
66 | - public function evaluateRedisSettings() { |
|
67 | - return $this->handleNotFound( |
|
68 | - function () { |
|
69 | - return [ |
|
70 | - 'set' => $this->appConfig->evaluateRedisSettings() |
|
71 | - ]; |
|
72 | - }); |
|
73 | - } |
|
61 | + /** |
|
62 | + * @NoAdminRequired |
|
63 | + * |
|
64 | + * @return DataResponse |
|
65 | + */ |
|
66 | + public function evaluateRedisSettings() { |
|
67 | + return $this->handleNotFound( |
|
68 | + function () { |
|
69 | + return [ |
|
70 | + 'set' => $this->appConfig->evaluateRedisSettings() |
|
71 | + ]; |
|
72 | + }); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Sets the languages that are supported by the docker worker instance. |
|
77 | - * |
|
78 | - * @param string $languages |
|
79 | - * @return DataResponse |
|
80 | - */ |
|
81 | - public function setLanguages($languages) { |
|
82 | - return $this->handleNotFound( |
|
83 | - function () use ($languages) { |
|
84 | - if ($languages !== null) { |
|
85 | - $this->appConfig->setAppValue(OcrConstants::LANGUAGES_CONFIG_KEY, $languages); |
|
86 | - return $this->l10n->t('Saved'); |
|
87 | - } else { |
|
88 | - throw new NotFoundException( |
|
89 | - $this->l10n->t('The languages are not specified in the correct format.')); |
|
90 | - } |
|
91 | - }); |
|
92 | - } |
|
75 | + /** |
|
76 | + * Sets the languages that are supported by the docker worker instance. |
|
77 | + * |
|
78 | + * @param string $languages |
|
79 | + * @return DataResponse |
|
80 | + */ |
|
81 | + public function setLanguages($languages) { |
|
82 | + return $this->handleNotFound( |
|
83 | + function () use ($languages) { |
|
84 | + if ($languages !== null) { |
|
85 | + $this->appConfig->setAppValue(OcrConstants::LANGUAGES_CONFIG_KEY, $languages); |
|
86 | + return $this->l10n->t('Saved'); |
|
87 | + } else { |
|
88 | + throw new NotFoundException( |
|
89 | + $this->l10n->t('The languages are not specified in the correct format.')); |
|
90 | + } |
|
91 | + }); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Sets the Redis settings. |
|
96 | - * |
|
97 | - * @param string $redisHost |
|
98 | - * @param string $redisPort |
|
99 | - * @param string $redisDb |
|
100 | - * @return DataResponse |
|
101 | - */ |
|
102 | - public function setRedis($redisHost, $redisPort, $redisDb) { |
|
103 | - return $this->handleNotFound( |
|
104 | - function () use ($redisHost, $redisPort, $redisDb) { |
|
105 | - if ($redisHost !== null && $redisPort !== null && $redisDb !== null) { |
|
106 | - $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost); |
|
107 | - $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort); |
|
108 | - $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb); |
|
109 | - return $this->l10n->t('Saved'); |
|
110 | - } else { |
|
111 | - throw new NotFoundException( |
|
112 | - $this->l10n->t('The Redis settings do not have the right format.')); |
|
113 | - } |
|
114 | - }); |
|
115 | - } |
|
94 | + /** |
|
95 | + * Sets the Redis settings. |
|
96 | + * |
|
97 | + * @param string $redisHost |
|
98 | + * @param string $redisPort |
|
99 | + * @param string $redisDb |
|
100 | + * @return DataResponse |
|
101 | + */ |
|
102 | + public function setRedis($redisHost, $redisPort, $redisDb) { |
|
103 | + return $this->handleNotFound( |
|
104 | + function () use ($redisHost, $redisPort, $redisDb) { |
|
105 | + if ($redisHost !== null && $redisPort !== null && $redisDb !== null) { |
|
106 | + $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost); |
|
107 | + $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort); |
|
108 | + $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb); |
|
109 | + return $this->l10n->t('Saved'); |
|
110 | + } else { |
|
111 | + throw new NotFoundException( |
|
112 | + $this->l10n->t('The Redis settings do not have the right format.')); |
|
113 | + } |
|
114 | + }); |
|
115 | + } |
|
116 | 116 | } |
117 | 117 | \ No newline at end of file |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function getLanguages() { |
53 | 53 | return $this->handleNotFound( |
54 | - function () { |
|
54 | + function() { |
|
55 | 55 | return [ |
56 | 56 | 'languages' => $this->appConfig->getAppValue(OcrConstants::LANGUAGES_CONFIG_KEY) |
57 | 57 | ]; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function evaluateRedisSettings() { |
67 | 67 | return $this->handleNotFound( |
68 | - function () { |
|
68 | + function() { |
|
69 | 69 | return [ |
70 | 70 | 'set' => $this->appConfig->evaluateRedisSettings() |
71 | 71 | ]; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function setLanguages($languages) { |
82 | 82 | return $this->handleNotFound( |
83 | - function () use ($languages) { |
|
83 | + function() use ($languages) { |
|
84 | 84 | if ($languages !== null) { |
85 | 85 | $this->appConfig->setAppValue(OcrConstants::LANGUAGES_CONFIG_KEY, $languages); |
86 | 86 | return $this->l10n->t('Saved'); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function setRedis($redisHost, $redisPort, $redisDb) { |
103 | 103 | return $this->handleNotFound( |
104 | - function () use ($redisHost, $redisPort, $redisDb) { |
|
104 | + function() use ($redisHost, $redisPort, $redisDb) { |
|
105 | 105 | if ($redisHost !== null && $redisPort !== null && $redisDb !== null) { |
106 | 106 | $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost); |
107 | 107 | $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort); |
@@ -23,71 +23,71 @@ |
||
23 | 23 | */ |
24 | 24 | class JobController extends Controller { |
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - private $userId; |
|
26 | + /** |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + private $userId; |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @var OcrService |
|
35 | - */ |
|
36 | - private $service; |
|
37 | - use Errors; |
|
32 | + /** |
|
33 | + * |
|
34 | + * @var OcrService |
|
35 | + */ |
|
36 | + private $service; |
|
37 | + use Errors; |
|
38 | 38 | |
39 | - /** |
|
40 | - * JobController constructor. |
|
41 | - * |
|
42 | - * @param string $AppName |
|
43 | - * @param IRequest $request |
|
44 | - * @param JobService $service |
|
45 | - * @param |
|
46 | - * $UserId |
|
47 | - */ |
|
48 | - public function __construct($AppName, IRequest $request, JobService $service, $UserId) { |
|
49 | - parent::__construct($AppName, $request); |
|
50 | - $this->userId = $UserId; |
|
51 | - $this->service = $service; |
|
52 | - } |
|
39 | + /** |
|
40 | + * JobController constructor. |
|
41 | + * |
|
42 | + * @param string $AppName |
|
43 | + * @param IRequest $request |
|
44 | + * @param JobService $service |
|
45 | + * @param |
|
46 | + * $UserId |
|
47 | + */ |
|
48 | + public function __construct($AppName, IRequest $request, JobService $service, $UserId) { |
|
49 | + parent::__construct($AppName, $request); |
|
50 | + $this->userId = $UserId; |
|
51 | + $this->service = $service; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Processing the srcFile(s) |
|
56 | - * @NoAdminRequired |
|
57 | - * |
|
58 | - * @param string[] $languages |
|
59 | - * - deu, eng... |
|
60 | - * @param array $files |
|
61 | - * @return DataResponse |
|
62 | - */ |
|
63 | - public function process($languages, $files) { |
|
64 | - return $this->handleNotFound( |
|
65 | - function () use ($languages, $files) { |
|
66 | - return $this->service->process($languages, $files); |
|
67 | - }); |
|
68 | - } |
|
54 | + /** |
|
55 | + * Processing the srcFile(s) |
|
56 | + * @NoAdminRequired |
|
57 | + * |
|
58 | + * @param string[] $languages |
|
59 | + * - deu, eng... |
|
60 | + * @param array $files |
|
61 | + * @return DataResponse |
|
62 | + */ |
|
63 | + public function process($languages, $files) { |
|
64 | + return $this->handleNotFound( |
|
65 | + function () use ($languages, $files) { |
|
66 | + return $this->service->process($languages, $files); |
|
67 | + }); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @NoAdminRequired |
|
72 | - * |
|
73 | - * @return \OCP\AppFramework\Http\DataResponse |
|
74 | - */ |
|
75 | - public function getAllJobs() { |
|
76 | - return $this->handleNotFound(function () { |
|
77 | - return $this->service->getAllJobsForUser($this->userId); |
|
78 | - }); |
|
79 | - } |
|
70 | + /** |
|
71 | + * @NoAdminRequired |
|
72 | + * |
|
73 | + * @return \OCP\AppFramework\Http\DataResponse |
|
74 | + */ |
|
75 | + public function getAllJobs() { |
|
76 | + return $this->handleNotFound(function () { |
|
77 | + return $this->service->getAllJobsForUser($this->userId); |
|
78 | + }); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @NoAdminRequired |
|
83 | - * |
|
84 | - * @param integer $id |
|
85 | - * @return \OCP\AppFramework\Http\DataResponse |
|
86 | - */ |
|
87 | - public function deleteJob($id) { |
|
88 | - return $this->handleNotFound( |
|
89 | - function () use ($id) { |
|
90 | - return $this->service->deleteJob($id, $this->userId); |
|
91 | - }); |
|
92 | - } |
|
81 | + /** |
|
82 | + * @NoAdminRequired |
|
83 | + * |
|
84 | + * @param integer $id |
|
85 | + * @return \OCP\AppFramework\Http\DataResponse |
|
86 | + */ |
|
87 | + public function deleteJob($id) { |
|
88 | + return $this->handleNotFound( |
|
89 | + function () use ($id) { |
|
90 | + return $this->service->deleteJob($id, $this->userId); |
|
91 | + }); |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | \ No newline at end of file |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function process($languages, $files) { |
64 | 64 | return $this->handleNotFound( |
65 | - function () use ($languages, $files) { |
|
65 | + function() use ($languages, $files) { |
|
66 | 66 | return $this->service->process($languages, $files); |
67 | 67 | }); |
68 | 68 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return \OCP\AppFramework\Http\DataResponse |
74 | 74 | */ |
75 | 75 | public function getAllJobs() { |
76 | - return $this->handleNotFound(function () { |
|
76 | + return $this->handleNotFound(function() { |
|
77 | 77 | return $this->service->getAllJobsForUser($this->userId); |
78 | 78 | }); |
79 | 79 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function deleteJob($id) { |
88 | 88 | return $this->handleNotFound( |
89 | - function () use ($id) { |
|
89 | + function() use ($id) { |
|
90 | 90 | return $this->service->deleteJob($id, $this->userId); |
91 | 91 | }); |
92 | 92 | } |
@@ -17,34 +17,34 @@ |
||
17 | 17 | |
18 | 18 | class StatusController extends Controller { |
19 | 19 | |
20 | - /** |
|
21 | - * |
|
22 | - * @var OcrService |
|
23 | - */ |
|
24 | - private $service; |
|
25 | - use Errors; |
|
20 | + /** |
|
21 | + * |
|
22 | + * @var OcrService |
|
23 | + */ |
|
24 | + private $service; |
|
25 | + use Errors; |
|
26 | 26 | |
27 | - /** |
|
28 | - * StatusController constructor. |
|
29 | - * |
|
30 | - * @param string $AppName |
|
31 | - * @param IRequest $request |
|
32 | - * @param StatusService $service |
|
33 | - */ |
|
34 | - public function __construct($AppName, IRequest $request, StatusService $service) { |
|
35 | - parent::__construct($AppName, $request); |
|
36 | - $this->service = $service; |
|
37 | - } |
|
27 | + /** |
|
28 | + * StatusController constructor. |
|
29 | + * |
|
30 | + * @param string $AppName |
|
31 | + * @param IRequest $request |
|
32 | + * @param StatusService $service |
|
33 | + */ |
|
34 | + public function __construct($AppName, IRequest $request, StatusService $service) { |
|
35 | + parent::__construct($AppName, $request); |
|
36 | + $this->service = $service; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the current status. |
|
41 | - * @NoAdminRequired |
|
42 | - * |
|
43 | - * @return DataResponse |
|
44 | - */ |
|
45 | - public function getStatus() { |
|
46 | - return $this->handleNotFound(function () { |
|
47 | - return $this->service->getStatus(); |
|
48 | - }); |
|
49 | - } |
|
39 | + /** |
|
40 | + * Get the current status. |
|
41 | + * @NoAdminRequired |
|
42 | + * |
|
43 | + * @return DataResponse |
|
44 | + */ |
|
45 | + public function getStatus() { |
|
46 | + return $this->handleNotFound(function () { |
|
47 | + return $this->service->getStatus(); |
|
48 | + }); |
|
49 | + } |
|
50 | 50 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | * @return DataResponse |
44 | 44 | */ |
45 | 45 | public function getStatus() { |
46 | - return $this->handleNotFound(function () { |
|
46 | + return $this->handleNotFound(function() { |
|
47 | 47 | return $this->service->getStatus(); |
48 | 48 | }); |
49 | 49 | } |
@@ -25,272 +25,272 @@ |
||
25 | 25 | */ |
26 | 26 | class FileService { |
27 | 27 | |
28 | - /** |
|
29 | - * |
|
30 | - * @var ILogger |
|
31 | - */ |
|
32 | - private $logger; |
|
28 | + /** |
|
29 | + * |
|
30 | + * @var ILogger |
|
31 | + */ |
|
32 | + private $logger; |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @var FileMapper |
|
37 | - */ |
|
38 | - private $fileMapper; |
|
34 | + /** |
|
35 | + * |
|
36 | + * @var FileMapper |
|
37 | + */ |
|
38 | + private $fileMapper; |
|
39 | 39 | |
40 | - /** |
|
41 | - * |
|
42 | - * @var ShareMapper |
|
43 | - */ |
|
44 | - private $shareMapper; |
|
40 | + /** |
|
41 | + * |
|
42 | + * @var ShareMapper |
|
43 | + */ |
|
44 | + private $shareMapper; |
|
45 | 45 | |
46 | - /** |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $userId; |
|
46 | + /** |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $userId; |
|
51 | 51 | |
52 | - /** |
|
53 | - * |
|
54 | - * @var IL10N |
|
55 | - */ |
|
56 | - private $l10n; |
|
52 | + /** |
|
53 | + * |
|
54 | + * @var IL10N |
|
55 | + */ |
|
56 | + private $l10n; |
|
57 | 57 | |
58 | - public function __construct(IL10N $l10n, ILogger $logger, $userId, FileMapper $fileMapper, ShareMapper $shareMapper) { |
|
59 | - $this->l10n = $l10n; |
|
60 | - $this->logger = $logger; |
|
61 | - $this->userId = $userId; |
|
62 | - $this->fileMapper = $fileMapper; |
|
63 | - $this->shareMapper = $shareMapper; |
|
64 | - } |
|
58 | + public function __construct(IL10N $l10n, ILogger $logger, $userId, FileMapper $fileMapper, ShareMapper $shareMapper) { |
|
59 | + $this->l10n = $l10n; |
|
60 | + $this->logger = $logger; |
|
61 | + $this->userId = $userId; |
|
62 | + $this->fileMapper = $fileMapper; |
|
63 | + $this->shareMapper = $shareMapper; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Checks if shared with the process initiator |
|
68 | - * |
|
69 | - * @param File $fileInfo |
|
70 | - * @return boolean|null |
|
71 | - */ |
|
72 | - public function checkSharedWithInitiator($fileInfo) { |
|
73 | - $owner = str_replace('home::', '', $fileInfo->getStoragename()); |
|
74 | - if ($this->userId === $owner) { |
|
75 | - // user is owner (no shared file) |
|
76 | - return false; |
|
77 | - } else { |
|
78 | - // user is not owner (shared file) |
|
79 | - return true; |
|
80 | - } |
|
81 | - } |
|
66 | + /** |
|
67 | + * Checks if shared with the process initiator |
|
68 | + * |
|
69 | + * @param File $fileInfo |
|
70 | + * @return boolean|null |
|
71 | + */ |
|
72 | + public function checkSharedWithInitiator($fileInfo) { |
|
73 | + $owner = str_replace('home::', '', $fileInfo->getStoragename()); |
|
74 | + if ($this->userId === $owner) { |
|
75 | + // user is owner (no shared file) |
|
76 | + return false; |
|
77 | + } else { |
|
78 | + // user is not owner (shared file) |
|
79 | + return true; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Builds the target name. |
|
85 | - * |
|
86 | - * @param File $fileInfo |
|
87 | - * @param boolean $shared |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function buildTarget($fileInfo, $shared) { |
|
91 | - if ($shared) { |
|
92 | - $target = $this->buildTargetForShared($fileInfo); |
|
93 | - } else { |
|
94 | - $target = $this->buildTargetNotForShared($fileInfo); |
|
95 | - } |
|
96 | - return $target; |
|
97 | - } |
|
83 | + /** |
|
84 | + * Builds the target name. |
|
85 | + * |
|
86 | + * @param File $fileInfo |
|
87 | + * @param boolean $shared |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function buildTarget($fileInfo, $shared) { |
|
91 | + if ($shared) { |
|
92 | + $target = $this->buildTargetForShared($fileInfo); |
|
93 | + } else { |
|
94 | + $target = $this->buildTargetNotForShared($fileInfo); |
|
95 | + } |
|
96 | + return $target; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Builds the source name. |
|
101 | - * |
|
102 | - * @param File $fileInfo |
|
103 | - * @param boolean $shared |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function buildSource($fileInfo, $shared) { |
|
107 | - $source = $fileInfo->getPath(); |
|
108 | - if ($shared) { |
|
109 | - $source = str_replace('home::', '', $fileInfo->getStoragename()) . '/' . $source; |
|
110 | - } else { |
|
111 | - $source = $this->userId . '/' . $source; |
|
112 | - } |
|
113 | - return $source; |
|
114 | - } |
|
99 | + /** |
|
100 | + * Builds the source name. |
|
101 | + * |
|
102 | + * @param File $fileInfo |
|
103 | + * @param boolean $shared |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function buildSource($fileInfo, $shared) { |
|
107 | + $source = $fileInfo->getPath(); |
|
108 | + if ($shared) { |
|
109 | + $source = str_replace('home::', '', $fileInfo->getStoragename()) . '/' . $source; |
|
110 | + } else { |
|
111 | + $source = $this->userId . '/' . $source; |
|
112 | + } |
|
113 | + return $source; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Returns the fileInfo for each file in files and checks |
|
118 | - * if it has a allowed MIME type and some other conditions. |
|
119 | - * |
|
120 | - * @param array $files |
|
121 | - * @return File[] |
|
122 | - * @throws NotFoundException |
|
123 | - */ |
|
124 | - public function buildFileInfo($files) { |
|
125 | - $fileArray = array(); |
|
126 | - foreach ($files as $file) { |
|
127 | - // Check if anything is missing and file type is correct |
|
128 | - if (!empty($file['id'])) { |
|
129 | - $fileInfo = $this->fileMapper->find($file['id']); |
|
130 | - $this->checkMimeType($fileInfo); |
|
131 | - array_push($fileArray, $fileInfo); |
|
132 | - } else { |
|
133 | - throw new NotFoundException($this->l10n->t('Wrong parameter.')); |
|
134 | - } |
|
135 | - } |
|
136 | - return $fileArray; |
|
137 | - } |
|
116 | + /** |
|
117 | + * Returns the fileInfo for each file in files and checks |
|
118 | + * if it has a allowed MIME type and some other conditions. |
|
119 | + * |
|
120 | + * @param array $files |
|
121 | + * @return File[] |
|
122 | + * @throws NotFoundException |
|
123 | + */ |
|
124 | + public function buildFileInfo($files) { |
|
125 | + $fileArray = array(); |
|
126 | + foreach ($files as $file) { |
|
127 | + // Check if anything is missing and file type is correct |
|
128 | + if (!empty($file['id'])) { |
|
129 | + $fileInfo = $this->fileMapper->find($file['id']); |
|
130 | + $this->checkMimeType($fileInfo); |
|
131 | + array_push($fileArray, $fileInfo); |
|
132 | + } else { |
|
133 | + throw new NotFoundException($this->l10n->t('Wrong parameter.')); |
|
134 | + } |
|
135 | + } |
|
136 | + return $fileArray; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Determines the correct type for the ocr process worker. |
|
141 | - * |
|
142 | - * @param File $fileInfo |
|
143 | - * @return integer |
|
144 | - */ |
|
145 | - public function getCorrectType($fileInfo) { |
|
146 | - if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
147 | - return OcrConstants::OCRmyPDF; |
|
148 | - } else { |
|
149 | - return OcrConstants::TESSERACT; |
|
150 | - } |
|
151 | - } |
|
139 | + /** |
|
140 | + * Determines the correct type for the ocr process worker. |
|
141 | + * |
|
142 | + * @param File $fileInfo |
|
143 | + * @return integer |
|
144 | + */ |
|
145 | + public function getCorrectType($fileInfo) { |
|
146 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
147 | + return OcrConstants::OCRmyPDF; |
|
148 | + } else { |
|
149 | + return OcrConstants::TESSERACT; |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Executes the exec function with a remove statement for a given file path. |
|
155 | - * @codeCoverageIgnore |
|
156 | - * |
|
157 | - * @param string $pathToFile |
|
158 | - */ |
|
159 | - public function execRemove($pathToFile) { |
|
160 | - exec('rm ' . $pathToFile); |
|
161 | - } |
|
153 | + /** |
|
154 | + * Executes the exec function with a remove statement for a given file path. |
|
155 | + * @codeCoverageIgnore |
|
156 | + * |
|
157 | + * @param string $pathToFile |
|
158 | + */ |
|
159 | + public function execRemove($pathToFile) { |
|
160 | + exec('rm ' . $pathToFile); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Wraps the static file_get_contents method of php. |
|
165 | - * @codeCoverageIgnore |
|
166 | - * |
|
167 | - * @param string $pathToFile |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function getFileContents($pathToFile) { |
|
171 | - return file_get_contents($pathToFile); |
|
172 | - } |
|
163 | + /** |
|
164 | + * Wraps the static file_get_contents method of php. |
|
165 | + * @codeCoverageIgnore |
|
166 | + * |
|
167 | + * @param string $pathToFile |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function getFileContents($pathToFile) { |
|
171 | + return file_get_contents($pathToFile); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Wraps the static file_exists method of php. |
|
176 | - * @codeCoverageIgnore |
|
177 | - * |
|
178 | - * @param string $pathToFile |
|
179 | - * @return boolean |
|
180 | - */ |
|
181 | - public function fileExists($pathToFile) { |
|
182 | - return file_exists($pathToFile); |
|
183 | - } |
|
174 | + /** |
|
175 | + * Wraps the static file_exists method of php. |
|
176 | + * @codeCoverageIgnore |
|
177 | + * |
|
178 | + * @param string $pathToFile |
|
179 | + * @return boolean |
|
180 | + */ |
|
181 | + public function fileExists($pathToFile) { |
|
182 | + return file_exists($pathToFile); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Wraps the static function \OCP\Files::buildNotExistingFileName() in order to be able to test everything else. |
|
187 | - * @codeCoverageIgnore |
|
188 | - * |
|
189 | - * @param string $filePath |
|
190 | - * @param string $fileName |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function buildNotExistingFilename($filePath, $fileName) { |
|
194 | - return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf'); |
|
195 | - } |
|
185 | + /** |
|
186 | + * Wraps the static function \OCP\Files::buildNotExistingFileName() in order to be able to test everything else. |
|
187 | + * @codeCoverageIgnore |
|
188 | + * |
|
189 | + * @param string $filePath |
|
190 | + * @param string $fileName |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function buildNotExistingFilename($filePath, $fileName) { |
|
194 | + return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf'); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Returns a not existing file name for pdf or image processing |
|
199 | - * protected as of testing issues with static methods. |
|
200 | - * (Actually |
|
201 | - * it will be mocked partially) FIXME: Change this behaviour as soon as the buidlNotExistingFileName function is not |
|
202 | - * static anymore |
|
203 | - * @codeCoverageIgnore |
|
204 | - * |
|
205 | - * @param File $fileInfo |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - private function buildTargetForShared(File $fileInfo) { |
|
209 | - $share = $this->shareMapper->find($fileInfo->getFileid(), $this->userId, |
|
210 | - str_replace('home::', '', $fileInfo->getStoragename())); |
|
211 | - // get rid of the .png or .pdf and so on |
|
212 | - $fileName = substr($share->getFileTarget(), 0, (strrpos($share->getFileTarget(), '.'))); // '/thedom.png' |
|
213 | - // => '/thedom' |
|
214 | - // || |
|
215 | - // '/Test/thedom.png' |
|
216 | - // => |
|
217 | - // '/Test/thedom' |
|
218 | - // remove |
|
219 | - // everything |
|
220 | - // in front of |
|
221 | - // and |
|
222 | - // including of |
|
223 | - // the first |
|
224 | - // appearance |
|
225 | - // of a slash |
|
226 | - // from behind |
|
227 | - $fileName = substr(strrchr($fileName, "/"), 1); // '/thedom' => 'thedom' || '/Test/thedom' => 'thedom' |
|
228 | - // eliminate the file name from the path |
|
229 | - $filePath = dirname($share->getFileTarget()); // '/thedom.png' => '/' || '/Test/thedom.png' => '/Test' |
|
230 | - // replace the first slash |
|
231 | - $pos = strpos($filePath, '/'); |
|
232 | - if ($pos !== false) { |
|
233 | - $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/' => '' || '/Test/' => 'Test' |
|
234 | - } |
|
235 | - if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
236 | - // PDFs: |
|
237 | - return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.pdf'); |
|
238 | - } else { |
|
239 | - // IMAGES: |
|
240 | - return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.txt'); |
|
241 | - } |
|
242 | - } |
|
197 | + /** |
|
198 | + * Returns a not existing file name for pdf or image processing |
|
199 | + * protected as of testing issues with static methods. |
|
200 | + * (Actually |
|
201 | + * it will be mocked partially) FIXME: Change this behaviour as soon as the buidlNotExistingFileName function is not |
|
202 | + * static anymore |
|
203 | + * @codeCoverageIgnore |
|
204 | + * |
|
205 | + * @param File $fileInfo |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + private function buildTargetForShared(File $fileInfo) { |
|
209 | + $share = $this->shareMapper->find($fileInfo->getFileid(), $this->userId, |
|
210 | + str_replace('home::', '', $fileInfo->getStoragename())); |
|
211 | + // get rid of the .png or .pdf and so on |
|
212 | + $fileName = substr($share->getFileTarget(), 0, (strrpos($share->getFileTarget(), '.'))); // '/thedom.png' |
|
213 | + // => '/thedom' |
|
214 | + // || |
|
215 | + // '/Test/thedom.png' |
|
216 | + // => |
|
217 | + // '/Test/thedom' |
|
218 | + // remove |
|
219 | + // everything |
|
220 | + // in front of |
|
221 | + // and |
|
222 | + // including of |
|
223 | + // the first |
|
224 | + // appearance |
|
225 | + // of a slash |
|
226 | + // from behind |
|
227 | + $fileName = substr(strrchr($fileName, "/"), 1); // '/thedom' => 'thedom' || '/Test/thedom' => 'thedom' |
|
228 | + // eliminate the file name from the path |
|
229 | + $filePath = dirname($share->getFileTarget()); // '/thedom.png' => '/' || '/Test/thedom.png' => '/Test' |
|
230 | + // replace the first slash |
|
231 | + $pos = strpos($filePath, '/'); |
|
232 | + if ($pos !== false) { |
|
233 | + $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/' => '' || '/Test/' => 'Test' |
|
234 | + } |
|
235 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
236 | + // PDFs: |
|
237 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.pdf'); |
|
238 | + } else { |
|
239 | + // IMAGES: |
|
240 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.txt'); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * Returns a not existing file name for PDF or image processing |
|
246 | - * protected as of testing issues with static methods. |
|
247 | - * (Actually |
|
248 | - * it will be mocked partially) FIXME: Change this behaviour as soon as the buidlNotExistingFileName function is not |
|
249 | - * static anymore |
|
250 | - * @codeCoverageIgnore |
|
251 | - * |
|
252 | - * @param File $fileInfo |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - private function buildTargetNotForShared(File $fileInfo) { |
|
256 | - // get rid of the .png or .pdf and so on |
|
257 | - $fileName = substr($fileInfo->getName(), 0, (strrpos($fileInfo->getName(), '.'))); // 'thedom.png' => |
|
258 | - // 'thedom' |
|
259 | - // eliminate the file |
|
260 | - // name from the path |
|
261 | - $filePath = str_replace($fileInfo->getName(), '', $fileInfo->getPath()); // 'files/Test/thedom.png' => |
|
262 | - // 'files/Test/' || |
|
263 | - // 'files/thedom.png' => 'files/' |
|
264 | - // and get the path on top of the |
|
265 | - // files/ dir |
|
266 | - $filePath = str_replace('files', '', $filePath); // 'files/Test/' => '/Test/' || 'files/' => '/' |
|
267 | - // remove the last slash |
|
268 | - $filePath = substr_replace($filePath, '', strrpos($filePath, '/'), strlen('/')); // '/Test/' => '/Test' |
|
269 | - // || '/' => '' |
|
270 | - // replace the first |
|
271 | - // slash |
|
272 | - $pos = strpos($filePath, '/'); |
|
273 | - if ($pos !== false) { |
|
274 | - $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/Test' => '// 'Test' || '/' => '' |
|
275 | - } |
|
276 | - if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
277 | - // PDFs: |
|
278 | - return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.pdf'); |
|
279 | - } else { |
|
280 | - // IMAGES: |
|
281 | - return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.txt'); |
|
282 | - } |
|
283 | - } |
|
244 | + /** |
|
245 | + * Returns a not existing file name for PDF or image processing |
|
246 | + * protected as of testing issues with static methods. |
|
247 | + * (Actually |
|
248 | + * it will be mocked partially) FIXME: Change this behaviour as soon as the buidlNotExistingFileName function is not |
|
249 | + * static anymore |
|
250 | + * @codeCoverageIgnore |
|
251 | + * |
|
252 | + * @param File $fileInfo |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + private function buildTargetNotForShared(File $fileInfo) { |
|
256 | + // get rid of the .png or .pdf and so on |
|
257 | + $fileName = substr($fileInfo->getName(), 0, (strrpos($fileInfo->getName(), '.'))); // 'thedom.png' => |
|
258 | + // 'thedom' |
|
259 | + // eliminate the file |
|
260 | + // name from the path |
|
261 | + $filePath = str_replace($fileInfo->getName(), '', $fileInfo->getPath()); // 'files/Test/thedom.png' => |
|
262 | + // 'files/Test/' || |
|
263 | + // 'files/thedom.png' => 'files/' |
|
264 | + // and get the path on top of the |
|
265 | + // files/ dir |
|
266 | + $filePath = str_replace('files', '', $filePath); // 'files/Test/' => '/Test/' || 'files/' => '/' |
|
267 | + // remove the last slash |
|
268 | + $filePath = substr_replace($filePath, '', strrpos($filePath, '/'), strlen('/')); // '/Test/' => '/Test' |
|
269 | + // || '/' => '' |
|
270 | + // replace the first |
|
271 | + // slash |
|
272 | + $pos = strpos($filePath, '/'); |
|
273 | + if ($pos !== false) { |
|
274 | + $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/Test' => '// 'Test' || '/' => '' |
|
275 | + } |
|
276 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
277 | + // PDFs: |
|
278 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.pdf'); |
|
279 | + } else { |
|
280 | + // IMAGES: |
|
281 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.txt'); |
|
282 | + } |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Checks a MIME type for a specifically given FileInfo. |
|
287 | - * |
|
288 | - * @param File $fileInfo |
|
289 | - */ |
|
290 | - private function checkMimeType(File $fileInfo) { |
|
291 | - if (!$fileInfo || !in_array($fileInfo->getMimetype(), OcrConstants::ALLOWED_MIME_TYPES)) { |
|
292 | - $this->logger->debug('Getting FileInfo did not work or not included in the ALLOWED_MIMETYPES array.'); |
|
293 | - throw new NotFoundException($this->l10n->t('Wrong MIME type.')); |
|
294 | - } |
|
295 | - } |
|
285 | + /** |
|
286 | + * Checks a MIME type for a specifically given FileInfo. |
|
287 | + * |
|
288 | + * @param File $fileInfo |
|
289 | + */ |
|
290 | + private function checkMimeType(File $fileInfo) { |
|
291 | + if (!$fileInfo || !in_array($fileInfo->getMimetype(), OcrConstants::ALLOWED_MIME_TYPES)) { |
|
292 | + $this->logger->debug('Getting FileInfo did not work or not included in the ALLOWED_MIMETYPES array.'); |
|
293 | + throw new NotFoundException($this->l10n->t('Wrong MIME type.')); |
|
294 | + } |
|
295 | + } |
|
296 | 296 | } |
297 | 297 | \ No newline at end of file |
@@ -17,93 +17,93 @@ |
||
17 | 17 | |
18 | 18 | class AppConfigService { |
19 | 19 | |
20 | - /** |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - private $appName = 'ocr'; |
|
20 | + /** |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + private $appName = 'ocr'; |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * @var IConfig |
|
29 | - */ |
|
30 | - private $config; |
|
26 | + /** |
|
27 | + * |
|
28 | + * @var IConfig |
|
29 | + */ |
|
30 | + private $config; |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @var IL10N |
|
35 | - */ |
|
36 | - private $l10n; |
|
32 | + /** |
|
33 | + * |
|
34 | + * @var IL10N |
|
35 | + */ |
|
36 | + private $l10n; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor |
|
40 | - * |
|
41 | - * @param IConfig $config |
|
42 | - * @param IL10N $l10n |
|
43 | - */ |
|
44 | - public function __construct(IConfig $config, IL10N $l10n) { |
|
45 | - $this->config = $config; |
|
46 | - $this->l10n = $l10n; |
|
47 | - } |
|
38 | + /** |
|
39 | + * Constructor |
|
40 | + * |
|
41 | + * @param IConfig $config |
|
42 | + * @param IL10N $l10n |
|
43 | + */ |
|
44 | + public function __construct(IConfig $config, IL10N $l10n) { |
|
45 | + $this->config = $config; |
|
46 | + $this->l10n = $l10n; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get a value by key |
|
51 | - * |
|
52 | - * @param string $key |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function getAppValue($key) { |
|
56 | - return $this->config->getAppValue($this->appName, $key); |
|
57 | - } |
|
49 | + /** |
|
50 | + * Get a value by key |
|
51 | + * |
|
52 | + * @param string $key |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function getAppValue($key) { |
|
56 | + return $this->config->getAppValue($this->appName, $key); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Evaluate if all redis related settings are set. |
|
61 | - * |
|
62 | - * @return boolean |
|
63 | - */ |
|
64 | - public function evaluateRedisSettings() { |
|
65 | - if ($this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_HOST) !== '' && |
|
66 | - $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_PORT) !== '' && |
|
67 | - $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_DB) !== '') { |
|
68 | - return true; |
|
69 | - } else { |
|
70 | - return false; |
|
71 | - } |
|
72 | - } |
|
59 | + /** |
|
60 | + * Evaluate if all redis related settings are set. |
|
61 | + * |
|
62 | + * @return boolean |
|
63 | + */ |
|
64 | + public function evaluateRedisSettings() { |
|
65 | + if ($this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_HOST) !== '' && |
|
66 | + $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_PORT) !== '' && |
|
67 | + $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_DB) !== '') { |
|
68 | + return true; |
|
69 | + } else { |
|
70 | + return false; |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Set a value by key |
|
76 | - * |
|
77 | - * @param string $key |
|
78 | - * @param string $value |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function setAppValue($key, $value) { |
|
82 | - if ($key === OcrConstants::LANGUAGES_CONFIG_KEY) { |
|
83 | - if (!preg_match('/^(([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4});)*([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4})$/', $value)) { |
|
84 | - throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.')); |
|
85 | - } |
|
86 | - } |
|
87 | - if ($key === OcrConstants::REDIS_CONFIG_KEY_HOST) { |
|
88 | - if (!preg_match( |
|
89 | - '/(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$)/', |
|
90 | - $value)) { |
|
91 | - throw new NotFoundException($this->l10n->t('The redis host is not specified in the correct format.')); |
|
92 | - } |
|
93 | - } |
|
94 | - if ($key === OcrConstants::REDIS_CONFIG_KEY_PORT) { |
|
95 | - $value = intval($value); |
|
96 | - if (!($value > 0 && $value < 65535)) { |
|
97 | - throw new NotFoundException( |
|
98 | - $this->l10n->t('The redis port number is not specified in the correct format.')); |
|
99 | - } |
|
100 | - } |
|
101 | - if ($key === OcrConstants::REDIS_CONFIG_KEY_DB) { |
|
102 | - $value = intval($value); |
|
103 | - if (!($value >= 0)) { |
|
104 | - throw new NotFoundException($this->l10n->t('The redis db is not specified in the correct format.')); |
|
105 | - } |
|
106 | - } |
|
107 | - return $this->config->setAppValue($this->appName, $key, $value); |
|
108 | - } |
|
74 | + /** |
|
75 | + * Set a value by key |
|
76 | + * |
|
77 | + * @param string $key |
|
78 | + * @param string $value |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function setAppValue($key, $value) { |
|
82 | + if ($key === OcrConstants::LANGUAGES_CONFIG_KEY) { |
|
83 | + if (!preg_match('/^(([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4});)*([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4})$/', $value)) { |
|
84 | + throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.')); |
|
85 | + } |
|
86 | + } |
|
87 | + if ($key === OcrConstants::REDIS_CONFIG_KEY_HOST) { |
|
88 | + if (!preg_match( |
|
89 | + '/(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$)/', |
|
90 | + $value)) { |
|
91 | + throw new NotFoundException($this->l10n->t('The redis host is not specified in the correct format.')); |
|
92 | + } |
|
93 | + } |
|
94 | + if ($key === OcrConstants::REDIS_CONFIG_KEY_PORT) { |
|
95 | + $value = intval($value); |
|
96 | + if (!($value > 0 && $value < 65535)) { |
|
97 | + throw new NotFoundException( |
|
98 | + $this->l10n->t('The redis port number is not specified in the correct format.')); |
|
99 | + } |
|
100 | + } |
|
101 | + if ($key === OcrConstants::REDIS_CONFIG_KEY_DB) { |
|
102 | + $value = intval($value); |
|
103 | + if (!($value >= 0)) { |
|
104 | + throw new NotFoundException($this->l10n->t('The redis db is not specified in the correct format.')); |
|
105 | + } |
|
106 | + } |
|
107 | + return $this->config->setAppValue($this->appName, $key, $value); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |