@@ -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 |
@@ -106,38 +106,38 @@ 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 | - if (! empty ( $files ) && $this->checkForAcceptedLanguages ( $languages )) { |
|
114 | - $fileInfo = $this->fileService->buildFileInfo ( $files ); |
|
115 | - foreach ( $fileInfo as $fInfo ) { |
|
113 | + if (!empty ($files) && $this->checkForAcceptedLanguages($languages)) { |
|
114 | + $fileInfo = $this->fileService->buildFileInfo($files); |
|
115 | + foreach ($fileInfo as $fInfo) { |
|
116 | 116 | // Check Shared |
117 | - $shared = $this->fileService->checkSharedWithInitiator ( $fInfo ); |
|
118 | - $target = $this->fileService->buildTarget ( $fInfo, $shared ); |
|
119 | - $source = $this->fileService->buildSource ( $fInfo, $shared ); |
|
117 | + $shared = $this->fileService->checkSharedWithInitiator($fInfo); |
|
118 | + $target = $this->fileService->buildTarget($fInfo, $shared); |
|
119 | + $source = $this->fileService->buildSource($fInfo, $shared); |
|
120 | 120 | |
121 | 121 | // create a temp file for ocr processing purposes |
122 | - $tempFile = $this->tempM->getTemporaryFile (); |
|
122 | + $tempFile = $this->tempM->getTemporaryFile(); |
|
123 | 123 | |
124 | 124 | // set the running type |
125 | - $fType = $this->fileService->getCorrectType (); |
|
125 | + $fType = $this->fileService->getCorrectType(); |
|
126 | 126 | |
127 | 127 | // TODO: create a security token |
128 | 128 | // Create job object |
129 | - $job = new OcrJob ( 'PENDING', $source, $target, $tempFile, $fType, $this->userId, false ); |
|
129 | + $job = new OcrJob('PENDING', $source, $target, $tempFile, $fType, $this->userId, false); |
|
130 | 130 | |
131 | 131 | // Init client and send task / job |
132 | 132 | // Feed the worker |
133 | - $this->queueService->sendJob ( $job, $languages, \OC::$SERVERROOT ); |
|
133 | + $this->queueService->sendJob($job, $languages, \OC::$SERVERROOT); |
|
134 | 134 | } |
135 | 135 | return 'PROCESSING'; |
136 | 136 | } else { |
137 | - throw new NotFoundException ( $this->l10n->t ( 'Empty parameters passed.' ) ); |
|
137 | + throw new NotFoundException($this->l10n->t('Empty parameters passed.')); |
|
138 | 138 | } |
139 | - } catch ( Exception $e ) { |
|
140 | - $this->handleException ( $e ); |
|
139 | + } catch (Exception $e) { |
|
140 | + $this->handleException($e); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
@@ -151,20 +151,20 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function deleteJob($jobId, $userId) { |
153 | 153 | try { |
154 | - $job = $this->jobMapper->find ( $jobId ); |
|
155 | - if ($job->getUserId () !== $userId) { |
|
156 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong owner.' ) ); |
|
154 | + $job = $this->jobMapper->find($jobId); |
|
155 | + if ($job->getUserId() !== $userId) { |
|
156 | + throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.')); |
|
157 | 157 | } else { |
158 | - $job = $this->jobMapper->delete ( $job ); |
|
158 | + $job = $this->jobMapper->delete($job); |
|
159 | 159 | } |
160 | 160 | // TODO: return sanitized job for the personal settings page (no information about the source and target and such things. |
161 | 161 | return $job; |
162 | - } catch ( Exception $e ) { |
|
162 | + } catch (Exception $e) { |
|
163 | 163 | if ($e instanceof DoesNotExistException) { |
164 | - $ex = new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong ID.' ) ); |
|
165 | - $this->handleException ( $ex ); |
|
164 | + $ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.')); |
|
165 | + $this->handleException($ex); |
|
166 | 166 | } else { |
167 | - $this->handleException ( $e ); |
|
167 | + $this->handleException($e); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -177,20 +177,20 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function getAllJobsForUser($userId) { |
179 | 179 | try { |
180 | - $jobs = $this->jobMapper->findAll ( $userId ); |
|
181 | - $jobsNew = array (); |
|
182 | - for($x = 0; $x < count ( $jobs ); $x ++) { |
|
183 | - $newName = $this->removeFileExtension ( $jobs [$x] ); |
|
184 | - $jobs [$x]->setTarget ( $newName ); |
|
185 | - $jobs [$x]->setSource ( null ); |
|
186 | - $jobs [$x]->setTempFile ( null ); |
|
187 | - $jobs [$x]->setType ( null ); |
|
188 | - $jobs [$x]->setErrorDisplayed ( null ); |
|
189 | - array_push ( $jobsNew, $jobs [$x] ); |
|
180 | + $jobs = $this->jobMapper->findAll($userId); |
|
181 | + $jobsNew = array(); |
|
182 | + for ($x = 0; $x < count($jobs); $x++) { |
|
183 | + $newName = $this->removeFileExtension($jobs [$x]); |
|
184 | + $jobs [$x]->setTarget($newName); |
|
185 | + $jobs [$x]->setSource(null); |
|
186 | + $jobs [$x]->setTempFile(null); |
|
187 | + $jobs [$x]->setType(null); |
|
188 | + $jobs [$x]->setErrorDisplayed(null); |
|
189 | + array_push($jobsNew, $jobs [$x]); |
|
190 | 190 | } |
191 | 191 | return $jobsNew; |
192 | - } catch ( Exception $e ) { |
|
193 | - $this->handleException ( $e ); |
|
192 | + } catch (Exception $e) { |
|
193 | + $this->handleException($e); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function jobFinished($jobId, $failed, $errorMessage) { |
207 | 207 | try { |
208 | - $job = $this->jobMapper->find ( $jobId ); |
|
209 | - if (! $failed) { |
|
210 | - $job->setStatus ( 'PROCESSED' ); |
|
211 | - $this->jobMapper->update ( $job ); |
|
208 | + $job = $this->jobMapper->find($jobId); |
|
209 | + if (!$failed) { |
|
210 | + $job->setStatus('PROCESSED'); |
|
211 | + $this->jobMapper->update($job); |
|
212 | 212 | } else { |
213 | - $job->setStatus ( 'FAILED' ); |
|
213 | + $job->setStatus('FAILED'); |
|
214 | 214 | // TODO: add error message log and so on |
215 | - $this->jobMapper->update ( $job ); |
|
216 | - $this->logger->error ( $errorMessage, [ |
|
215 | + $this->jobMapper->update($job); |
|
216 | + $this->logger->error($errorMessage, [ |
|
217 | 217 | 'app' => 'ocr' |
218 | - ] ); |
|
218 | + ]); |
|
219 | 219 | } |
220 | - } catch ( Exception $e ) { |
|
221 | - $this->handleException ( $e ); |
|
220 | + } catch (Exception $e) { |
|
221 | + $this->handleException($e); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
@@ -231,31 +231,31 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function handleProcessed() { |
233 | 233 | try { |
234 | - $this->logger->debug ( 'Check if files were processed by ocr and if so, put them to the right dirs.', [ |
|
234 | + $this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.', [ |
|
235 | 235 | 'app' => 'ocr' |
236 | - ] ); |
|
237 | - $processed = $this->jobMapper->findAllProcessed ( $this->userId ); |
|
238 | - foreach ( $processed as $job ) { |
|
239 | - if ($job->getType () === 'tess' && $this->fileService->fileExists ( $job->getTempFile () . '.txt' )) { |
|
236 | + ]); |
|
237 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
238 | + foreach ($processed as $job) { |
|
239 | + if ($job->getType() === 'tess' && $this->fileService->fileExists($job->getTempFile() . '.txt')) { |
|
240 | 240 | // Save the tmp file with newname |
241 | - $this->view->file_put_contents ( $job->getTarget (), $this->fileService->getFileContents ( $job->getTempFile () . '.txt' ) ); // need .txt because tesseract saves it like this |
|
241 | + $this->view->file_put_contents($job->getTarget(), $this->fileService->getFileContents($job->getTempFile() . '.txt')); // need .txt because tesseract saves it like this |
|
242 | 242 | // Cleaning temp files |
243 | - $this->jobMapper->delete ( $job ); |
|
244 | - $this->fileService->execRemove ( $job->getTempFile () . '.txt' ); |
|
245 | - } elseif ($job->getType () === 'mypdf' && $this->fileService->fileExists ( $job->getTempFile () )) { |
|
243 | + $this->jobMapper->delete($job); |
|
244 | + $this->fileService->execRemove($job->getTempFile() . '.txt'); |
|
245 | + } elseif ($job->getType() === 'mypdf' && $this->fileService->fileExists($job->getTempFile())) { |
|
246 | 246 | // Save the tmp file with newname |
247 | - $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 |
|
248 | - $this->jobMapper->delete ( $job ); |
|
249 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
247 | + $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 |
|
248 | + $this->jobMapper->delete($job); |
|
249 | + $this->fileService->execRemove($job->getTempFile()); |
|
250 | 250 | } else { |
251 | - $job->setStatus ( 'FAILED' ); |
|
252 | - $this->jobMapper->update ( $job ); |
|
253 | - throw new NotFoundException ( $this->l10n->t ( 'Temp file does not exist.' ) ); |
|
251 | + $job->setStatus('FAILED'); |
|
252 | + $this->jobMapper->update($job); |
|
253 | + throw new NotFoundException($this->l10n->t('Temp file does not exist.')); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | return $processed; |
257 | - } catch ( Exception $e ) { |
|
258 | - $this->handleException ( $e ); |
|
257 | + } catch (Exception $e) { |
|
258 | + $this->handleException($e); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
@@ -266,20 +266,20 @@ discard block |
||
266 | 266 | */ |
267 | 267 | public function handleFailed() { |
268 | 268 | try { |
269 | - $failed = $this->jobMapper->findAllFailed ( $this->userId ); |
|
270 | - foreach ( $failed as $job ) { |
|
269 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
270 | + foreach ($failed as $job) { |
|
271 | 271 | // clean the tempfile |
272 | - $this->fileService->execRemove ( $job->getTempFile () ); |
|
272 | + $this->fileService->execRemove($job->getTempFile()); |
|
273 | 273 | // set error displayed |
274 | - $job->setErrorDisplayed ( true ); |
|
275 | - $this->jobMapper->update ( $job ); |
|
274 | + $job->setErrorDisplayed(true); |
|
275 | + $this->jobMapper->update($job); |
|
276 | 276 | } |
277 | - $this->logger->debug ( 'Following jobs failed: ' . json_encode ( $failed ), [ |
|
277 | + $this->logger->debug('Following jobs failed: ' . json_encode($failed), [ |
|
278 | 278 | 'app' => 'ocr' |
279 | - ] ); |
|
279 | + ]); |
|
280 | 280 | return $failed; |
281 | - } catch ( Exception $e ) { |
|
282 | - $this->handleException ( $e ); |
|
281 | + } catch (Exception $e) { |
|
282 | + $this->handleException($e); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | * @return boolean |
292 | 292 | */ |
293 | 293 | private function checkForAcceptedLanguages($languages) { |
294 | - if (empty ( $languages )) { |
|
294 | + if (empty ($languages)) { |
|
295 | 295 | return true; |
296 | - } elseif (count ( array_diff ( $languages, [ |
|
296 | + } elseif (count(array_diff($languages, [ |
|
297 | 297 | 'deu', |
298 | 298 | 'eng' |
299 | - ] ) ) === 0) { |
|
299 | + ])) === 0) { |
|
300 | 300 | return true; |
301 | 301 | } else { |
302 | 302 | return false; |
@@ -311,12 +311,12 @@ discard block |
||
311 | 311 | * @throws NotFoundException |
312 | 312 | */ |
313 | 313 | private function handleException($e) { |
314 | - $this->logger->logException ( $e, [ |
|
314 | + $this->logger->logException($e, [ |
|
315 | 315 | 'app' => 'ocr', |
316 | 316 | 'message' => 'Exception during job service function processing' |
317 | - ] ); |
|
317 | + ]); |
|
318 | 318 | if ($e instanceof NotFoundException) { |
319 | - throw new NotFoundException ( $e->getMessage () ); |
|
319 | + throw new NotFoundException($e->getMessage()); |
|
320 | 320 | } else { |
321 | 321 | throw $e; |
322 | 322 | } |
@@ -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 | } |