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