Completed
Pull Request — master (#6)
by Janis
340:04 queued 336:33
created
appinfo/routes.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
18 18
  * it's instantiated in there
19 19
  */
20 20
 return [
21
-    'routes' => [
21
+	'routes' => [
22 22
 		['name' => 'ocr#process', 'url' => '/process', 'verb' => 'GET'],
23 23
 		['name' => 'ocr#languages', 'url' => '/languages', 'verb' => 'GET'],
24
-    ]
24
+	]
25 25
 ];
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Command/CompleteOCR.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,6 @@
 block discarded – undo
12 12
 namespace OCA\Ocr\Command;
13 13
 
14 14
 use Exception;
15
-use OCA\Ocr\Service\NotFoundException;
16 15
 use OCA\Ocr\Service\OcrService;
17 16
 use OCA\Ocr\Service\ServiceException;
18 17
 use OCP\AppFramework\Db\DoesNotExistException;
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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> ');
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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> ');
Please login to merge, or discard this patch.
lib/Service/GearmanWorkerService.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
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 {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
lib/Service/OcrService.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 {
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @return array Languages
100 100
 	 */
101
-	public function listLanguages(){
101
+	public function listLanguages() {
102 102
 		try {
103 103
 			$success = -1;
104 104
 			$this->logger->debug('Fetching languages. ', ['app' => 'ocr']);
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 						array_push($languages, $tdname);
117 117
 					}
118 118
 				}
119
-				$this->logger->debug('Fetched languages: '.json_encode($languages), ['app' => 'ocr']);
119
+				$this->logger->debug('Fetched languages: ' . json_encode($languages), ['app' => 'ocr']);
120 120
 				return $languages;
121 121
 			} else {
122 122
 				throw new NotFoundException('No languages found.');
123 123
 			}
124
-		}catch(Exception $e){
124
+		} catch (Exception $e) {
125 125
 			$this->handleException($e);
126 126
 		}
127 127
 	}
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function process($language, $files) {
138 138
 		try {
139
-			$this->logger->debug('Will now process files: '.json_encode($files) . ' with language: ' . json_encode($language), ['app' => 'ocr']);
139
+			$this->logger->debug('Will now process files: ' . json_encode($files) . ' with language: ' . json_encode($language), ['app' => 'ocr']);
140 140
 			// Check if $files and $language not empty
141
-			if(!empty($files) && !empty($language) && in_array($language, $this->listLanguages())){
141
+			if (!empty($files) && !empty($language) && in_array($language, $this->listLanguages())) {
142 142
 				// get the array with full fileinfo
143 143
 				$fileInfo = $this->buildFileInfo($files);
144
-				foreach ($fileInfo as $fInfo){
144
+				foreach ($fileInfo as $fInfo) {
145 145
 					// Check if filelock existing
146 146
 					// TODO: FileLock maybe \OC\Files\View::lockFile()
147 147
 					// get new name for saving purpose
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
 					$tempFile = $this->tempM->getTemporaryFile();
152 152
 
153 153
 					// set the gearman running type
154
-					if($fInfo->getMimetype() == $this::MIMETYPE_PDF){
154
+					if ($fInfo->getMimetype() == $this::MIMETYPE_PDF) {
155 155
 						$ftype = 'mypdf';
156
-					}else{
156
+					} else {
157 157
 						$ftype = 'tess';
158 158
 					}
159 159
 
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 					$this->sendGearmanJob($ftype, $this->config->getSystemValue('datadirectory'), $fInfo->getPath(), $tempFile, $language, $status, \OC::$SERVERROOT);
166 166
 				}
167 167
 				return 'PROCESSING';
168
-			}else{
168
+			} else {
169 169
 				throw new NotFoundException('Empty parameters.');
170 170
 			}
171
-		}catch(Exception $e){
171
+		} catch (Exception $e) {
172 172
 			$this->handleException($e);
173 173
 		}
174 174
 	}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return string
181 181
 	 */
182
-	public function status(){
182
+	public function status() {
183 183
 		try {
184 184
 			// TODO: release lock
185 185
 			$processed = $this->handleProcessed();
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			$pending = count($this->statusMapper->findAllPending($this->userId));
190 190
 
191 191
 			return ['processed' => $processed, 'failed' => $failed, 'pending' => $pending];
192
-		}catch (Exception $e){
192
+		} catch (Exception $e) {
193 193
 			$this->handleException($e);
194 194
 		}
195 195
 	}
@@ -201,18 +201,18 @@  discard block
 block discarded – undo
201 201
 	 * @param $statusId
202 202
 	 * @param $failed
203 203
 	 */
204
-	public function complete($statusId, $failed){
205
-		try{
204
+	public function complete($statusId, $failed) {
205
+		try {
206 206
 			$status = $this->statusMapper->find($statusId);
207
-			if(!$failed) {
207
+			if (!$failed) {
208 208
 				$status->setStatus('PROCESSED');
209 209
 				$this->statusMapper->update($status);
210
-			}else{
210
+			} else {
211 211
 				$status->setStatus('FAILED');
212 212
 				$this->statusMapper->update($status);
213 213
 			}
214
-		} catch (Exception $e){
215
-			if ($e instanceof NotFoundException){
214
+		} catch (Exception $e) {
215
+			if ($e instanceof NotFoundException) {
216 216
 				$status->setStatus('FAILED');
217 217
 				$this->statusMapper->update($status);
218 218
 				$this->handleException($e);
@@ -227,28 +227,28 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @return int
229 229
 	 */
230
-	private function handleProcessed(){
230
+	private function handleProcessed() {
231 231
 		try {
232 232
 			$this->logger->debug('Find processed ocr files and put them to the right dirs.', ['app' => 'ocr']);
233 233
 			$processed = $this->statusMapper->findAllProcessed($this->userId);
234 234
 			foreach ($processed as $status) {
235
-				if ($status->getType() == 'tess' && file_exists($status->getTempFile().'.txt')) {
235
+				if ($status->getType() == 'tess' && file_exists($status->getTempFile() . '.txt')) {
236 236
 					//Save the tmp file with newname
237
-					$this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile() . '.txt'));// need .txt because tesseract saves it like this
237
+					$this->view->file_put_contents($status->getNewName(), file_get_contents($status->getTempFile() . '.txt')); // need .txt because tesseract saves it like this
238 238
 					// Cleaning temp files
239 239
 					$this->statusMapper->delete($status);
240 240
 					exec('rm ' . $status->getTempFile() . '.txt');
241 241
 				} elseif ($status->getType() == 'mypdf' && file_exists($status->getTempFile())) {
242 242
 					//Save the tmp file with newname
243
-					$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
+					$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
244 244
 					$this->statusMapper->delete($status);
245 245
 					exec('rm ' . $status->getTempFile());
246
-				}else{
246
+				} else {
247 247
 					throw new NotFoundException('Temp file does not exist.');
248 248
 				}
249 249
 			}
250 250
 			return count($processed);
251
-		}catch (Exception $e){
251
+		} catch (Exception $e) {
252 252
 			$this->handleException($e);
253 253
 		}
254 254
 	}
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	 *
259 259
 	 * @return array
260 260
 	 */
261
-	private function handleFailed(){
261
+	private function handleFailed() {
262 262
 		try {
263 263
 			$failed = $this->statusMapper->findAllFailed($this->userId);
264 264
 			foreach ($failed as $status) {
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 				// clean from db
268 268
 				$this->statusMapper->delete($status);
269 269
 			}
270
-			$this->logger->debug('Following status objects failed: '.json_encode($failed), ['app' => 'ocr']);
270
+			$this->logger->debug('Following status objects failed: ' . json_encode($failed), ['app' => 'ocr']);
271 271
 			return $failed;
272
-		}catch (Exception $e){
272
+		} catch (Exception $e) {
273 273
 			$this->handleException($e);
274 274
 		}
275 275
 	}
@@ -281,19 +281,19 @@  discard block
 block discarded – undo
281 281
 	 * @param Files\FileInfo $fileInfo
282 282
 	 * @return string
283 283
 	 */
284
-	private function buildNewName(Files\FileInfo $fileInfo){
284
+	private function buildNewName(Files\FileInfo $fileInfo) {
285 285
 		// get rid of the .png or .pdf and so on
286
-		$fileName = substr($fileInfo->getName(),0,-4);
286
+		$fileName = substr($fileInfo->getName(), 0, -4);
287 287
 		// eliminate the file name from the path
288
-		$filePath = str_replace($fileInfo->getName(),'',$fileInfo->getPath());
288
+		$filePath = str_replace($fileInfo->getName(), '', $fileInfo->getPath());
289 289
 		// and get the path on top of the user/files/ dir
290
-		$filePath = str_replace('/'.$this->userId.'/files','',$filePath);
291
-		if($fileInfo->getMimetype() == $this::MIMETYPE_PDF){
290
+		$filePath = str_replace('/' . $this->userId . '/files', '', $filePath);
291
+		if ($fileInfo->getMimetype() == $this::MIMETYPE_PDF) {
292 292
 			// PDFs:
293
-			return Files::buildNotExistingFileName($filePath, $fileName.'_OCR.pdf');
293
+			return Files::buildNotExistingFileName($filePath, $fileName . '_OCR.pdf');
294 294
 		} else {
295 295
 			// IMAGES:
296
-			return Files::buildNotExistingFileName($filePath, $fileName.'_OCR.txt');
296
+			return Files::buildNotExistingFileName($filePath, $fileName . '_OCR.txt');
297 297
 		}
298 298
 	}
299 299
 
@@ -305,16 +305,16 @@  discard block
 block discarded – undo
305 305
 	 * @return array of Files\FileInfo
306 306
 	 * @throws NotFoundException
307 307
 	 */
308
-	private function buildFileInfo(array $files){
308
+	private function buildFileInfo(array $files) {
309 309
 		try {
310 310
 			$fileArray = array();
311 311
 			foreach ($files as $file) {
312 312
 				if ((!empty($file['path']) || !empty($file['directory'])) && $file['type'] == 'file') {
313
-					if(empty($file['path'])){ $file['path'] = $file['directory']; } //Because new updated files have the property directory instead of path
314
-					if($file['path'] == '/'){
315
-						$path = ''. '/' . $file['name'];
316
-					}else{
317
-						$path = $file['path']. '/' . $file['name'];
313
+					if (empty($file['path'])) { $file['path'] = $file['directory']; } //Because new updated files have the property directory instead of path
314
+					if ($file['path'] == '/') {
315
+						$path = '' . '/' . $file['name'];
316
+					} else {
317
+						$path = $file['path'] . '/' . $file['name'];
318 318
 					}
319 319
 					$fileInfo = $this->view->getFileInfo($path);
320 320
 					if (!$fileInfo || !in_array($fileInfo->getMimetype(), $this::ALLOWED_MIMETYPES)) {
@@ -341,15 +341,15 @@  discard block
 block discarded – undo
341 341
 	 * @param $language
342 342
 	 * @param $statusId
343 343
 	 */
344
-	private function sendGearmanJob($type, $datadirectory, $path, $tempFile, $language, $status, $occDir){
344
+	private function sendGearmanJob($type, $datadirectory, $path, $tempFile, $language, $status, $occDir) {
345 345
 		try {
346
-			if(!$this->workerService->workerExists()){
346
+			if (!$this->workerService->workerExists()) {
347 347
 				throw new NotFoundException('No gearman worker exists.');
348 348
 			}
349 349
 			$this->statusMapper->insert($status);
350 350
 			// Gearman thing
351 351
 			$client = new \GearmanClient();
352
-			$client->addServer('127.0.0.1',4730);
352
+			$client->addServer('127.0.0.1', 4730);
353 353
 			$result = $client->doBackground("ocr", json_encode(array(
354 354
 				'type' => $type,
355 355
 				'datadirectory' => $datadirectory,
Please login to merge, or discard this patch.
Braces   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			} else {
122 122
 				throw new NotFoundException('No languages found.');
123 123
 			}
124
-		}catch(Exception $e){
124
+		} catch(Exception $e){
125 125
 			$this->handleException($e);
126 126
 		}
127 127
 	}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 					// set the gearman running type
154 154
 					if($fInfo->getMimetype() == $this::MIMETYPE_PDF){
155 155
 						$ftype = 'mypdf';
156
-					}else{
156
+					} else{
157 157
 						$ftype = 'tess';
158 158
 					}
159 159
 
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 					$this->sendGearmanJob($ftype, $this->config->getSystemValue('datadirectory'), $fInfo->getPath(), $tempFile, $language, $status, \OC::$SERVERROOT);
166 166
 				}
167 167
 				return 'PROCESSING';
168
-			}else{
168
+			} else{
169 169
 				throw new NotFoundException('Empty parameters.');
170 170
 			}
171
-		}catch(Exception $e){
171
+		} catch(Exception $e){
172 172
 			$this->handleException($e);
173 173
 		}
174 174
 	}
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			$pending = count($this->statusMapper->findAllPending($this->userId));
190 190
 
191 191
 			return ['processed' => $processed, 'failed' => $failed, 'pending' => $pending];
192
-		}catch (Exception $e){
192
+		} catch (Exception $e){
193 193
 			$this->handleException($e);
194 194
 		}
195 195
 	}
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			if(!$failed) {
208 208
 				$status->setStatus('PROCESSED');
209 209
 				$this->statusMapper->update($status);
210
-			}else{
210
+			} else{
211 211
 				$status->setStatus('FAILED');
212 212
 				$this->statusMapper->update($status);
213 213
 			}
@@ -243,12 +243,12 @@  discard block
 block discarded – undo
243 243
 					$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
244 244
 					$this->statusMapper->delete($status);
245 245
 					exec('rm ' . $status->getTempFile());
246
-				}else{
246
+				} else{
247 247
 					throw new NotFoundException('Temp file does not exist.');
248 248
 				}
249 249
 			}
250 250
 			return count($processed);
251
-		}catch (Exception $e){
251
+		} catch (Exception $e){
252 252
 			$this->handleException($e);
253 253
 		}
254 254
 	}
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 			}
270 270
 			$this->logger->debug('Following status objects failed: '.json_encode($failed), ['app' => 'ocr']);
271 271
 			return $failed;
272
-		}catch (Exception $e){
272
+		} catch (Exception $e){
273 273
 			$this->handleException($e);
274 274
 		}
275 275
 	}
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 					if(empty($file['path'])){ $file['path'] = $file['directory']; } //Because new updated files have the property directory instead of path
314 314
 					if($file['path'] == '/'){
315 315
 						$path = ''. '/' . $file['name'];
316
-					}else{
316
+					} else{
317 317
 						$path = $file['path']. '/' . $file['name'];
318 318
 					}
319 319
 					$fileInfo = $this->view->getFileInfo($path);
Please login to merge, or discard this patch.
lib/Db/OcrStatusMapper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
lib/AppInfo/Application.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 			);
Please login to merge, or discard this patch.
lib/Controller/Errors.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
lib/Controller/OcrController.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
worker/GearmanOCRWorker.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
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'){
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 });
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,11 +16,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.