| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Nextcloud - OCR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * later. See the COPYING file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author Janis Koehr <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright Janis Koehr 2017 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace OCA\Ocr\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use OCP\IL10N; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use OCP\ILogger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use OCA\Ocr\Db\OcrJobMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Class StatusService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @package OCA\Ocr\Service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class StatusService { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * @var ILogger | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	private $logger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 * @var String | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	private $userId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * @var IL10N | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	private $l10n; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * @var OcrJobMapper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	private $jobMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	 * @var JobService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	private $jobService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 * StatusService constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	 * @param IL10N $l10n        	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	 * @param ILogger $logger        	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	 * @param unknown $userId        	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	 * @param OcrJobMapper $mapper        	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * @param JobService $jobService        	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	public function __construct(IL10N $l10n, ILogger $logger, $userId, OcrJobMapper $mapper, JobService $jobService) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->logger = $logger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->jobMapper = $mapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->userId = $userId; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$this->l10n = $l10n; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->jobService = $jobService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 * A function which returns the JSONResponse for all required status checks and tasks. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	 * It will check for already processed, pending and failed ocr tasks and return them as needed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	public function getStatus() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			// TODO: For now this will be placed in the regular check, but in the future this could be done in another way | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			$this->jobService->checkForFinishedJobs (); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			// returns user specific processed files | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			$processed = $this->jobMapper->findAllProcessed ( $this->userId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			$this->jobService->handleProcessed (); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			// return user specific pending state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			$pending = $this->jobMapper->findAllPending ( $this->userId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			// return user specific failed state and set up error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			$failed = $this->jobMapper->findAllFailed ( $this->userId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			$this->jobService->handleFailed (); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			return [  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 					'processed' => count ( $processed ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 					'failed' => count ( $failed ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 					'pending' => count ( $pending )  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		} catch ( Exception $e ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			$this->handleException ( $e ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * Handle the possible thrown Exceptions from all methods of this class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 * @param Exception $e        	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	 * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 * @throws NotFoundException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | 	 */ | 
            
                                                        
            
                                    
            
            
                | 114 |  |  | 	private function handleException($e) { | 
            
                                                        
            
                                    
            
            
                | 115 |  |  | 		$this->logger->logException ( $e, [  | 
            
                                                        
            
                                    
            
            
                | 116 |  |  | 				'message' => 'Exception during status service function processing'  | 
            
                                                        
            
                                    
            
            
                | 117 |  |  | 		] ); | 
            
                                                        
            
                                    
            
            
                | 118 |  |  | 		throw $e; | 
            
                                                        
            
                                    
            
            
                | 119 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 120 |  |  | } | 
            
                        
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..