@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @return boolean|null |
70 | 70 | */ |
71 | 71 | public function checkSharedWithInitiator($fileInfo) { |
72 | - $owner = str_replace ( 'home::', '', $fileInfo->getStoragename () ); |
|
72 | + $owner = str_replace('home::', '', $fileInfo->getStoragename()); |
|
73 | 73 | if ($this->userId === $owner) { |
74 | 74 | // user is owner (no shared file) |
75 | 75 | return false; |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function buildTarget($fileInfo, $shared) { |
90 | 90 | if ($shared) { |
91 | - $target = $this->buildTargetForShared ( $fileInfo ); |
|
91 | + $target = $this->buildTargetForShared($fileInfo); |
|
92 | 92 | } else { |
93 | - $target = $this->buildTargetNotForShared ( $fileInfo ); |
|
93 | + $target = $this->buildTargetNotForShared($fileInfo); |
|
94 | 94 | } |
95 | 95 | return $target; |
96 | 96 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @return string |
104 | 104 | */ |
105 | 105 | public function buildSource($fileInfo, $shared) { |
106 | - $source = $fileInfo->getPath (); |
|
106 | + $source = $fileInfo->getPath(); |
|
107 | 107 | if ($shared) { |
108 | - $source = str_replace ( 'home::', '', $fileInfo->getStoragename () ) . '/' . $source; |
|
108 | + $source = str_replace('home::', '', $fileInfo->getStoragename()) . '/' . $source; |
|
109 | 109 | } else { |
110 | 110 | $source = $this->userId . '/' . $source; |
111 | 111 | } |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | * @throws NotFoundException |
122 | 122 | */ |
123 | 123 | public function buildFileInfo($files) { |
124 | - $fileArray = array (); |
|
125 | - foreach ( $files as $file ) { |
|
124 | + $fileArray = array(); |
|
125 | + foreach ($files as $file) { |
|
126 | 126 | // Check if anything is missing and file type is correct |
127 | - if (! empty ( $file ['id'] )) { |
|
127 | + if (!empty ($file ['id'])) { |
|
128 | 128 | |
129 | - $fileInfo = $this->fileMapper->find ( $file ['id'] ); |
|
130 | - $this->checkMimeType ( $fileInfo ); |
|
129 | + $fileInfo = $this->fileMapper->find($file ['id']); |
|
130 | + $this->checkMimeType($fileInfo); |
|
131 | 131 | |
132 | - array_push ( $fileArray, $fileInfo ); |
|
132 | + array_push($fileArray, $fileInfo); |
|
133 | 133 | } else { |
134 | - throw new NotFoundException ( $this->l10n->t ( 'Wrong parameter.' ) ); |
|
134 | + throw new NotFoundException($this->l10n->t('Wrong parameter.')); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | return $fileArray; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return integer |
145 | 145 | */ |
146 | 146 | public function getCorrectType($fileInfo) { |
147 | - if ($fileInfo->getMimetype () === OcrConstants::MIME_TYPE_PDF) { |
|
147 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
148 | 148 | return OcrConstants::OCRmyPDF; |
149 | 149 | } else { |
150 | 150 | return OcrConstants::TESSERACT; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param string $pathToFile |
160 | 160 | */ |
161 | 161 | public function execRemove($pathToFile) { |
162 | - exec ( 'rm ' . $pathToFile ); |
|
162 | + exec('rm ' . $pathToFile); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @return string |
172 | 172 | */ |
173 | 173 | public function getFileContents($pathToFile) { |
174 | - return file_get_contents ( $pathToFile ); |
|
174 | + return file_get_contents($pathToFile); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @return boolean |
184 | 184 | */ |
185 | 185 | public function fileExists($pathToFile) { |
186 | - return file_exists ( $pathToFile ); |
|
186 | + return file_exists($pathToFile); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @return string |
197 | 197 | */ |
198 | 198 | public function buildNotExistingFilename($filePath, $fileName) { |
199 | - return \OCP\Files::buildNotExistingFileName ( $filePath, $fileName . '_OCR.pdf' ); |
|
199 | + return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -210,29 +210,29 @@ discard block |
||
210 | 210 | * @return string |
211 | 211 | */ |
212 | 212 | private function buildTargetForShared(File $fileInfo) { |
213 | - $share = $this->shareMapper->find ( $fileInfo->getFileid (), $this->userId, str_replace ( 'home::', '', $fileInfo->getStoragename () ) ); |
|
213 | + $share = $this->shareMapper->find($fileInfo->getFileid(), $this->userId, str_replace('home::', '', $fileInfo->getStoragename())); |
|
214 | 214 | |
215 | 215 | // get rid of the .png or .pdf and so on |
216 | - $fileName = substr ( $share->getFileTarget (), 0, (strrpos ( $share->getFileTarget (), '.' )) ); // '/thedom.png' => '/thedom' || '/Test/thedom.png' => '/Test/thedom' |
|
216 | + $fileName = substr($share->getFileTarget(), 0, (strrpos($share->getFileTarget(), '.'))); // '/thedom.png' => '/thedom' || '/Test/thedom.png' => '/Test/thedom' |
|
217 | 217 | |
218 | 218 | // remove everything in front of and including of the first appearance of a slash from behind |
219 | - $fileName = substr ( strrchr ( $fileName, "/" ), 1 ); // '/thedom' => 'thedom' || '/Test/thedom' => 'thedom' |
|
219 | + $fileName = substr(strrchr($fileName, "/"), 1); // '/thedom' => 'thedom' || '/Test/thedom' => 'thedom' |
|
220 | 220 | |
221 | 221 | // eliminate the file name from the path |
222 | - $filePath = dirname ( $share->getFileTarget () ); // '/thedom.png' => '/' || '/Test/thedom.png' => '/Test' |
|
222 | + $filePath = dirname($share->getFileTarget()); // '/thedom.png' => '/' || '/Test/thedom.png' => '/Test' |
|
223 | 223 | |
224 | 224 | // replace the first slash |
225 | - $pos = strpos ( $filePath, '/' ); |
|
225 | + $pos = strpos($filePath, '/'); |
|
226 | 226 | if ($pos !== false) { |
227 | - $filePath = substr_replace ( $filePath, '', $pos, strlen ( '/' ) ); // '/' => '' || '/Test/' => 'Test' |
|
227 | + $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/' => '' || '/Test/' => 'Test' |
|
228 | 228 | } |
229 | 229 | |
230 | - if ($fileInfo->getMimetype () === OcrConstants::MIME_TYPE_PDF) { |
|
230 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
231 | 231 | // PDFs: |
232 | - return $this->buildNotExistingFilename ( $filePath, $fileName . '_OCR.pdf' ); |
|
232 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.pdf'); |
|
233 | 233 | } else { |
234 | 234 | // IMAGES: |
235 | - return $this->buildNotExistingFilename ( $filePath, $fileName . '_OCR.txt' ); |
|
235 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.txt'); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
@@ -248,29 +248,29 @@ discard block |
||
248 | 248 | */ |
249 | 249 | private function buildTargetNotForShared(File $fileInfo) { |
250 | 250 | // get rid of the .png or .pdf and so on |
251 | - $fileName = substr ( $fileInfo->getName (), 0, (strrpos ( $fileInfo->getName (), '.' )) ); // 'thedom.png' => 'thedom' |
|
251 | + $fileName = substr($fileInfo->getName(), 0, (strrpos($fileInfo->getName(), '.'))); // 'thedom.png' => 'thedom' |
|
252 | 252 | |
253 | 253 | // eliminate the file name from the path |
254 | - $filePath = str_replace ( $fileInfo->getName (), '', $fileInfo->getPath () ); // 'files/Test/thedom.png' => 'files/Test/' || 'files/thedom.png' => 'files/' |
|
254 | + $filePath = str_replace($fileInfo->getName(), '', $fileInfo->getPath()); // 'files/Test/thedom.png' => 'files/Test/' || 'files/thedom.png' => 'files/' |
|
255 | 255 | |
256 | 256 | // and get the path on top of the files/ dir |
257 | - $filePath = str_replace ( 'files', '', $filePath ); // 'files/Test/' => '/Test/' || 'files/' => '/' |
|
257 | + $filePath = str_replace('files', '', $filePath); // 'files/Test/' => '/Test/' || 'files/' => '/' |
|
258 | 258 | |
259 | 259 | // remove the last slash |
260 | - $filePath = substr_replace ( $filePath, '', strrpos ( $filePath, '/' ), strlen ( '/' ) ); // '/Test/' => '/Test' || '/' => '' |
|
260 | + $filePath = substr_replace($filePath, '', strrpos($filePath, '/'), strlen('/')); // '/Test/' => '/Test' || '/' => '' |
|
261 | 261 | |
262 | 262 | // replace the first slash |
263 | - $pos = strpos ( $filePath, '/' ); |
|
263 | + $pos = strpos($filePath, '/'); |
|
264 | 264 | if ($pos !== false) { |
265 | - $filePath = substr_replace ( $filePath, '', $pos, strlen ( '/' ) ); // '/Test' => '// 'Test' || '/' => '' |
|
265 | + $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/Test' => '// 'Test' || '/' => '' |
|
266 | 266 | } |
267 | 267 | |
268 | - if ($fileInfo->getMimetype () === OcrConstants::MIME_TYPE_PDF) { |
|
268 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
269 | 269 | // PDFs: |
270 | - return $this->buildNotExistingFilename ( $filePath, $fileName . '_OCR.pdf' ); |
|
270 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.pdf'); |
|
271 | 271 | } else { |
272 | 272 | // IMAGES: |
273 | - return $this->buildNotExistingFilename ( $filePath, $fileName . '_OCR.txt' ); |
|
273 | + return $this->buildNotExistingFilename($filePath, $fileName . '_OCR.txt'); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @param File $fileInfo |
281 | 281 | */ |
282 | 282 | private function checkMimeType(File $fileInfo) { |
283 | - if (! $fileInfo || ! in_array ( $fileInfo->getMimetype (), OcrConstants::ALLOWED_MIME_TYPES )) { |
|
284 | - $this->logger->debug ( 'Getting FileInfo did not work or not included in the ALLOWED_MIMETYPES array.' ); |
|
285 | - throw new NotFoundException ( $this->l10n->t ( 'Wrong MIME type.' ) ); |
|
283 | + if (!$fileInfo || !in_array($fileInfo->getMimetype(), OcrConstants::ALLOWED_MIME_TYPES)) { |
|
284 | + $this->logger->debug('Getting FileInfo did not work or not included in the ALLOWED_MIMETYPES array.'); |
|
285 | + throw new NotFoundException($this->l10n->t('Wrong MIME type.')); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | } |
289 | 289 | \ No newline at end of file |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | $this->logger = $logger; |
96 | 96 | $this->l10n = $l10n; |
97 | 97 | $this->config = $config; |
98 | - $this->redisHost = $this->config->getAppValue ( $this->appName, 'redisHost' ); |
|
99 | - $this->redisPort = intval ( $this->config->getAppValue ( $this->appName, 'redisPort' ) ); |
|
100 | - $this->redisDb = intval ( $this->config->getAppValue ( $this->appName, 'redisDb' ) ); |
|
98 | + $this->redisHost = $this->config->getAppValue($this->appName, 'redisHost'); |
|
99 | + $this->redisPort = intval($this->config->getAppValue($this->appName, 'redisPort')); |
|
100 | + $this->redisDb = intval($this->config->getAppValue($this->appName, 'redisDb')); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -110,25 +110,25 @@ discard block |
||
110 | 110 | public function sendJob($job, $languages, $occDir) { |
111 | 111 | try { |
112 | 112 | // check for messaging and put everything together |
113 | - $redis = $this->setupRedisInstance (); |
|
113 | + $redis = $this->setupRedisInstance(); |
|
114 | 114 | |
115 | - $job = $this->mapper->insert ( $job ); |
|
116 | - $msg = json_encode ( array ( |
|
117 | - 'id' => $job->getId (), |
|
118 | - 'type' => $job->getType (), |
|
119 | - 'source' => $job->getSource (), |
|
120 | - 'tempFile' => $job->getTempFile (), |
|
115 | + $job = $this->mapper->insert($job); |
|
116 | + $msg = json_encode(array( |
|
117 | + 'id' => $job->getId(), |
|
118 | + 'type' => $job->getType(), |
|
119 | + 'source' => $job->getSource(), |
|
120 | + 'tempFile' => $job->getTempFile(), |
|
121 | 121 | 'languages' => $languages |
122 | - ) ); |
|
123 | - if (! $redis->lPush ( OcrConstants::REDIS_NEW_JOBS_QUEUE, $msg )) { |
|
124 | - throw new NotFoundException ( $this->l10n->t ( 'Could not add files to the redis OCR processing queue.' ) ); |
|
122 | + )); |
|
123 | + if (!$redis->lPush(OcrConstants::REDIS_NEW_JOBS_QUEUE, $msg)) { |
|
124 | + throw new NotFoundException($this->l10n->t('Could not add files to the redis OCR processing queue.')); |
|
125 | 125 | } |
126 | - } catch ( Exception $e ) { |
|
127 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
128 | - $job->setStatus ( 'FAILED' ); |
|
129 | - $job->setErrorLog ( $this->l10n->t ( 'Could not add files to the redis OCR processing queue.' ) ); |
|
130 | - $this->mapper->update ( $job ); |
|
131 | - $this->handleException ( $e ); |
|
126 | + } catch (Exception $e) { |
|
127 | + $this->fileService->execRemove($job->getTempFile()); |
|
128 | + $job->setStatus('FAILED'); |
|
129 | + $job->setErrorLog($this->l10n->t('Could not add files to the redis OCR processing queue.')); |
|
130 | + $this->mapper->update($job); |
|
131 | + $this->handleException($e); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function readingFinishedJobs() { |
141 | 141 | try { |
142 | - $redis = $this->setupRedisInstance (); |
|
142 | + $redis = $this->setupRedisInstance(); |
|
143 | 143 | |
144 | - $result = $redis->multi ()->lRange ( OcrConstants::REDIS_FINISHED_JOBS_QUEUE, 0, - 1 )->delete ( OcrConstants::REDIS_FINISHED_JOBS_QUEUE )->exec (); |
|
145 | - $this->logger->debug ( 'Retrieved the following array from redis: {result}', [ |
|
144 | + $result = $redis->multi()->lRange(OcrConstants::REDIS_FINISHED_JOBS_QUEUE, 0, - 1)->delete(OcrConstants::REDIS_FINISHED_JOBS_QUEUE)->exec(); |
|
145 | + $this->logger->debug('Retrieved the following array from redis: {result}', [ |
|
146 | 146 | 'result' => $result [0] |
147 | - ] ); |
|
147 | + ]); |
|
148 | 148 | return $result [0]; |
149 | - } catch ( Exception $e ) { |
|
150 | - $this->handleException ( $e ); |
|
149 | + } catch (Exception $e) { |
|
150 | + $this->handleException($e); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * @return \Redis |
159 | 159 | */ |
160 | 160 | private function setupRedisInstance() { |
161 | - if (! extension_loaded ( 'redis' )) { |
|
162 | - $this->logger->debug ( 'It seems that the message queueing capabilities are not available in your local php installation. Please install php-redis.' ); |
|
163 | - throw new NotFoundException ( $this->l10n->t ( 'Message queueing capabilities are missing on the server.' ) ); |
|
161 | + if (!extension_loaded('redis')) { |
|
162 | + $this->logger->debug('It seems that the message queueing capabilities are not available in your local php installation. Please install php-redis.'); |
|
163 | + throw new NotFoundException($this->l10n->t('Message queueing capabilities are missing on the server.')); |
|
164 | 164 | } |
165 | 165 | |
166 | - $redis = new \Redis (); |
|
167 | - if (! $redis->connect ( $this->redisHost, $this->redisPort, 2.5, NULL, 100 )) { |
|
168 | - $this->logger->debug ( 'Cannot connect to Redis.' ); |
|
169 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot connect to Redis.' ) ); |
|
166 | + $redis = new \Redis(); |
|
167 | + if (!$redis->connect($this->redisHost, $this->redisPort, 2.5, NULL, 100)) { |
|
168 | + $this->logger->debug('Cannot connect to Redis.'); |
|
169 | + throw new NotFoundException($this->l10n->t('Cannot connect to Redis.')); |
|
170 | 170 | } |
171 | - if (! $redis->select ( $this->redisDb )) { |
|
172 | - $this->logger->debug ( 'Cannot connect to the right Redis database.' ); |
|
173 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot connect to the right Redis database.' ) ); |
|
171 | + if (!$redis->select($this->redisDb)) { |
|
172 | + $this->logger->debug('Cannot connect to the right Redis database.'); |
|
173 | + throw new NotFoundException($this->l10n->t('Cannot connect to the right Redis database.')); |
|
174 | 174 | } |
175 | - $redis->setOption ( \Redis::OPT_PREFIX, OcrConstants::REDIS_KEY_PREFIX ); |
|
175 | + $redis->setOption(\Redis::OPT_PREFIX, OcrConstants::REDIS_KEY_PREFIX); |
|
176 | 176 | |
177 | 177 | return $redis; |
178 | 178 | } |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | * @throws NotFoundException |
186 | 186 | */ |
187 | 187 | private function handleException($e) { |
188 | - $this->logger->logException ( $e, [ |
|
188 | + $this->logger->logException($e, [ |
|
189 | 189 | 'message' => 'Exception during message queue processing' |
190 | - ] ); |
|
190 | + ]); |
|
191 | 191 | throw $e; |
192 | 192 | } |
193 | 193 | } |
194 | 194 | \ No newline at end of file |
@@ -81,26 +81,26 @@ discard block |
||
81 | 81 | public function getStatus() { |
82 | 82 | try { |
83 | 83 | // TODO: For now this will be placed in the regular check, but in the future this could be done in another way |
84 | - $this->jobService->checkForFinishedJobs (); |
|
84 | + $this->jobService->checkForFinishedJobs(); |
|
85 | 85 | |
86 | 86 | // returns user specific processed files |
87 | - $processed = $this->jobMapper->findAllProcessed ( $this->userId ); |
|
88 | - $this->jobService->handleProcessed (); |
|
87 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
88 | + $this->jobService->handleProcessed(); |
|
89 | 89 | |
90 | 90 | // return user specific pending state |
91 | - $pending = $this->jobMapper->findAllPending ( $this->userId ); |
|
91 | + $pending = $this->jobMapper->findAllPending($this->userId); |
|
92 | 92 | |
93 | 93 | // return user specific failed state and set up error |
94 | - $failed = $this->jobMapper->findAllFailed ( $this->userId ); |
|
95 | - $this->jobService->handleFailed (); |
|
94 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
95 | + $this->jobService->handleFailed(); |
|
96 | 96 | |
97 | 97 | return [ |
98 | - 'processed' => count ( $processed ), |
|
99 | - 'failed' => count ( $failed ), |
|
100 | - 'pending' => count ( $pending ) |
|
98 | + 'processed' => count($processed), |
|
99 | + 'failed' => count($failed), |
|
100 | + 'pending' => count($pending) |
|
101 | 101 | ]; |
102 | - } catch ( Exception $e ) { |
|
103 | - $this->handleException ( $e ); |
|
102 | + } catch (Exception $e) { |
|
103 | + $this->handleException($e); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * @throws NotFoundException |
113 | 113 | */ |
114 | 114 | private function handleException($e) { |
115 | - $this->logger->logException ( $e, [ |
|
115 | + $this->logger->logException($e, [ |
|
116 | 116 | 'message' => 'Exception during status service function processing' |
117 | - ] ); |
|
117 | + ]); |
|
118 | 118 | throw $e; |
119 | 119 | } |
120 | 120 | } |
121 | 121 | \ No newline at end of file |