@@ -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 |
@@ -124,44 +124,44 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function process($languages, $files) { |
| 126 | 126 | try { |
| 127 | - $this->logger->debug ( 'Will now process files: {files} with languages: {languages}', [ |
|
| 128 | - 'files' => json_encode ( $files ), |
|
| 129 | - 'languages' => json_encode ( $languages ) |
|
| 130 | - ] ); |
|
| 127 | + $this->logger->debug('Will now process files: {files} with languages: {languages}', [ |
|
| 128 | + 'files' => json_encode($files), |
|
| 129 | + 'languages' => json_encode($languages) |
|
| 130 | + ]); |
|
| 131 | 131 | // Check if files and language not empty |
| 132 | - $noLang = $this->noLanguage ( $languages ); |
|
| 133 | - if (! empty ( $files ) && ($this->checkForAcceptedLanguages ( $languages ) || $noLang)) { |
|
| 132 | + $noLang = $this->noLanguage($languages); |
|
| 133 | + if (!empty ($files) && ($this->checkForAcceptedLanguages($languages) || $noLang)) { |
|
| 134 | 134 | // language part: |
| 135 | 135 | if ($noLang) { |
| 136 | - $languages = [ ]; |
|
| 136 | + $languages = []; |
|
| 137 | 137 | } |
| 138 | 138 | // file part: |
| 139 | - $fileInfo = $this->fileService->buildFileInfo ( $files ); |
|
| 140 | - foreach ( $fileInfo as $fInfo ) { |
|
| 139 | + $fileInfo = $this->fileService->buildFileInfo($files); |
|
| 140 | + foreach ($fileInfo as $fInfo) { |
|
| 141 | 141 | // Check Shared |
| 142 | - $shared = $this->fileService->checkSharedWithInitiator ( $fInfo ); |
|
| 143 | - $target = $this->fileService->buildTarget ( $fInfo, $shared ); |
|
| 144 | - $source = $this->fileService->buildSource ( $fInfo, $shared ); |
|
| 142 | + $shared = $this->fileService->checkSharedWithInitiator($fInfo); |
|
| 143 | + $target = $this->fileService->buildTarget($fInfo, $shared); |
|
| 144 | + $source = $this->fileService->buildSource($fInfo, $shared); |
|
| 145 | 145 | |
| 146 | 146 | // set the running type |
| 147 | - $fType = $this->fileService->getCorrectType ( $fInfo ); |
|
| 147 | + $fType = $this->fileService->getCorrectType($fInfo); |
|
| 148 | 148 | |
| 149 | 149 | // create a temp file for ocr processing purposes |
| 150 | - $tempFile = $this->getTempFile ( $fType ); |
|
| 150 | + $tempFile = $this->getTempFile($fType); |
|
| 151 | 151 | |
| 152 | 152 | // Create job object |
| 153 | - $job = new OcrJob ( OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName (), null ); |
|
| 153 | + $job = new OcrJob(OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName(), null); |
|
| 154 | 154 | |
| 155 | 155 | // Init client and send task / job |
| 156 | 156 | // Feed the worker |
| 157 | - $this->redisService->sendJob ( $job, $languages, \OC::$SERVERROOT ); |
|
| 157 | + $this->redisService->sendJob($job, $languages, \OC::$SERVERROOT); |
|
| 158 | 158 | } |
| 159 | 159 | return 'PROCESSING'; |
| 160 | 160 | } else { |
| 161 | - throw new NotFoundException ( $this->l10n->t ( 'Empty parameters passed.' ) ); |
|
| 161 | + throw new NotFoundException($this->l10n->t('Empty parameters passed.')); |
|
| 162 | 162 | } |
| 163 | - } catch ( Exception $e ) { |
|
| 164 | - $this->handleException ( $e ); |
|
| 163 | + } catch (Exception $e) { |
|
| 164 | + $this->handleException($e); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
@@ -175,26 +175,26 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function deleteJob($jobId, $userId) { |
| 177 | 177 | try { |
| 178 | - $job = $this->jobMapper->find ( $jobId ); |
|
| 179 | - if ($job->getUserId () !== $userId) { |
|
| 180 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong owner.' ) ); |
|
| 178 | + $job = $this->jobMapper->find($jobId); |
|
| 179 | + if ($job->getUserId() !== $userId) { |
|
| 180 | + throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.')); |
|
| 181 | 181 | } else { |
| 182 | - $job = $this->jobMapper->delete ( $job ); |
|
| 182 | + $job = $this->jobMapper->delete($job); |
|
| 183 | 183 | } |
| 184 | - $job->setTarget ( null ); |
|
| 185 | - $job->setSource ( null ); |
|
| 186 | - $job->setStatus ( null ); |
|
| 187 | - $job->setTempFile ( null ); |
|
| 188 | - $job->setType ( null ); |
|
| 189 | - $job->setUserId ( null ); |
|
| 190 | - $job->setErrorDisplayed ( null ); |
|
| 184 | + $job->setTarget(null); |
|
| 185 | + $job->setSource(null); |
|
| 186 | + $job->setStatus(null); |
|
| 187 | + $job->setTempFile(null); |
|
| 188 | + $job->setType(null); |
|
| 189 | + $job->setUserId(null); |
|
| 190 | + $job->setErrorDisplayed(null); |
|
| 191 | 191 | return $job; |
| 192 | - } catch ( Exception $e ) { |
|
| 192 | + } catch (Exception $e) { |
|
| 193 | 193 | if ($e instanceof DoesNotExistException) { |
| 194 | - $ex = new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong ID.' ) ); |
|
| 195 | - $this->handleException ( $ex ); |
|
| 194 | + $ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.')); |
|
| 195 | + $this->handleException($ex); |
|
| 196 | 196 | } else { |
| 197 | - $this->handleException ( $e ); |
|
| 197 | + $this->handleException($e); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | } |
@@ -207,21 +207,21 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | public function getAllJobsForUser($userId) { |
| 209 | 209 | try { |
| 210 | - $jobs = $this->jobMapper->findAll ( $userId ); |
|
| 211 | - $jobsNew = array (); |
|
| 212 | - foreach ( $jobs as $job ) { |
|
| 213 | - $job->setTarget ( null ); |
|
| 214 | - $job->setSource ( null ); |
|
| 215 | - $job->setTempFile ( null ); |
|
| 216 | - $job->setType ( null ); |
|
| 217 | - $job->setUserId ( null ); |
|
| 218 | - $job->setErrorDisplayed ( null ); |
|
| 210 | + $jobs = $this->jobMapper->findAll($userId); |
|
| 211 | + $jobsNew = array(); |
|
| 212 | + foreach ($jobs as $job) { |
|
| 213 | + $job->setTarget(null); |
|
| 214 | + $job->setSource(null); |
|
| 215 | + $job->setTempFile(null); |
|
| 216 | + $job->setType(null); |
|
| 217 | + $job->setUserId(null); |
|
| 218 | + $job->setErrorDisplayed(null); |
|
| 219 | 219 | |
| 220 | - array_push ( $jobsNew, $job ); |
|
| 220 | + array_push($jobsNew, $job); |
|
| 221 | 221 | } |
| 222 | 222 | return $jobsNew; |
| 223 | - } catch ( Exception $e ) { |
|
| 224 | - $this->handleException ( $e ); |
|
| 223 | + } catch (Exception $e) { |
|
| 224 | + $this->handleException($e); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public function checkForFinishedJobs() { |
| 233 | 233 | try { |
| 234 | - $finishedJobs = $this->redisService->readingFinishedJobs (); |
|
| 235 | - foreach ( $finishedJobs as $finishedJob ) { |
|
| 236 | - $fJob = $this->transformJob( $finishedJob ); |
|
| 234 | + $finishedJobs = $this->redisService->readingFinishedJobs(); |
|
| 235 | + foreach ($finishedJobs as $finishedJob) { |
|
| 236 | + $fJob = $this->transformJob($finishedJob); |
|
| 237 | 237 | $this->logger->debug('The following job finished: {job}', ['job' => $fJob]); |
| 238 | - $this->jobFinished ( $fJob->id, $fJob->error, $fJob->log ); |
|
| 238 | + $this->jobFinished($fJob->id, $fJob->error, $fJob->log); |
|
| 239 | 239 | } |
| 240 | - } catch ( Exception $e ) { |
|
| 241 | - throw new NotFoundException ( $this->l10n->t ( 'Reading the finished jobs from redis went wrong.' ) ); |
|
| 240 | + } catch (Exception $e) { |
|
| 241 | + throw new NotFoundException($this->l10n->t('Reading the finished jobs from redis went wrong.')); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
@@ -252,18 +252,18 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function jobFinished($jobId, $error, $log) { |
| 254 | 254 | try { |
| 255 | - $job = $this->jobMapper->find ( $jobId ); |
|
| 256 | - if (! $error) { |
|
| 257 | - $job->setStatus ( OcrConstants::STATUS_PROCESSED ); |
|
| 258 | - $this->jobMapper->update ( $job ); |
|
| 255 | + $job = $this->jobMapper->find($jobId); |
|
| 256 | + if (!$error) { |
|
| 257 | + $job->setStatus(OcrConstants::STATUS_PROCESSED); |
|
| 258 | + $this->jobMapper->update($job); |
|
| 259 | 259 | } else { |
| 260 | - $job->setStatus ( OcrConstants::STATUS_FAILED ); |
|
| 261 | - $job->setErrorLog( $log ); |
|
| 262 | - $this->jobMapper->update ( $job ); |
|
| 263 | - $this->logger->error ( $log); |
|
| 260 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 261 | + $job->setErrorLog($log); |
|
| 262 | + $this->jobMapper->update($job); |
|
| 263 | + $this->logger->error($log); |
|
| 264 | 264 | } |
| 265 | - } catch ( Exception $e ) { |
|
| 266 | - $this->handleException ( $e ); |
|
| 265 | + } catch (Exception $e) { |
|
| 266 | + $this->handleException($e); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
@@ -275,24 +275,24 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public function handleProcessed() { |
| 277 | 277 | try { |
| 278 | - $this->logger->debug ( 'Check if files were processed by ocr and if so, put them to the right dirs.'); |
|
| 279 | - $processed = $this->jobMapper->findAllProcessed ( $this->userId ); |
|
| 280 | - foreach ( $processed as $job ) { |
|
| 281 | - if ($this->fileService->fileExists ( $job->getTempFile () )) { |
|
| 278 | + $this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.'); |
|
| 279 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
| 280 | + foreach ($processed as $job) { |
|
| 281 | + if ($this->fileService->fileExists($job->getTempFile())) { |
|
| 282 | 282 | // Save the tmp file with newname |
| 283 | - $this->view->file_put_contents ( $job->getTarget (), $this->fileService->getFileContents ( $job->getTempFile () ) ); |
|
| 284 | - $this->jobMapper->delete ( $job ); |
|
| 285 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
| 283 | + $this->view->file_put_contents($job->getTarget(), $this->fileService->getFileContents($job->getTempFile())); |
|
| 284 | + $this->jobMapper->delete($job); |
|
| 285 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 286 | 286 | } else { |
| 287 | - $job->setStatus ( OcrConstants::STATUS_FAILED ); |
|
| 287 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 288 | 288 | $job->setErrorLog('Temp file does not exist.'); |
| 289 | - $this->jobMapper->update ( $job ); |
|
| 290 | - throw new NotFoundException ( $this->l10n->t ( 'Temp file does not exist.' ) ); |
|
| 289 | + $this->jobMapper->update($job); |
|
| 290 | + throw new NotFoundException($this->l10n->t('Temp file does not exist.')); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | return $processed; |
| 294 | - } catch ( Exception $e ) { |
|
| 295 | - $this->handleException ( $e ); |
|
| 294 | + } catch (Exception $e) { |
|
| 295 | + $this->handleException($e); |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
@@ -303,20 +303,20 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function handleFailed() { |
| 305 | 305 | try { |
| 306 | - $failed = $this->jobMapper->findAllFailed ( $this->userId ); |
|
| 307 | - foreach ( $failed as $job ) { |
|
| 306 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
| 307 | + foreach ($failed as $job) { |
|
| 308 | 308 | // clean the tempfile |
| 309 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
| 309 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 310 | 310 | // set error displayed |
| 311 | - $job->setErrorDisplayed ( true ); |
|
| 312 | - $this->jobMapper->update ( $job ); |
|
| 311 | + $job->setErrorDisplayed(true); |
|
| 312 | + $this->jobMapper->update($job); |
|
| 313 | 313 | } |
| 314 | - $this->logger->debug ( 'Following jobs failed: {failed}', [ |
|
| 315 | - 'failed' => json_encode ( $failed ) |
|
| 316 | - ] ); |
|
| 314 | + $this->logger->debug('Following jobs failed: {failed}', [ |
|
| 315 | + 'failed' => json_encode($failed) |
|
| 316 | + ]); |
|
| 317 | 317 | return $failed; |
| 318 | - } catch ( Exception $e ) { |
|
| 319 | - $this->handleException ( $e ); |
|
| 318 | + } catch (Exception $e) { |
|
| 319 | + $this->handleException($e); |
|
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | |
@@ -329,14 +329,14 @@ discard block |
||
| 329 | 329 | */ |
| 330 | 330 | private function getTempFile($type) { |
| 331 | 331 | if ($type === OcrConstants::TESSERACT) { |
| 332 | - $fileName = $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir (), OcrConstants::TEMPFILE_PREFIX); |
|
| 332 | + $fileName = $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), OcrConstants::TEMPFILE_PREFIX); |
|
| 333 | 333 | $this->phpUtil->unlinkWrapper($fileName); |
| 334 | 334 | $fileNameWithPostfix = $fileName . '.txt'; |
| 335 | - $this->phpUtil->touchWrapper( $fileNameWithPostfix ); |
|
| 336 | - $this->phpUtil->chmodWrapper( $fileNameWithPostfix, 0600 ); |
|
| 335 | + $this->phpUtil->touchWrapper($fileNameWithPostfix); |
|
| 336 | + $this->phpUtil->chmodWrapper($fileNameWithPostfix, 0600); |
|
| 337 | 337 | return $fileNameWithPostfix; |
| 338 | 338 | } else { |
| 339 | - return $this->phpUtil->tempnamWrapper( $this->tempM->getTempBaseDir (), 'ocr_' ); |
|
| 339 | + return $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), 'ocr_'); |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | |
@@ -348,11 +348,11 @@ discard block |
||
| 348 | 348 | * @return mixed |
| 349 | 349 | */ |
| 350 | 350 | private function transformJob($job) { |
| 351 | - $decoded = json_decode ( $job ); |
|
| 352 | - if($decoded !== null && isset($decoded->id)) { |
|
| 351 | + $decoded = json_decode($job); |
|
| 352 | + if ($decoded !== null && isset($decoded->id)) { |
|
| 353 | 353 | return $decoded; |
| 354 | 354 | } else { |
| 355 | - throw new NotFoundException($this->l10n->t ( 'The finished job retrieved by Redis was corrupt.' )); |
|
| 355 | + throw new NotFoundException($this->l10n->t('The finished job retrieved by Redis was corrupt.')); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | * @return boolean |
| 364 | 364 | */ |
| 365 | 365 | private function checkForAcceptedLanguages($languages) { |
| 366 | - $installedLanguages = explode ( ';', $this->appConfigService->getAppValue ( 'languages' ) ); |
|
| 367 | - if (count ( array_diff ( $languages, $installedLanguages ) ) === 0) { |
|
| 366 | + $installedLanguages = explode(';', $this->appConfigService->getAppValue('languages')); |
|
| 367 | + if (count(array_diff($languages, $installedLanguages)) === 0) { |
|
| 368 | 368 | return true; |
| 369 | 369 | } else { |
| 370 | 370 | return false; |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @return boolean |
| 379 | 379 | */ |
| 380 | 380 | private function noLanguage($languages) { |
| 381 | - if (in_array ( 'any', $languages )) { |
|
| 381 | + if (in_array('any', $languages)) { |
|
| 382 | 382 | return true; |
| 383 | 383 | } else { |
| 384 | 384 | return false; |
@@ -393,9 +393,9 @@ discard block |
||
| 393 | 393 | * @throws NotFoundException |
| 394 | 394 | */ |
| 395 | 395 | private function handleException($e) { |
| 396 | - $this->logger->logException ( $e, [ |
|
| 396 | + $this->logger->logException($e, [ |
|
| 397 | 397 | 'message' => 'Exception during job service function processing' |
| 398 | - ] ); |
|
| 398 | + ]); |
|
| 399 | 399 | throw $e; |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | \ No newline at end of file |