@@ -38,7 +38,7 @@ |
||
| 38 | 38 | * |
| 39 | 39 | */ |
| 40 | 40 | public function getName() { |
| 41 | - return $this->l->t ( 'OCR' ); |
|
| 41 | + return $this->l->t('OCR'); |
|
| 42 | 42 | } |
| 43 | 43 | /** |
| 44 | 44 | * |
@@ -31,9 +31,9 @@ |
||
| 31 | 31 | * @return TemplateResponse |
| 32 | 32 | */ |
| 33 | 33 | public function getForm() { |
| 34 | - return new TemplateResponse( 'ocr', 'settings-admin', [ |
|
| 35 | - 'languages' => $this->config->getAppValue ( 'ocr', 'languages' ) |
|
| 36 | - ], 'blank' ); |
|
| 34 | + return new TemplateResponse('ocr', 'settings-admin', [ |
|
| 35 | + 'languages' => $this->config->getAppValue('ocr', 'languages') |
|
| 36 | + ], 'blank'); |
|
| 37 | 37 | } |
| 38 | 38 | /** |
| 39 | 39 | * |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return string |
| 52 | 52 | */ |
| 53 | 53 | public function getAppValue($key) { |
| 54 | - return $this->config->getAppValue ( $this->appName, $key ); |
|
| 54 | + return $this->config->getAppValue($this->appName, $key); |
|
| 55 | 55 | } |
| 56 | 56 | /** |
| 57 | 57 | * Set a value by key |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function setAppValue($key, $value) { |
| 64 | 64 | if ($key === 'languages') { |
| 65 | - 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 )) { |
|
| 66 | - throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) ); |
|
| 65 | + 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)) { |
|
| 66 | + throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.')); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | - return $this->config->setAppValue ( $this->appName, $key, $value ); |
|
| 69 | + return $this->config->setAppValue($this->appName, $key, $value); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param string $userId |
| 40 | 40 | */ |
| 41 | 41 | public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) { |
| 42 | - parent::__construct ( $appName, $request ); |
|
| 42 | + parent::__construct($appName, $request); |
|
| 43 | 43 | $this->l10n = $l10n; |
| 44 | 44 | $this->appConfig = $appConfig; |
| 45 | 45 | } |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | * @return DataResponse |
| 51 | 51 | */ |
| 52 | 52 | public function getSettings() { |
| 53 | - return $this->handleNotFound ( function () { |
|
| 54 | - return [ 'languages' => $this->appConfig->getAppValue ( 'languages' )]; |
|
| 53 | + return $this->handleNotFound(function() { |
|
| 54 | + return ['languages' => $this->appConfig->getAppValue('languages')]; |
|
| 55 | 55 | } ); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | * @return DataResponse |
| 63 | 63 | */ |
| 64 | 64 | public function setSettings($languages) { |
| 65 | - return $this->handleNotFound ( function () use ($languages) { |
|
| 65 | + return $this->handleNotFound(function() use ($languages) { |
|
| 66 | 66 | if ($languages !== null) { |
| 67 | - $this->appConfig->setAppValue ( 'languages', $languages ); |
|
| 68 | - return $this->l10n->t ( 'Saved' ); |
|
| 67 | + $this->appConfig->setAppValue('languages', $languages); |
|
| 68 | + return $this->l10n->t('Saved'); |
|
| 69 | 69 | } else { |
| 70 | - throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) ); |
|
| 70 | + throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.')); |
|
| 71 | 71 | } |
| 72 | 72 | } ); |
| 73 | 73 | } |
@@ -17,7 +17,6 @@ |
||
| 17 | 17 | use OCP\IL10N; |
| 18 | 18 | use OCP\ITempManager; |
| 19 | 19 | use OCA\Ocr\Db\OcrJob; |
| 20 | -use OCA\Ocr\Db\File; |
|
| 21 | 20 | use OCA\Ocr\Constants\OcrConstants; |
| 22 | 21 | |
| 23 | 22 | /** |
@@ -115,43 +115,43 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function process($languages, $files) { |
| 117 | 117 | try { |
| 118 | - $this->logger->debug ( 'Will now process files: ' . json_encode ( $files ) . ' with languages: ' . json_encode ( $languages ), [ |
|
| 118 | + $this->logger->debug('Will now process files: ' . json_encode($files) . ' with languages: ' . json_encode($languages), [ |
|
| 119 | 119 | 'app' => 'ocr' |
| 120 | - ] ); |
|
| 120 | + ]); |
|
| 121 | 121 | // Check if files and language not empty |
| 122 | - $noLang = $this->noLanguage ( $languages ); |
|
| 123 | - if (! empty ( $files ) && ($this->checkForAcceptedLanguages ( $languages ) || $noLang)) { |
|
| 122 | + $noLang = $this->noLanguage($languages); |
|
| 123 | + if (!empty ($files) && ($this->checkForAcceptedLanguages($languages) || $noLang)) { |
|
| 124 | 124 | // language part: |
| 125 | 125 | if ($noLang) { |
| 126 | - $languages = [ ]; |
|
| 126 | + $languages = []; |
|
| 127 | 127 | } |
| 128 | 128 | // file part: |
| 129 | - $fileInfo = $this->fileService->buildFileInfo ( $files ); |
|
| 130 | - foreach ( $fileInfo as $fInfo ) { |
|
| 129 | + $fileInfo = $this->fileService->buildFileInfo($files); |
|
| 130 | + foreach ($fileInfo as $fInfo) { |
|
| 131 | 131 | // Check Shared |
| 132 | - $shared = $this->fileService->checkSharedWithInitiator ( $fInfo ); |
|
| 133 | - $target = $this->fileService->buildTarget ( $fInfo, $shared ); |
|
| 134 | - $source = $this->fileService->buildSource ( $fInfo, $shared ); |
|
| 132 | + $shared = $this->fileService->checkSharedWithInitiator($fInfo); |
|
| 133 | + $target = $this->fileService->buildTarget($fInfo, $shared); |
|
| 134 | + $source = $this->fileService->buildSource($fInfo, $shared); |
|
| 135 | 135 | |
| 136 | 136 | // set the running type |
| 137 | - $fType = $this->fileService->getCorrectType ( $fInfo ); |
|
| 137 | + $fType = $this->fileService->getCorrectType($fInfo); |
|
| 138 | 138 | |
| 139 | 139 | // create a temp file for ocr processing purposes |
| 140 | - $tempFile = $this->getTempFile ( $fType ); |
|
| 140 | + $tempFile = $this->getTempFile($fType); |
|
| 141 | 141 | |
| 142 | 142 | // Create job object |
| 143 | - $job = new OcrJob ( OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName (), null ); |
|
| 143 | + $job = new OcrJob(OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName(), null); |
|
| 144 | 144 | |
| 145 | 145 | // Init client and send task / job |
| 146 | 146 | // Feed the worker |
| 147 | - $this->redisService->sendJob ( $job, $languages, \OC::$SERVERROOT ); |
|
| 147 | + $this->redisService->sendJob($job, $languages, \OC::$SERVERROOT); |
|
| 148 | 148 | } |
| 149 | 149 | return 'PROCESSING'; |
| 150 | 150 | } else { |
| 151 | - throw new NotFoundException ( $this->l10n->t ( 'Empty parameters passed.' ) ); |
|
| 151 | + throw new NotFoundException($this->l10n->t('Empty parameters passed.')); |
|
| 152 | 152 | } |
| 153 | - } catch ( Exception $e ) { |
|
| 154 | - $this->handleException ( $e ); |
|
| 153 | + } catch (Exception $e) { |
|
| 154 | + $this->handleException($e); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
@@ -165,20 +165,20 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function deleteJob($jobId, $userId) { |
| 167 | 167 | try { |
| 168 | - $job = $this->jobMapper->find ( $jobId ); |
|
| 169 | - if ($job->getUserId () !== $userId) { |
|
| 170 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong owner.' ) ); |
|
| 168 | + $job = $this->jobMapper->find($jobId); |
|
| 169 | + if ($job->getUserId() !== $userId) { |
|
| 170 | + throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.')); |
|
| 171 | 171 | } else { |
| 172 | - $job = $this->jobMapper->delete ( $job ); |
|
| 172 | + $job = $this->jobMapper->delete($job); |
|
| 173 | 173 | } |
| 174 | 174 | // TODO: return sanitized job for the personal settings page (no information about the source and target and such things. |
| 175 | 175 | return $job; |
| 176 | - } catch ( Exception $e ) { |
|
| 176 | + } catch (Exception $e) { |
|
| 177 | 177 | if ($e instanceof DoesNotExistException) { |
| 178 | - $ex = new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong ID.' ) ); |
|
| 179 | - $this->handleException ( $ex ); |
|
| 178 | + $ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.')); |
|
| 179 | + $this->handleException($ex); |
|
| 180 | 180 | } else { |
| 181 | - $this->handleException ( $e ); |
|
| 181 | + $this->handleException($e); |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -192,20 +192,20 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function getAllJobsForUser($userId) { |
| 194 | 194 | try { |
| 195 | - $jobs = $this->jobMapper->findAll ( $userId ); |
|
| 196 | - $jobsNew = array (); |
|
| 197 | - for($x = 0; $x < count ( $jobs ); $x ++) { |
|
| 198 | - $newName = $this->fileService->removeFileExtension ( $jobs [$x] ); |
|
| 199 | - $jobs [$x]->setTarget ( $newName ); |
|
| 200 | - $jobs [$x]->setSource ( null ); |
|
| 201 | - $jobs [$x]->setTempFile ( null ); |
|
| 202 | - $jobs [$x]->setType ( null ); |
|
| 203 | - $jobs [$x]->setErrorDisplayed ( null ); |
|
| 204 | - array_push ( $jobsNew, $jobs [$x] ); |
|
| 195 | + $jobs = $this->jobMapper->findAll($userId); |
|
| 196 | + $jobsNew = array(); |
|
| 197 | + for ($x = 0; $x < count($jobs); $x++) { |
|
| 198 | + $newName = $this->fileService->removeFileExtension($jobs [$x]); |
|
| 199 | + $jobs [$x]->setTarget($newName); |
|
| 200 | + $jobs [$x]->setSource(null); |
|
| 201 | + $jobs [$x]->setTempFile(null); |
|
| 202 | + $jobs [$x]->setType(null); |
|
| 203 | + $jobs [$x]->setErrorDisplayed(null); |
|
| 204 | + array_push($jobsNew, $jobs [$x]); |
|
| 205 | 205 | } |
| 206 | 206 | return $jobsNew; |
| 207 | - } catch ( Exception $e ) { |
|
| 208 | - $this->handleException ( $e ); |
|
| 207 | + } catch (Exception $e) { |
|
| 208 | + $this->handleException($e); |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
@@ -220,20 +220,20 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function jobFinished($jobId, $failed, $errorMessage) { |
| 222 | 222 | try { |
| 223 | - $job = $this->jobMapper->find ( $jobId ); |
|
| 224 | - if (! $failed) { |
|
| 225 | - $job->setStatus ( OcrConstants::STATUS_PROCESSED ); |
|
| 226 | - $this->jobMapper->update ( $job ); |
|
| 223 | + $job = $this->jobMapper->find($jobId); |
|
| 224 | + if (!$failed) { |
|
| 225 | + $job->setStatus(OcrConstants::STATUS_PROCESSED); |
|
| 226 | + $this->jobMapper->update($job); |
|
| 227 | 227 | } else { |
| 228 | - $job->setStatus ( OcrConstants::STATUS_FAILED ); |
|
| 228 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 229 | 229 | // TODO: add error message log and so on |
| 230 | - $this->jobMapper->update ( $job ); |
|
| 231 | - $this->logger->error ( $errorMessage, [ |
|
| 230 | + $this->jobMapper->update($job); |
|
| 231 | + $this->logger->error($errorMessage, [ |
|
| 232 | 232 | 'app' => 'ocr' |
| 233 | - ] ); |
|
| 233 | + ]); |
|
| 234 | 234 | } |
| 235 | - } catch ( Exception $e ) { |
|
| 236 | - $this->handleException ( $e ); |
|
| 235 | + } catch (Exception $e) { |
|
| 236 | + $this->handleException($e); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
@@ -246,26 +246,26 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function handleProcessed() { |
| 248 | 248 | try { |
| 249 | - $this->logger->debug ( 'Check if files were processed by ocr and if so, put them to the right dirs.', [ |
|
| 249 | + $this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.', [ |
|
| 250 | 250 | 'app' => 'ocr' |
| 251 | - ] ); |
|
| 252 | - $processed = $this->jobMapper->findAllProcessed ( $this->userId ); |
|
| 253 | - foreach ( $processed as $job ) { |
|
| 254 | - if ($this->fileService->fileExists ( $job->getTempFile () )) { |
|
| 251 | + ]); |
|
| 252 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
| 253 | + foreach ($processed as $job) { |
|
| 254 | + if ($this->fileService->fileExists($job->getTempFile())) { |
|
| 255 | 255 | // Save the tmp file with newname |
| 256 | - $this->view->file_put_contents ( $job->getTarget (), $this->fileService->getFileContents ( $job->getTempFile () ) ); |
|
| 257 | - $this->jobMapper->delete ( $job ); |
|
| 258 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
| 256 | + $this->view->file_put_contents($job->getTarget(), $this->fileService->getFileContents($job->getTempFile())); |
|
| 257 | + $this->jobMapper->delete($job); |
|
| 258 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 259 | 259 | } else { |
| 260 | - $job->setStatus ( 'FAILED' ); |
|
| 260 | + $job->setStatus('FAILED'); |
|
| 261 | 261 | // TODO: set log |
| 262 | - $this->jobMapper->update ( $job ); |
|
| 263 | - throw new NotFoundException ( $this->l10n->t ( 'Temp file does not exist.' ) ); |
|
| 262 | + $this->jobMapper->update($job); |
|
| 263 | + throw new NotFoundException($this->l10n->t('Temp file does not exist.')); |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | return $processed; |
| 267 | - } catch ( Exception $e ) { |
|
| 268 | - $this->handleException ( $e ); |
|
| 267 | + } catch (Exception $e) { |
|
| 268 | + $this->handleException($e); |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
@@ -276,20 +276,20 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function handleFailed() { |
| 278 | 278 | try { |
| 279 | - $failed = $this->jobMapper->findAllFailed ( $this->userId ); |
|
| 280 | - foreach ( $failed as $job ) { |
|
| 279 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
| 280 | + foreach ($failed as $job) { |
|
| 281 | 281 | // clean the tempfile |
| 282 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
| 282 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 283 | 283 | // set error displayed |
| 284 | - $job->setErrorDisplayed ( true ); |
|
| 285 | - $this->jobMapper->update ( $job ); |
|
| 284 | + $job->setErrorDisplayed(true); |
|
| 285 | + $this->jobMapper->update($job); |
|
| 286 | 286 | } |
| 287 | - $this->logger->debug ( 'Following jobs failed: ' . json_encode ( $failed ), [ |
|
| 287 | + $this->logger->debug('Following jobs failed: ' . json_encode($failed), [ |
|
| 288 | 288 | 'app' => 'ocr' |
| 289 | - ] ); |
|
| 289 | + ]); |
|
| 290 | 290 | return $failed; |
| 291 | - } catch ( Exception $e ) { |
|
| 292 | - $this->handleException ( $e ); |
|
| 291 | + } catch (Exception $e) { |
|
| 292 | + $this->handleException($e); |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
@@ -302,9 +302,9 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | private function getTempFile($type) { |
| 304 | 304 | if ($type == OcrConstants::TESSERACT) { |
| 305 | - return $this->tempM->getTemporaryFile ( 'txt' ); |
|
| 305 | + return $this->tempM->getTemporaryFile('txt'); |
|
| 306 | 306 | } else { |
| 307 | - return $this->tempM->getTemporaryFile (); |
|
| 307 | + return $this->tempM->getTemporaryFile(); |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
@@ -315,8 +315,8 @@ discard block |
||
| 315 | 315 | * @return boolean |
| 316 | 316 | */ |
| 317 | 317 | private function checkForAcceptedLanguages($languages) { |
| 318 | - $installedLanguages = explode ( ';', $this->appConfigService->getAppValue ( 'languages' ) ); |
|
| 319 | - if (count ( array_diff ( $languages, $installedLanguages ) ) === 0) { |
|
| 318 | + $installedLanguages = explode(';', $this->appConfigService->getAppValue('languages')); |
|
| 319 | + if (count(array_diff($languages, $installedLanguages)) === 0) { |
|
| 320 | 320 | return true; |
| 321 | 321 | } else { |
| 322 | 322 | return false; |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * @return boolean |
| 331 | 331 | */ |
| 332 | 332 | private function noLanguage($languages) { |
| 333 | - if (in_array ( 'any', $languages )) { |
|
| 333 | + if (in_array('any', $languages)) { |
|
| 334 | 334 | return true; |
| 335 | 335 | } else { |
| 336 | 336 | return false; |
@@ -345,12 +345,12 @@ discard block |
||
| 345 | 345 | * @throws NotFoundException |
| 346 | 346 | */ |
| 347 | 347 | private function handleException($e) { |
| 348 | - $this->logger->logException ( $e, [ |
|
| 348 | + $this->logger->logException($e, [ |
|
| 349 | 349 | 'app' => 'ocr', |
| 350 | 350 | 'message' => 'Exception during job service function processing' |
| 351 | - ] ); |
|
| 351 | + ]); |
|
| 352 | 352 | if ($e instanceof NotFoundException) { |
| 353 | - throw new NotFoundException ( $e->getMessage () ); |
|
| 353 | + throw new NotFoundException($e->getMessage()); |
|
| 354 | 354 | } else { |
| 355 | 355 | throw $e; |
| 356 | 356 | } |
@@ -39,130 +39,130 @@ discard block |
||
| 39 | 39 | * @param array $urlParams |
| 40 | 40 | */ |
| 41 | 41 | public function __construct(array $urlParams = array()) { |
| 42 | - parent::__construct ( 'ocr', $urlParams ); |
|
| 43 | - $container = $this->getContainer (); |
|
| 42 | + parent::__construct('ocr', $urlParams); |
|
| 43 | + $container = $this->getContainer(); |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Add the js and style if OCA\Files app is loaded |
| 47 | 47 | */ |
| 48 | - $eventDispatcher = \OC::$server->getEventDispatcher (); |
|
| 49 | - $eventDispatcher->addListener ( 'OCA\Files::loadAdditionalScripts', function () { |
|
| 50 | - script ( 'ocr', 'dist/ocrapp' ); |
|
| 51 | - style ( 'ocr', 'ocrstyle' ); |
|
| 48 | + $eventDispatcher = \OC::$server->getEventDispatcher(); |
|
| 49 | + $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() { |
|
| 50 | + script('ocr', 'dist/ocrapp'); |
|
| 51 | + style('ocr', 'ocrstyle'); |
|
| 52 | 52 | // if not loaded before - load select2 for multi select languages |
| 53 | - vendor_script ( 'select2/select2' ); |
|
| 54 | - vendor_style ( 'select2/select2' ); |
|
| 53 | + vendor_script('select2/select2'); |
|
| 54 | + vendor_style('select2/select2'); |
|
| 55 | 55 | } ); |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Register core services |
| 59 | 59 | */ |
| 60 | - $container->registerService ( 'CurrentUID', function (IContainer $c) { |
|
| 60 | + $container->registerService('CurrentUID', function(IContainer $c) { |
|
| 61 | 61 | /** @var \OC\Server $server */ |
| 62 | - $server = $c->query ( 'ServerContainer' ); |
|
| 63 | - $user = $server->getUserSession ()->getUser (); |
|
| 64 | - return ($user) ? $user->getUID () : ''; |
|
| 62 | + $server = $c->query('ServerContainer'); |
|
| 63 | + $user = $server->getUserSession()->getUser(); |
|
| 64 | + return ($user) ? $user->getUID() : ''; |
|
| 65 | 65 | } ); |
| 66 | 66 | |
| 67 | 67 | // Allow automatic DI for the View, until they migrated to Nodes API |
| 68 | - $container->registerService ( View::class, function () { |
|
| 69 | - return new View ( '' ); |
|
| 70 | - }, false ); |
|
| 68 | + $container->registerService(View::class, function() { |
|
| 69 | + return new View(''); |
|
| 70 | + }, false); |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * Register the Ocr Job mapper |
| 74 | 74 | */ |
| 75 | - $container->registerService ( 'OcrJobMapper', function (IContainer $c) { |
|
| 75 | + $container->registerService('OcrJobMapper', function(IContainer $c) { |
|
| 76 | 76 | /** @var \OC\Server $server */ |
| 77 | - $server = $c->query ( 'ServerContainer' ); |
|
| 78 | - return new OcrJobMapper ( $server->getDatabaseConnection () ); |
|
| 77 | + $server = $c->query('ServerContainer'); |
|
| 78 | + return new OcrJobMapper($server->getDatabaseConnection()); |
|
| 79 | 79 | } ); |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Register the File mapper |
| 83 | 83 | */ |
| 84 | - $container->registerService ( 'FileMapper', function (IContainer $c) { |
|
| 84 | + $container->registerService('FileMapper', function(IContainer $c) { |
|
| 85 | 85 | /** @var \OC\Server $server */ |
| 86 | - $server = $c->query ( 'ServerContainer' ); |
|
| 87 | - return new FileMapper ( $server->getDatabaseConnection () ); |
|
| 86 | + $server = $c->query('ServerContainer'); |
|
| 87 | + return new FileMapper($server->getDatabaseConnection()); |
|
| 88 | 88 | } ); |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * Register the Share mapper |
| 92 | 92 | */ |
| 93 | - $container->registerService ( 'ShareMapper', function (IContainer $c) { |
|
| 93 | + $container->registerService('ShareMapper', function(IContainer $c) { |
|
| 94 | 94 | /** @var \OC\Server $server */ |
| 95 | - $server = $c->query ( 'ServerContainer' ); |
|
| 96 | - return new ShareMapper ( $server->getDatabaseConnection () ); |
|
| 95 | + $server = $c->query('ServerContainer'); |
|
| 96 | + return new ShareMapper($server->getDatabaseConnection()); |
|
| 97 | 97 | } ); |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Register the App Config Service |
| 101 | 101 | */ |
| 102 | - $container->registerService ( 'AppConfigService', function (IAppContainer $c) { |
|
| 102 | + $container->registerService('AppConfigService', function(IAppContainer $c) { |
|
| 103 | 103 | /** @var \OC\Server $server */ |
| 104 | - $server = $c->query ( 'ServerContainer' ); |
|
| 105 | - return new AppConfigService( $server->getConfig (), $server->getL10N ( 'ocr' ) ); |
|
| 104 | + $server = $c->query('ServerContainer'); |
|
| 105 | + return new AppConfigService($server->getConfig(), $server->getL10N('ocr')); |
|
| 106 | 106 | } ); |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Register the Redis Service |
| 110 | 110 | */ |
| 111 | - $container->registerService ( 'RedisService', function (IAppContainer $c) { |
|
| 111 | + $container->registerService('RedisService', function(IAppContainer $c) { |
|
| 112 | 112 | /** @var \OC\Server $server */ |
| 113 | - $server = $c->query ( 'ServerContainer' ); |
|
| 114 | - return new RedisService ( $c->query ( 'OcrJobMapper' ), $server->getConfig (), $server->getL10N ( 'ocr' ), $server->getLogger () ); |
|
| 113 | + $server = $c->query('ServerContainer'); |
|
| 114 | + return new RedisService($c->query('OcrJobMapper'), $server->getConfig(), $server->getL10N('ocr'), $server->getLogger()); |
|
| 115 | 115 | } ); |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * Register the Job Service |
| 119 | 119 | */ |
| 120 | - $container->registerService ( 'FileService', function (IAppContainer $c) { |
|
| 120 | + $container->registerService('FileService', function(IAppContainer $c) { |
|
| 121 | 121 | /** @var \OC\Server $server */ |
| 122 | - $server = $c->query ( 'ServerContainer' ); |
|
| 123 | - return new FileService ( $server->getL10N ( 'ocr' ), $server->getLogger (), $c->query ( 'CurrentUID' ), $c->query ( 'FileMapper' ), $c->query ( 'ShareMapper' ) ); |
|
| 122 | + $server = $c->query('ServerContainer'); |
|
| 123 | + return new FileService($server->getL10N('ocr'), $server->getLogger(), $c->query('CurrentUID'), $c->query('FileMapper'), $c->query('ShareMapper')); |
|
| 124 | 124 | } ); |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Register the Job Service |
| 128 | 128 | */ |
| 129 | - $container->registerService ( 'JobService', function (IAppContainer $c) { |
|
| 129 | + $container->registerService('JobService', function(IAppContainer $c) { |
|
| 130 | 130 | /** @var \OC\Server $server */ |
| 131 | - $server = $c->query ( 'ServerContainer' ); |
|
| 132 | - return new JobService ( $server->getL10N ( 'ocr' ), $server->getLogger (), $c->query ( 'CurrentUID' ), new View ( '/' . $c->query ( 'CurrentUID' ) . '/files' ), $server->getTempManager (), $c->query ( 'RedisService' ), $c->query ( 'OcrJobMapper' ), $c->query ( 'FileService' ), $c->query ( 'AppConfigService' ) ); |
|
| 131 | + $server = $c->query('ServerContainer'); |
|
| 132 | + return new JobService($server->getL10N('ocr'), $server->getLogger(), $c->query('CurrentUID'), new View('/' . $c->query('CurrentUID') . '/files'), $server->getTempManager(), $c->query('RedisService'), $c->query('OcrJobMapper'), $c->query('FileService'), $c->query('AppConfigService')); |
|
| 133 | 133 | } ); |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Register the Status Service |
| 137 | 137 | */ |
| 138 | - $container->registerService ( 'StatusService', function (IAppContainer $c) { |
|
| 138 | + $container->registerService('StatusService', function(IAppContainer $c) { |
|
| 139 | 139 | /** @var \OC\Server $server */ |
| 140 | - $server = $c->query ( 'ServerContainer' ); |
|
| 141 | - return new StatusService ( $server->getL10N ( 'ocr' ), $server->getLogger (), $c->query ( 'CurrentUID' ), $c->query ( 'OcrJobMapper' ), $c->query ( 'JobService' ) ); |
|
| 140 | + $server = $c->query('ServerContainer'); |
|
| 141 | + return new StatusService($server->getL10N('ocr'), $server->getLogger(), $c->query('CurrentUID'), $c->query('OcrJobMapper'), $c->query('JobService')); |
|
| 142 | 142 | } ); |
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * Controller |
| 146 | 146 | */ |
| 147 | - $container->registerService ( 'StatusController', function (IAppContainer $c) { |
|
| 147 | + $container->registerService('StatusController', function(IAppContainer $c) { |
|
| 148 | 148 | /** @var \OC\Server $server */ |
| 149 | - $server = $c->query ( 'ServerContainer' ); |
|
| 150 | - return new StatusController ( $c->getAppName (), $server->getRequest (), $c->query ( 'StatusService' ) ); |
|
| 149 | + $server = $c->query('ServerContainer'); |
|
| 150 | + return new StatusController($c->getAppName(), $server->getRequest(), $c->query('StatusService')); |
|
| 151 | 151 | } ); |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Controller |
| 155 | 155 | */ |
| 156 | - $container->registerService ( 'JobController', function (IAppContainer $c) { |
|
| 156 | + $container->registerService('JobController', function(IAppContainer $c) { |
|
| 157 | 157 | /** @var \OC\Server $server */ |
| 158 | - $server = $c->query ( 'ServerContainer' ); |
|
| 159 | - return new JobController ( $c->getAppName (), $server->getRequest (), $c->query ( 'JobService' ), $c->query ( 'CurrentUID' ) ); |
|
| 158 | + $server = $c->query('ServerContainer'); |
|
| 159 | + return new JobController($c->getAppName(), $server->getRequest(), $c->query('JobService'), $c->query('CurrentUID')); |
|
| 160 | 160 | } ); |
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | 163 | * Controller |
| 164 | 164 | */ |
| 165 | - $container->registerAlias ( 'PersonalSettingsController', PersonalSettingsController::class ); |
|
| 165 | + $container->registerAlias('PersonalSettingsController', PersonalSettingsController::class); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -170,6 +170,6 @@ discard block |
||
| 170 | 170 | * @codeCoverageIgnore |
| 171 | 171 | */ |
| 172 | 172 | public function registerPersonal() { |
| 173 | - \OCP\App::registerPersonal ( $this->getContainer ()->getAppName (), 'personal' ); |
|
| 173 | + \OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal'); |
|
| 174 | 174 | } |
| 175 | 175 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * $UserId |
| 48 | 48 | */ |
| 49 | 49 | public function __construct($AppName, IRequest $request, JobService $service, $UserId) { |
| 50 | - parent::__construct ( $AppName, $request ); |
|
| 50 | + parent::__construct($AppName, $request); |
|
| 51 | 51 | $this->userId = $UserId; |
| 52 | 52 | $this->service = $service; |
| 53 | 53 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @return DataResponse |
| 63 | 63 | */ |
| 64 | 64 | public function process($languages, $files) { |
| 65 | - return $this->handleNotFound ( function () use ($languages, $files) { |
|
| 66 | - return $this->service->process ( $languages, $files ); |
|
| 65 | + return $this->handleNotFound(function() use ($languages, $files) { |
|
| 66 | + return $this->service->process($languages, $files); |
|
| 67 | 67 | } ); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | * @return \OCP\AppFramework\Http\DataResponse |
| 74 | 74 | */ |
| 75 | 75 | public function getAllJobs() { |
| 76 | - return $this->handleNotFound ( function () { |
|
| 77 | - return $this->service->getAllJobsForUser ( $this->userId ); |
|
| 76 | + return $this->handleNotFound(function() { |
|
| 77 | + return $this->service->getAllJobsForUser($this->userId); |
|
| 78 | 78 | } ); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * @return \OCP\AppFramework\Http\DataResponse |
| 86 | 86 | */ |
| 87 | 87 | public function deleteJob($id) { |
| 88 | - return $this->handleNotFound ( function () use ($id) { |
|
| 89 | - return $this->service->deleteJob ( $id, $this->userId ); |
|
| 88 | + return $this->handleNotFound(function() use ($id) { |
|
| 89 | + return $this->service->deleteJob($id, $this->userId); |
|
| 90 | 90 | } ); |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | \ No newline at end of file |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function checkSharedWithInitiator($fileInfo) { |
| 74 | 74 | try { |
| 75 | - $owner = str_replace ( 'home::', '', $fileInfo->getStoragename () ); |
|
| 75 | + $owner = str_replace('home::', '', $fileInfo->getStoragename()); |
|
| 76 | 76 | if ($this->userId === $owner) { |
| 77 | 77 | // user is owner (no shared file) |
| 78 | 78 | return false; |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | // user is not owner (shared file) |
| 81 | 81 | return true; |
| 82 | 82 | } |
| 83 | - } catch ( Exception $e ) { |
|
| 84 | - $this->handleException ( $e ); |
|
| 83 | + } catch (Exception $e) { |
|
| 84 | + $this->handleException($e); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function buildTarget($fileInfo, $shared) { |
| 96 | 96 | if ($shared) { |
| 97 | - $target = $this->buildTargetForShared ( $fileInfo ); |
|
| 97 | + $target = $this->buildTargetForShared($fileInfo); |
|
| 98 | 98 | } else { |
| 99 | - $target = $this->buildTargetNotForShared ( $fileInfo ); |
|
| 99 | + $target = $this->buildTargetNotForShared($fileInfo); |
|
| 100 | 100 | } |
| 101 | 101 | return $target; |
| 102 | 102 | } |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | 111 | public function buildSource($fileInfo, $shared) { |
| 112 | - $source = $fileInfo->getPath (); |
|
| 112 | + $source = $fileInfo->getPath(); |
|
| 113 | 113 | if ($shared) { |
| 114 | - $source = str_replace ( 'home::', '', $fileInfo->getStoragename () ) . '/' . $source; |
|
| 114 | + $source = str_replace('home::', '', $fileInfo->getStoragename()) . '/' . $source; |
|
| 115 | 115 | } else { |
| 116 | 116 | $source = $this->userId . '/' . $source; |
| 117 | 117 | } |
@@ -128,22 +128,22 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function buildFileInfo($files) { |
| 130 | 130 | try { |
| 131 | - $fileArray = array (); |
|
| 132 | - foreach ( $files as $file ) { |
|
| 131 | + $fileArray = array(); |
|
| 132 | + foreach ($files as $file) { |
|
| 133 | 133 | // Check if anything is missing and file type is correct |
| 134 | - if (! empty ( $file ['id'] )) { |
|
| 134 | + if (!empty ($file ['id'])) { |
|
| 135 | 135 | |
| 136 | - $fileInfo = $this->fileMapper->find ( $file ['id'] ); |
|
| 137 | - $this->checkMimeType ( $fileInfo ); |
|
| 136 | + $fileInfo = $this->fileMapper->find($file ['id']); |
|
| 137 | + $this->checkMimeType($fileInfo); |
|
| 138 | 138 | |
| 139 | - array_push ( $fileArray, $fileInfo ); |
|
| 139 | + array_push($fileArray, $fileInfo); |
|
| 140 | 140 | } else { |
| 141 | - throw new NotFoundException ( $this->l10n->t ( 'Wrong parameter.' ) ); |
|
| 141 | + throw new NotFoundException($this->l10n->t('Wrong parameter.')); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | return $fileArray; |
| 145 | - } catch ( Exception $e ) { |
|
| 146 | - $this->handleException ( $e ); |
|
| 145 | + } catch (Exception $e) { |
|
| 146 | + $this->handleException($e); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return string |
| 155 | 155 | */ |
| 156 | 156 | public function removeFileExtension($job) { |
| 157 | - return substr ( $job->getTarget (), 0, strrpos ( $job->getTarget (), '_OCR' ) ); |
|
| 157 | + return substr($job->getTarget(), 0, strrpos($job->getTarget(), '_OCR')); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * @return integer |
| 165 | 165 | */ |
| 166 | 166 | public function getCorrectType($fileInfo) { |
| 167 | - if ($fileInfo->getMimetype () === OcrConstants::MIME_TYPE_PDF) { |
|
| 167 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
| 168 | 168 | return OcrConstants::OCRmyPDF; |
| 169 | 169 | } else { |
| 170 | 170 | return OcrConstants::TESSERACT; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param string $pathToFile |
| 180 | 180 | */ |
| 181 | 181 | public function execRemove($pathToFile) { |
| 182 | - exec ( 'rm ' . $pathToFile ); |
|
| 182 | + exec('rm ' . $pathToFile); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @return string |
| 192 | 192 | */ |
| 193 | 193 | public function getFileContents($pathToFile) { |
| 194 | - return file_get_contents ( $pathToFile ); |
|
| 194 | + return file_get_contents($pathToFile); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @return boolean |
| 204 | 204 | */ |
| 205 | 205 | public function fileExists($pathToFile) { |
| 206 | - return file_exists ( $pathToFile ); |
|
| 206 | + return file_exists($pathToFile); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -218,32 +218,32 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | protected function buildTargetForShared(File $fileInfo) { |
| 220 | 220 | try { |
| 221 | - $share = $this->shareMapper->find ( $fileInfo->getFileid (), $this->userId, str_replace ( 'home::', '', $fileInfo->getStoragename () ) ); |
|
| 221 | + $share = $this->shareMapper->find($fileInfo->getFileid(), $this->userId, str_replace('home::', '', $fileInfo->getStoragename())); |
|
| 222 | 222 | |
| 223 | 223 | // get rid of the .png or .pdf and so on |
| 224 | - $fileName = substr ( $share->getFileTarget (), 0, (strrpos ( $share->getFileTarget (), '.' )) ); // '/thedom.png' => '/thedom' || '/Test/thedom.png' => '/Test/thedom' |
|
| 224 | + $fileName = substr($share->getFileTarget(), 0, (strrpos($share->getFileTarget(), '.'))); // '/thedom.png' => '/thedom' || '/Test/thedom.png' => '/Test/thedom' |
|
| 225 | 225 | |
| 226 | 226 | // remove everything in front of and including of the first appearance of a slash from behind |
| 227 | - $fileName = substr ( strrchr ( $fileName, "/" ), 1 ); // '/thedom' => 'thedom' || '/Test/thedom' => 'thedom' |
|
| 227 | + $fileName = substr(strrchr($fileName, "/"), 1); // '/thedom' => 'thedom' || '/Test/thedom' => 'thedom' |
|
| 228 | 228 | |
| 229 | 229 | // eliminate the file name from the path |
| 230 | - $filePath = dirname ( $share->getFileTarget () ); // '/thedom.png' => '/' || '/Test/thedom.png' => '/Test' |
|
| 230 | + $filePath = dirname($share->getFileTarget()); // '/thedom.png' => '/' || '/Test/thedom.png' => '/Test' |
|
| 231 | 231 | |
| 232 | 232 | // replace the first slash |
| 233 | - $pos = strpos ( $filePath, '/' ); |
|
| 233 | + $pos = strpos($filePath, '/'); |
|
| 234 | 234 | if ($pos !== false) { |
| 235 | - $filePath = substr_replace ( $filePath, '', $pos, strlen ( '/' ) ); // '/' => '' || '/Test/' => 'Test' |
|
| 235 | + $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/' => '' || '/Test/' => 'Test' |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - if ($fileInfo->getMimetype () === OcrConstants::MIME_TYPE_PDF) { |
|
| 238 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
| 239 | 239 | // PDFs: |
| 240 | - return \OCP\Files::buildNotExistingFileName ( $filePath, $fileName . '_OCR.pdf' ); |
|
| 240 | + return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf'); |
|
| 241 | 241 | } else { |
| 242 | 242 | // IMAGES: |
| 243 | - return \OCP\Files::buildNotExistingFileName ( $filePath, $fileName . '_OCR.txt' ); |
|
| 243 | + return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.txt'); |
|
| 244 | 244 | } |
| 245 | - } catch ( Exception $e ) { |
|
| 246 | - $this->handleException ( $e ); |
|
| 245 | + } catch (Exception $e) { |
|
| 246 | + $this->handleException($e); |
|
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
@@ -260,32 +260,32 @@ discard block |
||
| 260 | 260 | protected function buildTargetNotForShared(File $fileInfo) { |
| 261 | 261 | try { |
| 262 | 262 | // get rid of the .png or .pdf and so on |
| 263 | - $fileName = substr ( $fileInfo->getName (), 0, (strrpos ( $fileInfo->getName (), '.' )) ); // 'thedom.png' => 'thedom' |
|
| 263 | + $fileName = substr($fileInfo->getName(), 0, (strrpos($fileInfo->getName(), '.'))); // 'thedom.png' => 'thedom' |
|
| 264 | 264 | |
| 265 | 265 | // eliminate the file name from the path |
| 266 | - $filePath = str_replace ( $fileInfo->getName (), '', $fileInfo->getPath () ); // 'files/Test/thedom.png' => 'files/Test/' || 'files/thedom.png' => 'files/' |
|
| 266 | + $filePath = str_replace($fileInfo->getName(), '', $fileInfo->getPath()); // 'files/Test/thedom.png' => 'files/Test/' || 'files/thedom.png' => 'files/' |
|
| 267 | 267 | |
| 268 | 268 | // and get the path on top of the files/ dir |
| 269 | - $filePath = str_replace ( 'files', '', $filePath ); // 'files/Test/' => '/Test/' || 'files/' => '/' |
|
| 269 | + $filePath = str_replace('files', '', $filePath); // 'files/Test/' => '/Test/' || 'files/' => '/' |
|
| 270 | 270 | |
| 271 | 271 | // remove the last slash |
| 272 | - $filePath = substr_replace ( $filePath, '', strrpos ( $filePath, '/' ), strlen ( '/' ) ); // '/Test/' => '/Test' || '/' => '' |
|
| 272 | + $filePath = substr_replace($filePath, '', strrpos($filePath, '/'), strlen('/')); // '/Test/' => '/Test' || '/' => '' |
|
| 273 | 273 | |
| 274 | 274 | // replace the first slash |
| 275 | - $pos = strpos ( $filePath, '/' ); |
|
| 275 | + $pos = strpos($filePath, '/'); |
|
| 276 | 276 | if ($pos !== false) { |
| 277 | - $filePath = substr_replace ( $filePath, '', $pos, strlen ( '/' ) ); // '/Test' => '// 'Test' || '/' => '' |
|
| 277 | + $filePath = substr_replace($filePath, '', $pos, strlen('/')); // '/Test' => '// 'Test' || '/' => '' |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ($fileInfo->getMimetype () === OcrConstants::MIME_TYPE_PDF) { |
|
| 280 | + if ($fileInfo->getMimetype() === OcrConstants::MIME_TYPE_PDF) { |
|
| 281 | 281 | // PDFs: |
| 282 | - return \OCP\Files::buildNotExistingFileName ( $filePath, $fileName . '_OCR.pdf' ); |
|
| 282 | + return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf'); |
|
| 283 | 283 | } else { |
| 284 | 284 | // IMAGES: |
| 285 | - return \OCP\Files::buildNotExistingFileName ( $filePath, $fileName . '_OCR.txt' ); |
|
| 285 | + return \OCP\Files::buildNotExistingFileName($filePath, $fileName . '_OCR.txt'); |
|
| 286 | 286 | } |
| 287 | - } catch ( Exception $e ) { |
|
| 288 | - $this->handleException ( $e ); |
|
| 287 | + } catch (Exception $e) { |
|
| 288 | + $this->handleException($e); |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | private function checkMimeType(File $fileInfo) { |
| 298 | 298 | try { |
| 299 | - if (! $fileInfo || ! in_array ( $fileInfo->getMimetype (), OcrConstants::ALLOWED_MIME_TYPES )) { |
|
| 300 | - $this->logger->debug ( 'Getting FileInfo did not work or not included in the ALLOWED_MIMETYPES array.', [ |
|
| 299 | + if (!$fileInfo || !in_array($fileInfo->getMimetype(), OcrConstants::ALLOWED_MIME_TYPES)) { |
|
| 300 | + $this->logger->debug('Getting FileInfo did not work or not included in the ALLOWED_MIMETYPES array.', [ |
|
| 301 | 301 | 'app' => 'ocr' |
| 302 | - ] ); |
|
| 303 | - throw new NotFoundException ( $this->l10n->t ( 'Wrong MIME type.' ) ); |
|
| 302 | + ]); |
|
| 303 | + throw new NotFoundException($this->l10n->t('Wrong MIME type.')); |
|
| 304 | 304 | } |
| 305 | - } catch ( Exception $e ) { |
|
| 306 | - $this->handleException ( $e ); |
|
| 305 | + } catch (Exception $e) { |
|
| 306 | + $this->handleException($e); |
|
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | * @throws NotFoundException |
| 316 | 316 | */ |
| 317 | 317 | private function handleException($e) { |
| 318 | - $this->logger->logException ( $e, [ |
|
| 318 | + $this->logger->logException($e, [ |
|
| 319 | 319 | 'app' => 'ocr', |
| 320 | 320 | 'message' => 'Exception during file service function processing' |
| 321 | - ] ); |
|
| 321 | + ]); |
|
| 322 | 322 | if ($e instanceof NotFoundException) { |
| 323 | - throw new NotFoundException ( $e->getMessage () ); |
|
| 323 | + throw new NotFoundException($e->getMessage()); |
|
| 324 | 324 | } else { |
| 325 | 325 | throw $e; |
| 326 | 326 | } |
@@ -81,23 +81,23 @@ discard block |
||
| 81 | 81 | public function getStatus() { |
| 82 | 82 | try { |
| 83 | 83 | // returns user specific processed files |
| 84 | - $processed = $this->jobMapper->findAllProcessed ( $this->userId ); |
|
| 85 | - $this->jobService->handleProcessed (); |
|
| 84 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
| 85 | + $this->jobService->handleProcessed(); |
|
| 86 | 86 | |
| 87 | 87 | // return user specific pending state |
| 88 | - $pending = $this->jobMapper->findAllPending ( $this->userId ); |
|
| 88 | + $pending = $this->jobMapper->findAllPending($this->userId); |
|
| 89 | 89 | |
| 90 | 90 | // return user specific failed state and set up error |
| 91 | - $failed = $this->jobMapper->findAllFailed ( $this->userId ); |
|
| 92 | - $this->jobService->handleFailed (); |
|
| 91 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
| 92 | + $this->jobService->handleFailed(); |
|
| 93 | 93 | |
| 94 | 94 | return [ |
| 95 | - 'processed' => count ( $processed ), |
|
| 96 | - 'failed' => count ( $failed ), |
|
| 97 | - 'pending' => count ( $pending ) |
|
| 95 | + 'processed' => count($processed), |
|
| 96 | + 'failed' => count($failed), |
|
| 97 | + 'pending' => count($pending) |
|
| 98 | 98 | ]; |
| 99 | - } catch ( Exception $e ) { |
|
| 100 | - $this->handleException ( $e ); |
|
| 99 | + } catch (Exception $e) { |
|
| 100 | + $this->handleException($e); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -109,12 +109,12 @@ discard block |
||
| 109 | 109 | * @throws NotFoundException |
| 110 | 110 | */ |
| 111 | 111 | private function handleException($e) { |
| 112 | - $this->logger->logException ( $e, [ |
|
| 112 | + $this->logger->logException($e, [ |
|
| 113 | 113 | 'app' => 'ocr', |
| 114 | 114 | 'message' => 'Exception during status service function processing' |
| 115 | - ] ); |
|
| 115 | + ]); |
|
| 116 | 116 | if ($e instanceof NotFoundException) { |
| 117 | - throw new NotFoundException ( $e->getMessage () ); |
|
| 117 | + throw new NotFoundException($e->getMessage()); |
|
| 118 | 118 | } else { |
| 119 | 119 | throw $e; |
| 120 | 120 | } |