@@ -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 | * |
@@ -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,44 +115,44 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function process($languages, $files) { |
| 117 | 117 | try { |
| 118 | - $this->logger->debug ( 'Will now process files: {files} with languages: {languages}', [ |
|
| 119 | - 'files' => json_encode ( $files ), |
|
| 120 | - 'languages' => json_encode ( $languages ) |
|
| 121 | - ] ); |
|
| 118 | + $this->logger->debug('Will now process files: {files} with languages: {languages}', [ |
|
| 119 | + 'files' => json_encode($files), |
|
| 120 | + 'languages' => json_encode($languages) |
|
| 121 | + ]); |
|
| 122 | 122 | // Check if files and language not empty |
| 123 | - $noLang = $this->noLanguage ( $languages ); |
|
| 124 | - if (! empty ( $files ) && ($this->checkForAcceptedLanguages ( $languages ) || $noLang)) { |
|
| 123 | + $noLang = $this->noLanguage($languages); |
|
| 124 | + if (!empty ($files) && ($this->checkForAcceptedLanguages($languages) || $noLang)) { |
|
| 125 | 125 | // language part: |
| 126 | 126 | if ($noLang) { |
| 127 | - $languages = [ ]; |
|
| 127 | + $languages = []; |
|
| 128 | 128 | } |
| 129 | 129 | // file part: |
| 130 | - $fileInfo = $this->fileService->buildFileInfo ( $files ); |
|
| 131 | - foreach ( $fileInfo as $fInfo ) { |
|
| 130 | + $fileInfo = $this->fileService->buildFileInfo($files); |
|
| 131 | + foreach ($fileInfo as $fInfo) { |
|
| 132 | 132 | // Check Shared |
| 133 | - $shared = $this->fileService->checkSharedWithInitiator ( $fInfo ); |
|
| 134 | - $target = $this->fileService->buildTarget ( $fInfo, $shared ); |
|
| 135 | - $source = $this->fileService->buildSource ( $fInfo, $shared ); |
|
| 133 | + $shared = $this->fileService->checkSharedWithInitiator($fInfo); |
|
| 134 | + $target = $this->fileService->buildTarget($fInfo, $shared); |
|
| 135 | + $source = $this->fileService->buildSource($fInfo, $shared); |
|
| 136 | 136 | |
| 137 | 137 | // set the running type |
| 138 | - $fType = $this->fileService->getCorrectType ( $fInfo ); |
|
| 138 | + $fType = $this->fileService->getCorrectType($fInfo); |
|
| 139 | 139 | |
| 140 | 140 | // create a temp file for ocr processing purposes |
| 141 | - $tempFile = $this->getTempFile ( $fType ); |
|
| 141 | + $tempFile = $this->getTempFile($fType); |
|
| 142 | 142 | |
| 143 | 143 | // Create job object |
| 144 | - $job = new OcrJob ( OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName (), null ); |
|
| 144 | + $job = new OcrJob(OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName(), null); |
|
| 145 | 145 | |
| 146 | 146 | // Init client and send task / job |
| 147 | 147 | // Feed the worker |
| 148 | - $this->redisService->sendJob ( $job, $languages, \OC::$SERVERROOT ); |
|
| 148 | + $this->redisService->sendJob($job, $languages, \OC::$SERVERROOT); |
|
| 149 | 149 | } |
| 150 | 150 | return 'PROCESSING'; |
| 151 | 151 | } else { |
| 152 | - throw new NotFoundException ( $this->l10n->t ( 'Empty parameters passed.' ) ); |
|
| 152 | + throw new NotFoundException($this->l10n->t('Empty parameters passed.')); |
|
| 153 | 153 | } |
| 154 | - } catch ( Exception $e ) { |
|
| 155 | - $this->handleException ( $e ); |
|
| 154 | + } catch (Exception $e) { |
|
| 155 | + $this->handleException($e); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
@@ -166,26 +166,26 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function deleteJob($jobId, $userId) { |
| 168 | 168 | try { |
| 169 | - $job = $this->jobMapper->find ( $jobId ); |
|
| 170 | - if ($job->getUserId () !== $userId) { |
|
| 171 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong owner.' ) ); |
|
| 169 | + $job = $this->jobMapper->find($jobId); |
|
| 170 | + if ($job->getUserId() !== $userId) { |
|
| 171 | + throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.')); |
|
| 172 | 172 | } else { |
| 173 | - $job = $this->jobMapper->delete ( $job ); |
|
| 173 | + $job = $this->jobMapper->delete($job); |
|
| 174 | 174 | } |
| 175 | - $job->setTarget ( null ); |
|
| 176 | - $job->setSource ( null ); |
|
| 177 | - $job->setStatus ( null ); |
|
| 178 | - $job->setTempFile ( null ); |
|
| 179 | - $job->setType ( null ); |
|
| 180 | - $job->setUserId ( null ); |
|
| 181 | - $job->setErrorDisplayed ( null ); |
|
| 175 | + $job->setTarget(null); |
|
| 176 | + $job->setSource(null); |
|
| 177 | + $job->setStatus(null); |
|
| 178 | + $job->setTempFile(null); |
|
| 179 | + $job->setType(null); |
|
| 180 | + $job->setUserId(null); |
|
| 181 | + $job->setErrorDisplayed(null); |
|
| 182 | 182 | return $job; |
| 183 | - } catch ( Exception $e ) { |
|
| 183 | + } catch (Exception $e) { |
|
| 184 | 184 | if ($e instanceof DoesNotExistException) { |
| 185 | - $ex = new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong ID.' ) ); |
|
| 186 | - $this->handleException ( $ex ); |
|
| 185 | + $ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.')); |
|
| 186 | + $this->handleException($ex); |
|
| 187 | 187 | } else { |
| 188 | - $this->handleException ( $e ); |
|
| 188 | + $this->handleException($e); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | } |
@@ -198,21 +198,21 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function getAllJobsForUser($userId) { |
| 200 | 200 | try { |
| 201 | - $jobs = $this->jobMapper->findAll ( $userId ); |
|
| 202 | - $jobsNew = array (); |
|
| 203 | - foreach ( $jobs as $job ) { |
|
| 204 | - $job->setTarget ( null ); |
|
| 205 | - $job->setSource ( null ); |
|
| 206 | - $job->setTempFile ( null ); |
|
| 207 | - $job->setType ( null ); |
|
| 208 | - $job->setUserId ( null ); |
|
| 209 | - $job->setErrorDisplayed ( null ); |
|
| 201 | + $jobs = $this->jobMapper->findAll($userId); |
|
| 202 | + $jobsNew = array(); |
|
| 203 | + foreach ($jobs as $job) { |
|
| 204 | + $job->setTarget(null); |
|
| 205 | + $job->setSource(null); |
|
| 206 | + $job->setTempFile(null); |
|
| 207 | + $job->setType(null); |
|
| 208 | + $job->setUserId(null); |
|
| 209 | + $job->setErrorDisplayed(null); |
|
| 210 | 210 | |
| 211 | - array_push ( $jobsNew, $job ); |
|
| 211 | + array_push($jobsNew, $job); |
|
| 212 | 212 | } |
| 213 | 213 | return $jobsNew; |
| 214 | - } catch ( Exception $e ) { |
|
| 215 | - $this->handleException ( $e ); |
|
| 214 | + } catch (Exception $e) { |
|
| 215 | + $this->handleException($e); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
@@ -222,14 +222,14 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function checkForFinishedJobs() { |
| 224 | 224 | try { |
| 225 | - $finishedJobs = $this->redisService->readingFinishedJobs (); |
|
| 226 | - foreach ( $finishedJobs as $finishedJob ) { |
|
| 227 | - $fJob = json_decode ( $finishedJob ); |
|
| 225 | + $finishedJobs = $this->redisService->readingFinishedJobs(); |
|
| 226 | + foreach ($finishedJobs as $finishedJob) { |
|
| 227 | + $fJob = json_decode($finishedJob); |
|
| 228 | 228 | $this->logger->debug('The following job finished: {job}', ['job' => $fJob]); |
| 229 | - $this->jobFinished ( $fJob->id, $fJob->error, $fJob->log ); |
|
| 229 | + $this->jobFinished($fJob->id, $fJob->error, $fJob->log); |
|
| 230 | 230 | } |
| 231 | - } catch ( Exception $e ) { |
|
| 232 | - throw new NotFoundException ( $this->l10n->t ( 'Reading the finished jobs from redis went wrong.' ) ); |
|
| 231 | + } catch (Exception $e) { |
|
| 232 | + throw new NotFoundException($this->l10n->t('Reading the finished jobs from redis went wrong.')); |
|
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | |
@@ -243,18 +243,18 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | public function jobFinished($jobId, $error, $log) { |
| 245 | 245 | try { |
| 246 | - $job = $this->jobMapper->find ( $jobId ); |
|
| 247 | - if (! $error) { |
|
| 248 | - $job->setStatus ( OcrConstants::STATUS_PROCESSED ); |
|
| 249 | - $this->jobMapper->update ( $job ); |
|
| 246 | + $job = $this->jobMapper->find($jobId); |
|
| 247 | + if (!$error) { |
|
| 248 | + $job->setStatus(OcrConstants::STATUS_PROCESSED); |
|
| 249 | + $this->jobMapper->update($job); |
|
| 250 | 250 | } else { |
| 251 | - $job->setStatus ( OcrConstants::STATUS_FAILED ); |
|
| 252 | - $job->setErrorLog( $log ); |
|
| 253 | - $this->jobMapper->update ( $job ); |
|
| 254 | - $this->logger->error ( $log); |
|
| 251 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 252 | + $job->setErrorLog($log); |
|
| 253 | + $this->jobMapper->update($job); |
|
| 254 | + $this->logger->error($log); |
|
| 255 | 255 | } |
| 256 | - } catch ( Exception $e ) { |
|
| 257 | - $this->handleException ( $e ); |
|
| 256 | + } catch (Exception $e) { |
|
| 257 | + $this->handleException($e); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
@@ -266,24 +266,24 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public function handleProcessed() { |
| 268 | 268 | try { |
| 269 | - $this->logger->debug ( 'Check if files were processed by ocr and if so, put them to the right dirs.'); |
|
| 270 | - $processed = $this->jobMapper->findAllProcessed ( $this->userId ); |
|
| 271 | - foreach ( $processed as $job ) { |
|
| 272 | - if ($this->fileService->fileExists ( $job->getTempFile () )) { |
|
| 269 | + $this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.'); |
|
| 270 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
| 271 | + foreach ($processed as $job) { |
|
| 272 | + if ($this->fileService->fileExists($job->getTempFile())) { |
|
| 273 | 273 | // Save the tmp file with newname |
| 274 | - $this->view->file_put_contents ( $job->getTarget (), $this->fileService->getFileContents ( $job->getTempFile () ) ); |
|
| 275 | - $this->jobMapper->delete ( $job ); |
|
| 276 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
| 274 | + $this->view->file_put_contents($job->getTarget(), $this->fileService->getFileContents($job->getTempFile())); |
|
| 275 | + $this->jobMapper->delete($job); |
|
| 276 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 277 | 277 | } else { |
| 278 | - $job->setStatus ( OcrConstants::STATUS_FAILED ); |
|
| 278 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 279 | 279 | $job->setErrorLog('Temp file does not exist.'); |
| 280 | - $this->jobMapper->update ( $job ); |
|
| 281 | - throw new NotFoundException ( $this->l10n->t ( 'Temp file does not exist.' ) ); |
|
| 280 | + $this->jobMapper->update($job); |
|
| 281 | + throw new NotFoundException($this->l10n->t('Temp file does not exist.')); |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | return $processed; |
| 285 | - } catch ( Exception $e ) { |
|
| 286 | - $this->handleException ( $e ); |
|
| 285 | + } catch (Exception $e) { |
|
| 286 | + $this->handleException($e); |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
@@ -294,20 +294,20 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | public function handleFailed() { |
| 296 | 296 | try { |
| 297 | - $failed = $this->jobMapper->findAllFailed ( $this->userId ); |
|
| 298 | - foreach ( $failed as $job ) { |
|
| 297 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
| 298 | + foreach ($failed as $job) { |
|
| 299 | 299 | // clean the tempfile |
| 300 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
| 300 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 301 | 301 | // set error displayed |
| 302 | - $job->setErrorDisplayed ( true ); |
|
| 303 | - $this->jobMapper->update ( $job ); |
|
| 302 | + $job->setErrorDisplayed(true); |
|
| 303 | + $this->jobMapper->update($job); |
|
| 304 | 304 | } |
| 305 | - $this->logger->debug ( 'Following jobs failed: {failed}', [ |
|
| 306 | - 'failed' => json_encode ( $failed ) |
|
| 307 | - ] ); |
|
| 305 | + $this->logger->debug('Following jobs failed: {failed}', [ |
|
| 306 | + 'failed' => json_encode($failed) |
|
| 307 | + ]); |
|
| 308 | 308 | return $failed; |
| 309 | - } catch ( Exception $e ) { |
|
| 310 | - $this->handleException ( $e ); |
|
| 309 | + } catch (Exception $e) { |
|
| 310 | + $this->handleException($e); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | private function getTempFile($type) { |
| 323 | 323 | if ($type == OcrConstants::TESSERACT) { |
| 324 | - $fileName = tempnam ( $this->tempM->getTempBaseDir (), 'ocr_' ); |
|
| 325 | - unlink ( $fileName ); |
|
| 324 | + $fileName = tempnam($this->tempM->getTempBaseDir(), 'ocr_'); |
|
| 325 | + unlink($fileName); |
|
| 326 | 326 | $fileNameWithPostfix = $fileName . '.txt'; |
| 327 | - touch ( $fileNameWithPostfix ); |
|
| 328 | - chmod ( $fileNameWithPostfix, 0600 ); |
|
| 327 | + touch($fileNameWithPostfix); |
|
| 328 | + chmod($fileNameWithPostfix, 0600); |
|
| 329 | 329 | return $fileNameWithPostfix; |
| 330 | 330 | } else { |
| 331 | - return tempnam ( $this->tempM->getTempBaseDir (), 'ocr_' ); |
|
| 331 | + return tempnam($this->tempM->getTempBaseDir(), 'ocr_'); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | * @return boolean |
| 340 | 340 | */ |
| 341 | 341 | private function checkForAcceptedLanguages($languages) { |
| 342 | - $installedLanguages = explode ( ';', $this->appConfigService->getAppValue ( 'languages' ) ); |
|
| 343 | - if (count ( array_diff ( $languages, $installedLanguages ) ) === 0) { |
|
| 342 | + $installedLanguages = explode(';', $this->appConfigService->getAppValue('languages')); |
|
| 343 | + if (count(array_diff($languages, $installedLanguages)) === 0) { |
|
| 344 | 344 | return true; |
| 345 | 345 | } else { |
| 346 | 346 | return false; |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * @return boolean |
| 355 | 355 | */ |
| 356 | 356 | private function noLanguage($languages) { |
| 357 | - if (in_array ( 'any', $languages )) { |
|
| 357 | + if (in_array('any', $languages)) { |
|
| 358 | 358 | return true; |
| 359 | 359 | } else { |
| 360 | 360 | return false; |
@@ -369,12 +369,12 @@ discard block |
||
| 369 | 369 | * @throws NotFoundException |
| 370 | 370 | */ |
| 371 | 371 | private function handleException($e) { |
| 372 | - $this->logger->logException ( $e, [ |
|
| 372 | + $this->logger->logException($e, [ |
|
| 373 | 373 | 'app' => 'ocr', |
| 374 | 374 | 'message' => 'Exception during job service function processing' |
| 375 | - ] ); |
|
| 375 | + ]); |
|
| 376 | 376 | if ($e instanceof NotFoundException) { |
| 377 | - throw new NotFoundException ( $e->getMessage () ); |
|
| 377 | + throw new NotFoundException($e->getMessage()); |
|
| 378 | 378 | } else { |
| 379 | 379 | throw $e; |
| 380 | 380 | } |
@@ -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 |
@@ -18,15 +18,15 @@ |
||
| 18 | 18 | * it's instantiated in there |
| 19 | 19 | */ |
| 20 | 20 | return [ |
| 21 | - 'routes' => [ |
|
| 21 | + 'routes' => [ |
|
| 22 | 22 | ['name' => 'Job#process', 'url' => '/', 'verb' => 'POST'], |
| 23 | - ['name' => 'Job#deleteJob', 'url' => '/', 'verb' => 'DELETE'], |
|
| 24 | - ['name' => 'Job#getAllJobs', 'url' => '/', 'verb' => 'GET'], |
|
| 23 | + ['name' => 'Job#deleteJob', 'url' => '/', 'verb' => 'DELETE'], |
|
| 24 | + ['name' => 'Job#getAllJobs', 'url' => '/', 'verb' => 'GET'], |
|
| 25 | 25 | ['name' => 'Status#getStatus', 'url' => '/status', 'verb' => 'GET'], |
| 26 | - // settings |
|
| 27 | - ['name' => 'AdminSettings#setLanguages', 'url' => '/admin/languages', 'verb' => 'POST'], |
|
| 28 | - ['name' => 'AdminSettings#setRedis', 'url' => '/admin/redis', 'verb' => 'POST'], |
|
| 29 | - ['name' => 'AdminSettings#getLanguages', 'url' => '/languages', 'verb' => 'GET'], |
|
| 30 | - ['name' => 'AdminSettings#evaluateRedisSettings', 'url' => '/redis', 'verb' => 'GET'] |
|
| 31 | - ] |
|
| 26 | + // settings |
|
| 27 | + ['name' => 'AdminSettings#setLanguages', 'url' => '/admin/languages', 'verb' => 'POST'], |
|
| 28 | + ['name' => 'AdminSettings#setRedis', 'url' => '/admin/redis', 'verb' => 'POST'], |
|
| 29 | + ['name' => 'AdminSettings#getLanguages', 'url' => '/languages', 'verb' => 'GET'], |
|
| 30 | + ['name' => 'AdminSettings#evaluateRedisSettings', 'url' => '/redis', 'verb' => 'GET'] |
|
| 31 | + ] |
|
| 32 | 32 | ]; |
| 33 | 33 | \ No newline at end of file |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param string $userId |
| 41 | 41 | */ |
| 42 | 42 | public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) { |
| 43 | - parent::__construct ( $appName, $request ); |
|
| 43 | + parent::__construct($appName, $request); |
|
| 44 | 44 | $this->l10n = $l10n; |
| 45 | 45 | $this->appConfig = $appConfig; |
| 46 | 46 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * @return DataResponse |
| 52 | 52 | */ |
| 53 | 53 | public function getLanguages() { |
| 54 | - return $this->handleNotFound ( function () { |
|
| 55 | - return [ 'languages' => $this->appConfig->getAppValue ( OcrConstants::LANGUAGES_CONFIG_KEY )]; |
|
| 54 | + return $this->handleNotFound(function() { |
|
| 55 | + return ['languages' => $this->appConfig->getAppValue(OcrConstants::LANGUAGES_CONFIG_KEY)]; |
|
| 56 | 56 | } ); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @return DataResponse |
| 63 | 63 | */ |
| 64 | 64 | public function evaluateRedisSettings() { |
| 65 | - return $this->handleNotFound ( function () { |
|
| 66 | - return [ 'set' => $this->appConfig->evaluateRedisSettings ()]; |
|
| 65 | + return $this->handleNotFound(function() { |
|
| 66 | + return ['set' => $this->appConfig->evaluateRedisSettings()]; |
|
| 67 | 67 | } ); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | * @return DataResponse |
| 75 | 75 | */ |
| 76 | 76 | public function setLanguages($languages) { |
| 77 | - return $this->handleNotFound ( function () use ($languages) { |
|
| 77 | + return $this->handleNotFound(function() use ($languages) { |
|
| 78 | 78 | if ($languages !== null) { |
| 79 | - $this->appConfig->setAppValue ( OcrConstants::LANGUAGES_CONFIG_KEY, $languages ); |
|
| 80 | - return $this->l10n->t ( 'Saved' ); |
|
| 79 | + $this->appConfig->setAppValue(OcrConstants::LANGUAGES_CONFIG_KEY, $languages); |
|
| 80 | + return $this->l10n->t('Saved'); |
|
| 81 | 81 | } else { |
| 82 | - throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) ); |
|
| 82 | + throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.')); |
|
| 83 | 83 | } |
| 84 | 84 | } ); |
| 85 | 85 | } |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | * @return DataResponse |
| 94 | 94 | */ |
| 95 | 95 | public function setRedis($redisHost, $redisPort, $redisDb) { |
| 96 | - return $this->handleNotFound ( function () use ($redisHost, $redisPort, $redisDb) { |
|
| 96 | + return $this->handleNotFound(function() use ($redisHost, $redisPort, $redisDb) { |
|
| 97 | 97 | if ($redisHost !== null && $redisPort !== null && $redisDb !== null) { |
| 98 | - $this->appConfig->setAppValue ( OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost ); |
|
| 99 | - $this->appConfig->setAppValue ( OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort ); |
|
| 100 | - $this->appConfig->setAppValue ( OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb ); |
|
| 101 | - return $this->l10n->t ( 'Saved' ); |
|
| 98 | + $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost); |
|
| 99 | + $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort); |
|
| 100 | + $this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb); |
|
| 101 | + return $this->l10n->t('Saved'); |
|
| 102 | 102 | } else { |
| 103 | - throw new NotFoundException ( $this->l10n->t ( 'The Redis settings do not have the right format.' ) ); |
|
| 103 | + throw new NotFoundException($this->l10n->t('The Redis settings do not have the right format.')); |
|
| 104 | 104 | } |
| 105 | 105 | } ); |
| 106 | 106 | } |
@@ -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,12 +296,12 @@ 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.'); |
|
| 301 | - throw new NotFoundException ( $this->l10n->t ( 'Wrong MIME type.' ) ); |
|
| 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 | + throw new NotFoundException($this->l10n->t('Wrong MIME type.')); |
|
| 302 | 302 | } |
| 303 | - } catch ( Exception $e ) { |
|
| 304 | - $this->handleException ( $e ); |
|
| 303 | + } catch (Exception $e) { |
|
| 304 | + $this->handleException($e); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
@@ -313,12 +313,12 @@ discard block |
||
| 313 | 313 | * @throws NotFoundException |
| 314 | 314 | */ |
| 315 | 315 | private function handleException($e) { |
| 316 | - $this->logger->logException ( $e, [ |
|
| 316 | + $this->logger->logException($e, [ |
|
| 317 | 317 | 'app' => 'ocr', |
| 318 | 318 | 'message' => 'Exception during file service function processing' |
| 319 | - ] ); |
|
| 319 | + ]); |
|
| 320 | 320 | if ($e instanceof NotFoundException) { |
| 321 | - throw new NotFoundException ( $e->getMessage () ); |
|
| 321 | + throw new NotFoundException($e->getMessage()); |
|
| 322 | 322 | } else { |
| 323 | 323 | throw $e; |
| 324 | 324 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | 54 | public function getAppValue($key) { |
| 55 | - return $this->config->getAppValue ( $this->appName, $key ); |
|
| 55 | + return $this->config->getAppValue($this->appName, $key); |
|
| 56 | 56 | } |
| 57 | 57 | /** |
| 58 | 58 | * Evaluate if all redis related settings are set. |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function evaluateRedisSettings() { |
| 63 | 63 | |
| 64 | - if ($this->config->getAppValue ( $this->appName, OcrConstants::REDIS_CONFIG_KEY_HOST ) !== '' && $this->config->getAppValue ( $this->appName, OcrConstants::REDIS_CONFIG_KEY_PORT ) !== '' && $this->config->getAppValue ( $this->appName, OcrConstants::REDIS_CONFIG_KEY_DB ) !== '') { |
|
| 64 | + if ($this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_HOST) !== '' && $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_PORT) !== '' && $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_DB) !== '') { |
|
| 65 | 65 | return true; |
| 66 | 66 | } else { |
| 67 | 67 | return false; |
@@ -76,27 +76,27 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function setAppValue($key, $value) { |
| 78 | 78 | if ($key === OcrConstants::LANGUAGES_CONFIG_KEY) { |
| 79 | - 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 )) { |
|
| 80 | - throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) ); |
|
| 79 | + 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)) { |
|
| 80 | + throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.')); |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | if ($key === OcrConstants::REDIS_CONFIG_KEY_HOST) { |
| 84 | - if (! preg_match ( '/(^(([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])$)/', $value )) { |
|
| 85 | - throw new NotFoundException ( $this->l10n->t ( 'The redis host is not specified in the correct format.' ) ); |
|
| 84 | + if (!preg_match('/(^(([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])$)/', $value)) { |
|
| 85 | + throw new NotFoundException($this->l10n->t('The redis host is not specified in the correct format.')); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | if ($key === OcrConstants::REDIS_CONFIG_KEY_PORT) { |
| 89 | - $value = intval ( $value ); |
|
| 90 | - if (! ($value > 0 && $value < 65535)) { |
|
| 91 | - throw new NotFoundException ( $this->l10n->t ( 'The redis port number is not specified in the correct format.' ) ); |
|
| 89 | + $value = intval($value); |
|
| 90 | + if (!($value > 0 && $value < 65535)) { |
|
| 91 | + throw new NotFoundException($this->l10n->t('The redis port number is not specified in the correct format.')); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | if ($key === OcrConstants::REDIS_CONFIG_KEY_DB) { |
| 95 | - $value = intval ( $value ); |
|
| 96 | - if (! ($value >= 0)) { |
|
| 97 | - throw new NotFoundException ( $this->l10n->t ( 'The redis db is not specified in the correct format.' ) ); |
|
| 95 | + $value = intval($value); |
|
| 96 | + if (!($value >= 0)) { |
|
| 97 | + throw new NotFoundException($this->l10n->t('The redis db is not specified in the correct format.')); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - return $this->config->setAppValue ( $this->appName, $key, $value ); |
|
| 100 | + return $this->config->setAppValue($this->appName, $key, $value); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | \ No newline at end of file |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 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,12 +112,12 @@ 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 | 'app' => 'ocr', |
| 117 | 117 | 'message' => 'Exception during status service function processing' |
| 118 | - ] ); |
|
| 118 | + ]); |
|
| 119 | 119 | if ($e instanceof NotFoundException) { |
| 120 | - throw new NotFoundException ( $e->getMessage () ); |
|
| 120 | + throw new NotFoundException($e->getMessage()); |
|
| 121 | 121 | } else { |
| 122 | 122 | throw $e; |
| 123 | 123 | } |