@@ -38,7 +38,7 @@ |
||
| 38 | 38 | /** |
| 39 | 39 | * Checks if a worker is active and registered at the Gearman Job Server. |
| 40 | 40 | * returns false if not. |
| 41 | - * @return bool |
|
| 41 | + * @return boolean|null |
|
| 42 | 42 | */ |
| 43 | 43 | public function workerExists(){ |
| 44 | 44 | try { |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * returns false if not. |
| 41 | 41 | * @return bool |
| 42 | 42 | */ |
| 43 | - public function workerExists(){ |
|
| 43 | + public function workerExists() { |
|
| 44 | 44 | try { |
| 45 | 45 | $checkCommand = 'gearadmin -h 127.0.0.1 -p 4730 --workers 2>&1'; |
| 46 | 46 | exec($checkCommand, $result, $success); |
@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | throw new NotFoundException('Gearman worker detection failed.'); |
| 49 | 49 | } |
| 50 | 50 | // look into the resulting array. 3 because first row is the ps checking command, second row is the grep command separated from the ps and 3rd or more has to be the GearmanOCRWorker.php. |
| 51 | - foreach ($result as $res){ |
|
| 52 | - if(strpos($res, 'ocr') !== false){ |
|
| 51 | + foreach ($result as $res) { |
|
| 52 | + if (strpos($res, 'ocr') !== false) { |
|
| 53 | 53 | $this->logger->debug('Worker found.', ['app' => 'ocr']); |
| 54 | 54 | return true; |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | $this->logger->debug('No worker found.', ['app' => 'ocr']); |
| 58 | 58 | return false; |
| 59 | - } catch (Exception $e){ |
|
| 59 | + } catch (Exception $e) { |
|
| 60 | 60 | $this->handleException($e); |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * Processes and prepares the files for ocr. |
| 131 | 131 | * Sends the stuff to the gearman client in order to ocr async. |
| 132 | 132 | * |
| 133 | - * @param $language |
|
| 133 | + * @param string $language |
|
| 134 | 134 | * @param array $files |
| 135 | 135 | * @return string |
| 136 | 136 | */ |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * the gearman worker should call it automatically after each processing step. |
| 200 | 200 | * |
| 201 | 201 | * @param $statusId |
| 202 | - * @param $failed |
|
| 202 | + * @param boolean $failed |
|
| 203 | 203 | */ |
| 204 | 204 | public function complete($statusId, $failed){ |
| 205 | 205 | try{ |
@@ -334,12 +334,13 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | 336 | * Inits the Gearman client and sends the task to the background worker (async) |
| 337 | - * @param $type |
|
| 337 | + * @param string $type |
|
| 338 | 338 | * @param $datadirectory |
| 339 | 339 | * @param $path |
| 340 | 340 | * @param $tempFile |
| 341 | 341 | * @param $language |
| 342 | 342 | * @param $statusId |
| 343 | + * @param OcrStatus $status |
|
| 343 | 344 | */ |
| 344 | 345 | private function sendGearmanJob($type, $datadirectory, $path, $tempFile, $language, $status, $occDir){ |
| 345 | 346 | try { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return array Languages |
| 99 | 99 | */ |
| 100 | - public function listLanguages(){ |
|
| 100 | + public function listLanguages() { |
|
| 101 | 101 | try { |
| 102 | 102 | $success = -1; |
| 103 | 103 | $this->logger->debug('Fetching languages. ', ['app' => 'ocr']); |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | array_push($languages, $tdname); |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | - $this->logger->debug('Fetched languages: '.json_encode($languages), ['app' => 'ocr']); |
|
| 118 | + $this->logger->debug('Fetched languages: ' . json_encode($languages), ['app' => 'ocr']); |
|
| 119 | 119 | return $languages; |
| 120 | 120 | } else { |
| 121 | 121 | throw new NotFoundException('No languages found.'); |
| 122 | 122 | } |
| 123 | - }catch(Exception $e){ |
|
| 123 | + } catch (Exception $e) { |
|
| 124 | 124 | $this->handleException($e); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function process($language, $files) { |
| 137 | 137 | try { |
| 138 | - $this->logger->debug('Will now process files: '.json_encode($files) . ' with language: ' . json_encode($language), ['app' => 'ocr']); |
|
| 138 | + $this->logger->debug('Will now process files: ' . json_encode($files) . ' with language: ' . json_encode($language), ['app' => 'ocr']); |
|
| 139 | 139 | // Check if files and language not empty |
| 140 | - if(!empty($files) && !empty($language) && in_array($language, $this->listLanguages())){ |
|
| 140 | + if (!empty($files) && !empty($language) && in_array($language, $this->listLanguages())) { |
|
| 141 | 141 | // get the array with full fileinfo |
| 142 | 142 | $fileInfo = $this->buildFileInfo($files); |
| 143 | - foreach ($fileInfo as $fInfo){ |
|
| 143 | + foreach ($fileInfo as $fInfo) { |
|
| 144 | 144 | // Check if filelock existing |
| 145 | 145 | // TODO: FileLock maybe \OC\Files\View::lockFile() |
| 146 | 146 | // get new name for saving purpose |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | $tempFile = $this->tempM->getTemporaryFile(); |
| 151 | 151 | |
| 152 | 152 | // set the gearman running type |
| 153 | - if($fInfo->getMimetype() === $this::MIMETYPE_PDF){ |
|
| 153 | + if ($fInfo->getMimetype() === $this::MIMETYPE_PDF) { |
|
| 154 | 154 | $ftype = 'mypdf'; |
| 155 | - }else{ |
|
| 155 | + } else { |
|
| 156 | 156 | $ftype = 'tess'; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | $this->sendGearmanJob($ftype, $this->config->getSystemValue('datadirectory'), $fInfo->getPath(), $tempFile, $language, $status, \OC::$SERVERROOT); |
| 165 | 165 | } |
| 166 | 166 | return 'PROCESSING'; |
| 167 | - }else{ |
|
| 167 | + } else { |
|
| 168 | 168 | throw new NotFoundException('Empty parameters.'); |
| 169 | 169 | } |
| 170 | - }catch(Exception $e){ |
|
| 170 | + } catch (Exception $e) { |
|
| 171 | 171 | $this->handleException($e); |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | - public function status(){ |
|
| 181 | + public function status() { |
|
| 182 | 182 | try { |
| 183 | 183 | // TODO: release lock |
| 184 | 184 | $processed = $this->handleProcessed(); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $pending = count($this->statusMapper->findAllPending($this->userId)); |
| 189 | 189 | |
| 190 | 190 | return ['processed' => $processed, 'failed' => $failed, 'pending' => $pending]; |
| 191 | - }catch (Exception $e){ |
|
| 191 | + } catch (Exception $e) { |
|
| 192 | 192 | $this->handleException($e); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -200,18 +200,18 @@ discard block |
||
| 200 | 200 | * @param $statusId |
| 201 | 201 | * @param $failed |
| 202 | 202 | */ |
| 203 | - public function complete($statusId, $failed){ |
|
| 204 | - try{ |
|
| 203 | + public function complete($statusId, $failed) { |
|
| 204 | + try { |
|
| 205 | 205 | $status = $this->statusMapper->find($statusId); |
| 206 | - if(!$failed) { |
|
| 206 | + if (!$failed) { |
|
| 207 | 207 | $status->setStatus('PROCESSED'); |
| 208 | 208 | $this->statusMapper->update($status); |
| 209 | - }else{ |
|
| 209 | + } else { |
|
| 210 | 210 | $status->setStatus('FAILED'); |
| 211 | 211 | $this->statusMapper->update($status); |
| 212 | 212 | } |
| 213 | - } catch (Exception $e){ |
|
| 214 | - if ($e instanceof NotFoundException){ |
|
| 213 | + } catch (Exception $e) { |
|
| 214 | + if ($e instanceof NotFoundException) { |
|
| 215 | 215 | $status->setStatus('FAILED'); |
| 216 | 216 | $this->statusMapper->update($status); |
| 217 | 217 | $this->handleException($e); |
@@ -226,28 +226,28 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @return int |
| 228 | 228 | */ |
| 229 | - private function handleProcessed(){ |
|
| 229 | + private function handleProcessed() { |
|
| 230 | 230 | try { |
| 231 | 231 | $this->logger->debug('Find processed ocr files and put them to the right dirs.', ['app' => 'ocr']); |
| 232 | 232 | $processed = $this->statusMapper->findAllProcessed($this->userId); |
| 233 | 233 | foreach ($processed as $status) { |
| 234 | - if ($status->getType() === 'tess' && file_exists($status->getTempFile().'.txt')) { |
|
| 234 | + if ($status->getType() === 'tess' && file_exists($status->getTempFile() . '.txt')) { |
|
| 235 | 235 | //Save the tmp file with newname |
| 236 | - $this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile() . '.txt'));// need .txt because tesseract saves it like this |
|
| 236 | + $this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile() . '.txt')); // need .txt because tesseract saves it like this |
|
| 237 | 237 | // Cleaning temp files |
| 238 | 238 | $this->statusMapper->delete($status); |
| 239 | 239 | exec('rm ' . $status->getTempFile() . '.txt'); |
| 240 | 240 | } elseif ($status->getType() === 'mypdf' && file_exists($status->getTempFile())) { |
| 241 | 241 | //Save the tmp file with newname |
| 242 | - $this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile()));// don't need to extend with .pdf / it uses the tmp file to save |
|
| 242 | + $this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile())); // don't need to extend with .pdf / it uses the tmp file to save |
|
| 243 | 243 | $this->statusMapper->delete($status); |
| 244 | 244 | exec('rm ' . $status->getTempFile()); |
| 245 | - }else{ |
|
| 245 | + } else { |
|
| 246 | 246 | throw new NotFoundException('Temp file does not exist.'); |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | return count($processed); |
| 250 | - }catch (Exception $e){ |
|
| 250 | + } catch (Exception $e) { |
|
| 251 | 251 | $this->handleException($e); |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @return array |
| 259 | 259 | */ |
| 260 | - private function handleFailed(){ |
|
| 260 | + private function handleFailed() { |
|
| 261 | 261 | try { |
| 262 | 262 | $failed = $this->statusMapper->findAllFailed($this->userId); |
| 263 | 263 | foreach ($failed as $status) { |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | // clean from db |
| 267 | 267 | $this->statusMapper->delete($status); |
| 268 | 268 | } |
| 269 | - $this->logger->debug('Following status objects failed: '.json_encode($failed), ['app' => 'ocr']); |
|
| 269 | + $this->logger->debug('Following status objects failed: ' . json_encode($failed), ['app' => 'ocr']); |
|
| 270 | 270 | return $failed; |
| 271 | - }catch (Exception $e){ |
|
| 271 | + } catch (Exception $e) { |
|
| 272 | 272 | $this->handleException($e); |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -280,19 +280,19 @@ discard block |
||
| 280 | 280 | * @param Files\FileInfo $fileInfo |
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | - private function buildNewName(Files\FileInfo $fileInfo){ |
|
| 283 | + private function buildNewName(Files\FileInfo $fileInfo) { |
|
| 284 | 284 | // get rid of the .png or .pdf and so on |
| 285 | - $fileName = substr($fileInfo->getName(),0,-4); |
|
| 285 | + $fileName = substr($fileInfo->getName(), 0, -4); |
|
| 286 | 286 | // eliminate the file name from the path |
| 287 | - $filePath = str_replace($fileInfo->getName(),'',$fileInfo->getPath()); |
|
| 287 | + $filePath = str_replace($fileInfo->getName(), '', $fileInfo->getPath()); |
|
| 288 | 288 | // and get the path on top of the user/files/ dir |
| 289 | - $filePath = str_replace('/'.$this->userId.'/files','',$filePath); |
|
| 290 | - if($fileInfo->getMimetype() === $this::MIMETYPE_PDF){ |
|
| 289 | + $filePath = str_replace('/' . $this->userId . '/files', '', $filePath); |
|
| 290 | + if ($fileInfo->getMimetype() === $this::MIMETYPE_PDF) { |
|
| 291 | 291 | // PDFs: |
| 292 | - return Files::buildNotExistingFileName($filePath, $fileName.'_OCR.pdf'); |
|
| 292 | + return Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf'); |
|
| 293 | 293 | } else { |
| 294 | 294 | // IMAGES: |
| 295 | - return Files::buildNotExistingFileName($filePath, $fileName.'_OCR.txt'); |
|
| 295 | + return Files::buildNotExistingFileName($filePath, $fileName . '_OCR.txt'); |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | * @return array of Files\FileInfo |
| 305 | 305 | * @throws NotFoundException |
| 306 | 306 | */ |
| 307 | - private function buildFileInfo(array $files){ |
|
| 307 | + private function buildFileInfo(array $files) { |
|
| 308 | 308 | try { |
| 309 | 309 | $fileArray = array(); |
| 310 | 310 | foreach ($files as $file) { |
| 311 | 311 | // Check if anything is missing and file type is correct |
| 312 | 312 | if ((!empty($file['path']) || !empty($file['directory'])) && $file['type'] === 'file') { |
| 313 | - if(empty($file['path'])){ |
|
| 313 | + if (empty($file['path'])) { |
|
| 314 | 314 | //Because new updated files have the property directory instead of path |
| 315 | 315 | $file['path'] = $file['directory']; |
| 316 | 316 | } |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | * @param $file |
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | - private function getCorrectPath($file){ |
|
| 341 | - if($file['path'] === '/'){ |
|
| 342 | - $path = ''. '/' . $file['name']; |
|
| 343 | - }else{ |
|
| 344 | - $path = $file['path']. '/' . $file['name']; |
|
| 340 | + private function getCorrectPath($file) { |
|
| 341 | + if ($file['path'] === '/') { |
|
| 342 | + $path = '' . '/' . $file['name']; |
|
| 343 | + } else { |
|
| 344 | + $path = $file['path'] . '/' . $file['name']; |
|
| 345 | 345 | } |
| 346 | 346 | return $path; |
| 347 | 347 | } |
@@ -355,15 +355,15 @@ discard block |
||
| 355 | 355 | * @param $language |
| 356 | 356 | * @param $statusId |
| 357 | 357 | */ |
| 358 | - private function sendGearmanJob($type, $datadirectory, $path, $tempFile, $language, $status, $occDir){ |
|
| 358 | + private function sendGearmanJob($type, $datadirectory, $path, $tempFile, $language, $status, $occDir) { |
|
| 359 | 359 | try { |
| 360 | - if($this->workerService->workerExists() === false){ |
|
| 360 | + if ($this->workerService->workerExists() === false) { |
|
| 361 | 361 | throw new NotFoundException('No gearman worker exists.'); |
| 362 | 362 | } |
| 363 | 363 | $this->statusMapper->insert($status); |
| 364 | 364 | // Gearman thing |
| 365 | 365 | $client = new \GearmanClient(); |
| 366 | - $client->addServer('127.0.0.1',4730); |
|
| 366 | + $client->addServer('127.0.0.1', 4730); |
|
| 367 | 367 | $result = $client->doBackground("ocr", json_encode(array( |
| 368 | 368 | 'type' => $type, |
| 369 | 369 | 'datadirectory' => $datadirectory, |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | 'statusid' => $status->getId(), |
| 374 | 374 | 'occdir' => $occDir |
| 375 | 375 | ))); |
| 376 | - $this->logger->debug('Gearman Client output: '.json_encode($result), ['app' => 'ocr']); |
|
| 376 | + $this->logger->debug('Gearman Client output: ' . json_encode($result), ['app' => 'ocr']); |
|
| 377 | 377 | } catch (Exception $e) { |
| 378 | 378 | $this->handleException($e); |
| 379 | 379 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } else { |
| 121 | 121 | throw new NotFoundException('No languages found.'); |
| 122 | 122 | } |
| 123 | - }catch(Exception $e){ |
|
| 123 | + } catch(Exception $e){ |
|
| 124 | 124 | $this->handleException($e); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // set the gearman running type |
| 153 | 153 | if($fInfo->getMimetype() === $this::MIMETYPE_PDF){ |
| 154 | 154 | $ftype = 'mypdf'; |
| 155 | - }else{ |
|
| 155 | + } else{ |
|
| 156 | 156 | $ftype = 'tess'; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | $this->sendGearmanJob($ftype, $this->config->getSystemValue('datadirectory'), $fInfo->getPath(), $tempFile, $language, $status, \OC::$SERVERROOT); |
| 165 | 165 | } |
| 166 | 166 | return 'PROCESSING'; |
| 167 | - }else{ |
|
| 167 | + } else{ |
|
| 168 | 168 | throw new NotFoundException('Empty parameters.'); |
| 169 | 169 | } |
| 170 | - }catch(Exception $e){ |
|
| 170 | + } catch(Exception $e){ |
|
| 171 | 171 | $this->handleException($e); |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $pending = count($this->statusMapper->findAllPending($this->userId)); |
| 189 | 189 | |
| 190 | 190 | return ['processed' => $processed, 'failed' => $failed, 'pending' => $pending]; |
| 191 | - }catch (Exception $e){ |
|
| 191 | + } catch (Exception $e){ |
|
| 192 | 192 | $this->handleException($e); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | if(!$failed) { |
| 207 | 207 | $status->setStatus('PROCESSED'); |
| 208 | 208 | $this->statusMapper->update($status); |
| 209 | - }else{ |
|
| 209 | + } else{ |
|
| 210 | 210 | $status->setStatus('FAILED'); |
| 211 | 211 | $this->statusMapper->update($status); |
| 212 | 212 | } |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | $this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile()));// don't need to extend with .pdf / it uses the tmp file to save |
| 243 | 243 | $this->statusMapper->delete($status); |
| 244 | 244 | exec('rm ' . $status->getTempFile()); |
| 245 | - }else{ |
|
| 245 | + } else{ |
|
| 246 | 246 | throw new NotFoundException('Temp file does not exist.'); |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | return count($processed); |
| 250 | - }catch (Exception $e){ |
|
| 250 | + } catch (Exception $e){ |
|
| 251 | 251 | $this->handleException($e); |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | $this->logger->debug('Following status objects failed: '.json_encode($failed), ['app' => 'ocr']); |
| 270 | 270 | return $failed; |
| 271 | - }catch (Exception $e){ |
|
| 271 | + } catch (Exception $e){ |
|
| 272 | 272 | $this->handleException($e); |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | private function getCorrectPath($file){ |
| 341 | 341 | if($file['path'] === '/'){ |
| 342 | 342 | $path = ''. '/' . $file['name']; |
| 343 | - }else{ |
|
| 343 | + } else{ |
|
| 344 | 344 | $path = $file['path']. '/' . $file['name']; |
| 345 | 345 | } |
| 346 | 346 | return $path; |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * @param $id |
| 37 | 37 | * @return \OCP\AppFramework\Db\Entity |
| 38 | 38 | */ |
| 39 | - public function find($id){ |
|
| 39 | + public function find($id) { |
|
| 40 | 40 | $sql = 'SELECT * FROM *PREFIX*ocr_status WHERE id = ?'; |
| 41 | 41 | return $this->findEntity($sql, [$id]); |
| 42 | 42 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * Register the Gearman Worker Service |
| 66 | 66 | */ |
| 67 | - $container->registerService('GearmanWorkerService', function (IAppContainer $c){ |
|
| 67 | + $container->registerService('GearmanWorkerService', function(IAppContainer $c) { |
|
| 68 | 68 | /** @var \OC\Server $server */ |
| 69 | 69 | $server = $c->query('ServerContainer'); |
| 70 | 70 | return new GearmanWorkerService( |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $server->getConfig(), |
| 95 | 95 | $c->query('GearmanWorkerService'), |
| 96 | 96 | $c->query('OcrStatusMapper'), |
| 97 | - new View('/'.$c->query('CurrentUID').'/files'), |
|
| 97 | + new View('/' . $c->query('CurrentUID') . '/files'), |
|
| 98 | 98 | $c->query('CurrentUID'), |
| 99 | 99 | $server->getLogger() |
| 100 | 100 | ); |
@@ -30,10 +30,10 @@ |
||
| 30 | 30 | * @param Closure $callback |
| 31 | 31 | * @return DataResponse |
| 32 | 32 | */ |
| 33 | - protected function handleNotFound (Closure $callback) { |
|
| 33 | + protected function handleNotFound(Closure $callback) { |
|
| 34 | 34 | try { |
| 35 | 35 | return new DataResponse($callback()); |
| 36 | - } catch(NotFoundException $e) { |
|
| 36 | + } catch (NotFoundException $e) { |
|
| 37 | 37 | return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param OcrService $service |
| 46 | 46 | * @param $UserId |
| 47 | 47 | */ |
| 48 | - public function __construct($AppName, IRequest $request, OcrService $service, $UserId){ |
|
| 48 | + public function __construct($AppName, IRequest $request, OcrService $service, $UserId) { |
|
| 49 | 49 | parent::__construct($AppName, $request); |
| 50 | 50 | $this->userId = $UserId; |
| 51 | 51 | $this->service = $service; |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @NoAdminRequired |
| 57 | 57 | * @return DataResponse |
| 58 | 58 | */ |
| 59 | - public function languages(){ |
|
| 60 | - return $this->handleNotFound(function(){ |
|
| 59 | + public function languages() { |
|
| 60 | + return $this->handleNotFound(function() { |
|
| 61 | 61 | return $this->service->listLanguages(); |
| 62 | 62 | }); |
| 63 | 63 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @return DataResponse |
| 71 | 71 | */ |
| 72 | 72 | public function process($language, $files) { |
| 73 | - return $this->handleNotFound(function () use ($language, $files){ |
|
| 73 | + return $this->handleNotFound(function() use ($language, $files){ |
|
| 74 | 74 | return $this->service->process($language, $files); |
| 75 | 75 | }); |
| 76 | 76 | } |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * @NoAdminRequired |
| 81 | 81 | * @return DataResponse |
| 82 | 82 | */ |
| 83 | - public function status(){ |
|
| 84 | - return $this->handleNotFound(function () { |
|
| 83 | + public function status() { |
|
| 84 | + return $this->handleNotFound(function() { |
|
| 85 | 85 | return $this->service->status(); |
| 86 | 86 | }); |
| 87 | 87 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | $worker->addServer('127.0.0.1',4730); |
| 5 | 5 | |
| 6 | 6 | $worker->addFunction(/** |
| 7 | - * @param GearmanJob $job |
|
| 8 | - */ |
|
| 7 | + * @param GearmanJob $job |
|
| 8 | + */ |
|
| 9 | 9 | "ocr", function(GearmanJob $job) { |
| 10 | 10 | $workload = json_decode($job->workload()); |
| 11 | 11 | if($workload->type == 'tess'){ |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | if ($success == 0 && !isset($_out[1])) { |
| 17 | 17 | //occ command which puts the file and cleans the tempfile |
| 18 | 18 | exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' false'); |
| 19 | - }else{ |
|
| 19 | + } else{ |
|
| 20 | 20 | //update status failed. |
| 21 | 21 | exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' true'); |
| 22 | 22 | } |
| 23 | - }else{ |
|
| 23 | + } else{ |
|
| 24 | 24 | //ocrmypdf |
| 25 | 25 | $command = 'ocrmypdf "' . $workload->datadirectory . $workload->path . '" "' . $workload->tempfile . '" -l ' . $workload->language . ' --skip-text'; |
| 26 | 26 | $success = -1; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | if ($success == 0 && !isset($_out[0])) { |
| 30 | 30 | //occ command which puts the file and cleans the tempfile |
| 31 | 31 | exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' false'); |
| 32 | - }else{ |
|
| 32 | + } else{ |
|
| 33 | 33 | //update status failed. |
| 34 | 34 | exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' true'); |
| 35 | 35 | } |
@@ -1,26 +1,26 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $worker = new GearmanWorker(); |
| 4 | -$worker->addServer('127.0.0.1',4730); |
|
| 4 | +$worker->addServer('127.0.0.1', 4730); |
|
| 5 | 5 | |
| 6 | 6 | $worker->addFunction(/** |
| 7 | 7 | * @param GearmanJob $job |
| 8 | 8 | */ |
| 9 | 9 | "ocr", function(GearmanJob $job) { |
| 10 | 10 | $workload = json_decode($job->workload()); |
| 11 | - if($workload->type === 'tess'){ |
|
| 11 | + if ($workload->type === 'tess') { |
|
| 12 | 12 | //tesseract |
| 13 | 13 | $command = 'tesseract "' . $workload->datadirectory . $workload->path . '" "' . $workload->tempfile . '" -l ' . $workload->language; |
| 14 | 14 | $success = -1; |
| 15 | 15 | exec($command, $_out, $success); |
| 16 | 16 | if ($success === 0 && !isset($_out[1])) { |
| 17 | 17 | //occ command which puts the file and cleans the tempfile |
| 18 | - exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' false'); |
|
| 19 | - }else{ |
|
| 18 | + exec('php ' . $workload->occdir . '/occ ocr:complete ' . $workload->statusid . ' false'); |
|
| 19 | + } else { |
|
| 20 | 20 | //update status failed. |
| 21 | - exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' true'); |
|
| 21 | + exec('php ' . $workload->occdir . '/occ ocr:complete ' . $workload->statusid . ' true'); |
|
| 22 | 22 | } |
| 23 | - }else{ |
|
| 23 | + } else { |
|
| 24 | 24 | //ocrmypdf |
| 25 | 25 | $command = 'ocrmypdf "' . $workload->datadirectory . $workload->path . '" "' . $workload->tempfile . '" -l ' . $workload->language . ' --skip-text'; |
| 26 | 26 | $success = -1; |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | // Command successful and no error by tesseract (line[0] is 'Tesseract Open Source OCR Engine v3.03 with Leptonica' line[1] should not exist) |
| 29 | 29 | if ($success === 0 && !isset($_out[0])) { |
| 30 | 30 | //occ command which puts the file and cleans the tempfile |
| 31 | - exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' false'); |
|
| 32 | - }else{ |
|
| 31 | + exec('php ' . $workload->occdir . '/occ ocr:complete ' . $workload->statusid . ' false'); |
|
| 32 | + } else { |
|
| 33 | 33 | //update status failed. |
| 34 | - exec('php '.$workload->occdir.'/occ ocr:complete '.$workload->statusid.' true'); |
|
| 34 | + exec('php ' . $workload->occdir . '/occ ocr:complete ' . $workload->statusid . ' true'); |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | }); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @package OCA\Ocr\Command |
| 29 | 29 | */ |
| 30 | -class CompleteOCR extends Command { |
|
| 30 | +class CompleteOCR extends Command { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * @var OcrService |
@@ -68,21 +68,21 @@ discard block |
||
| 68 | 68 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 69 | 69 | $statusId = $input->getArgument('status-id'); |
| 70 | 70 | $failed = $input->getArgument('failed'); |
| 71 | - try{ |
|
| 72 | - if($failed === 'false'){ |
|
| 71 | + try { |
|
| 72 | + if ($failed === 'false') { |
|
| 73 | 73 | $failed = false; |
| 74 | - }elseif ($failed === 'true'){ |
|
| 74 | + }elseif ($failed === 'true') { |
|
| 75 | 75 | $failed = true; |
| 76 | - }else{ |
|
| 76 | + } else { |
|
| 77 | 77 | throw new ServiceException('Wrong Arguments.'); |
| 78 | 78 | } |
| 79 | 79 | $this->ocrService->complete($statusId, $failed); |
| 80 | - } catch(Exception $e){ |
|
| 81 | - if($e instanceof MultipleObjectsReturnedException || $e instanceof DoesNotExistException) { |
|
| 80 | + } catch (Exception $e) { |
|
| 81 | + if ($e instanceof MultipleObjectsReturnedException || $e instanceof DoesNotExistException) { |
|
| 82 | 82 | $output->writeln('<error>Could not complete ocr for status id ' . $statusId . |
| 83 | 83 | ': ' . $e->getMessage() . |
| 84 | 84 | '</error> '); |
| 85 | - }else{ |
|
| 85 | + } else { |
|
| 86 | 86 | $output->writeln('<error>Unexpected error for status id ' . $statusId . |
| 87 | 87 | ': ' . $e->getMessage() . |
| 88 | 88 | '</error> '); |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | try{ |
| 72 | 72 | if($failed === 'false'){ |
| 73 | 73 | $failed = false; |
| 74 | - }elseif ($failed === 'true'){ |
|
| 74 | + } elseif ($failed === 'true'){ |
|
| 75 | 75 | $failed = true; |
| 76 | - }else{ |
|
| 76 | + } else{ |
|
| 77 | 77 | throw new ServiceException('Wrong Arguments.'); |
| 78 | 78 | } |
| 79 | 79 | $this->ocrService->complete($statusId, $failed); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $output->writeln('<error>Could not complete ocr for status id ' . $statusId . |
| 83 | 83 | ': ' . $e->getMessage() . |
| 84 | 84 | '</error> '); |
| 85 | - }else{ |
|
| 85 | + } else{ |
|
| 86 | 86 | $output->writeln('<error>Unexpected error for status id ' . $statusId . |
| 87 | 87 | ': ' . $e->getMessage() . |
| 88 | 88 | '</error> '); |