@@ -17,7 +17,6 @@ |
||
| 17 | 17 | use OCP\IL10N; |
| 18 | 18 | use OCP\ITempManager; |
| 19 | 19 | use OCA\Ocr\Db\OcrJob; |
| 20 | -use OCA\Ocr\Db\File; |
|
| 21 | 20 | use OCA\Ocr\Constants\OcrConstants; |
| 22 | 21 | use OCA\Ocr\Util\PHPUtil; |
| 23 | 22 | |
@@ -29,380 +29,380 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class JobService { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * |
|
| 34 | - * @var ILogger |
|
| 35 | - */ |
|
| 36 | - private $logger; |
|
| 32 | + /** |
|
| 33 | + * |
|
| 34 | + * @var ILogger |
|
| 35 | + */ |
|
| 36 | + private $logger; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * |
|
| 40 | - * @var RedisService |
|
| 41 | - */ |
|
| 42 | - private $redisService; |
|
| 38 | + /** |
|
| 39 | + * |
|
| 40 | + * @var RedisService |
|
| 41 | + */ |
|
| 42 | + private $redisService; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * @var OcrJobMapper |
|
| 47 | - */ |
|
| 48 | - private $jobMapper; |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * @var OcrJobMapper |
|
| 47 | + */ |
|
| 48 | + private $jobMapper; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * |
|
| 52 | - * @var View |
|
| 53 | - */ |
|
| 54 | - private $view; |
|
| 50 | + /** |
|
| 51 | + * |
|
| 52 | + * @var View |
|
| 53 | + */ |
|
| 54 | + private $view; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * |
|
| 58 | - * @var String |
|
| 59 | - */ |
|
| 60 | - private $userId; |
|
| 56 | + /** |
|
| 57 | + * |
|
| 58 | + * @var String |
|
| 59 | + */ |
|
| 60 | + private $userId; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * |
|
| 64 | - * @var IL10N |
|
| 65 | - */ |
|
| 66 | - private $l10n; |
|
| 62 | + /** |
|
| 63 | + * |
|
| 64 | + * @var IL10N |
|
| 65 | + */ |
|
| 66 | + private $l10n; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * |
|
| 70 | - * @var FileService |
|
| 71 | - */ |
|
| 72 | - private $fileService; |
|
| 68 | + /** |
|
| 69 | + * |
|
| 70 | + * @var FileService |
|
| 71 | + */ |
|
| 72 | + private $fileService; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * |
|
| 76 | - * @var ITempManager |
|
| 77 | - */ |
|
| 78 | - private $tempM; |
|
| 74 | + /** |
|
| 75 | + * |
|
| 76 | + * @var ITempManager |
|
| 77 | + */ |
|
| 78 | + private $tempM; |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * |
|
| 82 | - * @var AppConfigService |
|
| 83 | - */ |
|
| 84 | - private $appConfigService; |
|
| 80 | + /** |
|
| 81 | + * |
|
| 82 | + * @var AppConfigService |
|
| 83 | + */ |
|
| 84 | + private $appConfigService; |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * |
|
| 88 | - * @var PHPUtil |
|
| 89 | - */ |
|
| 90 | - private $phpUtil; |
|
| 86 | + /** |
|
| 87 | + * |
|
| 88 | + * @var PHPUtil |
|
| 89 | + */ |
|
| 90 | + private $phpUtil; |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * JobService constructor. |
|
| 94 | - * |
|
| 95 | - * @param IL10N $l10n |
|
| 96 | - * @param ILogger $logger |
|
| 97 | - * @param string $userId |
|
| 98 | - * @param View $view |
|
| 99 | - * @param RedisService $queueService |
|
| 100 | - * @param OcrJobMapper $mapper |
|
| 101 | - * @param FileService $fileService |
|
| 102 | - * @param AppConfigService $appConfigService |
|
| 103 | - * @param PHPUtil $phpUtil |
|
| 104 | - */ |
|
| 105 | - public function __construct(IL10N $l10n, ILogger $logger, $userId, View $view, ITempManager $tempManager, |
|
| 106 | - RedisService $queueService, OcrJobMapper $mapper, FileService $fileService, |
|
| 107 | - AppConfigService $appConfigService, PHPUtil $phpUtil) { |
|
| 108 | - $this->logger = $logger; |
|
| 109 | - $this->redisService = $queueService; |
|
| 110 | - $this->jobMapper = $mapper; |
|
| 111 | - $this->view = $view; |
|
| 112 | - $this->userId = $userId; |
|
| 113 | - $this->l10n = $l10n; |
|
| 114 | - $this->fileService = $fileService; |
|
| 115 | - $this->tempM = $tempManager; |
|
| 116 | - $this->appConfigService = $appConfigService; |
|
| 117 | - $this->phpUtil = $phpUtil; |
|
| 118 | - } |
|
| 92 | + /** |
|
| 93 | + * JobService constructor. |
|
| 94 | + * |
|
| 95 | + * @param IL10N $l10n |
|
| 96 | + * @param ILogger $logger |
|
| 97 | + * @param string $userId |
|
| 98 | + * @param View $view |
|
| 99 | + * @param RedisService $queueService |
|
| 100 | + * @param OcrJobMapper $mapper |
|
| 101 | + * @param FileService $fileService |
|
| 102 | + * @param AppConfigService $appConfigService |
|
| 103 | + * @param PHPUtil $phpUtil |
|
| 104 | + */ |
|
| 105 | + public function __construct(IL10N $l10n, ILogger $logger, $userId, View $view, ITempManager $tempManager, |
|
| 106 | + RedisService $queueService, OcrJobMapper $mapper, FileService $fileService, |
|
| 107 | + AppConfigService $appConfigService, PHPUtil $phpUtil) { |
|
| 108 | + $this->logger = $logger; |
|
| 109 | + $this->redisService = $queueService; |
|
| 110 | + $this->jobMapper = $mapper; |
|
| 111 | + $this->view = $view; |
|
| 112 | + $this->userId = $userId; |
|
| 113 | + $this->l10n = $l10n; |
|
| 114 | + $this->fileService = $fileService; |
|
| 115 | + $this->tempM = $tempManager; |
|
| 116 | + $this->appConfigService = $appConfigService; |
|
| 117 | + $this->phpUtil = $phpUtil; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Processes and prepares the files for OCR. |
|
| 122 | - * Sends the stuff to the client in order to OCR async. |
|
| 123 | - * |
|
| 124 | - * @param string[] $languages |
|
| 125 | - * @param array $files |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function process($languages, $files) { |
|
| 129 | - try { |
|
| 130 | - $this->logger->debug('Will now process files: {files} with languages: {languages}', |
|
| 131 | - [ |
|
| 132 | - 'files' => json_encode($files), |
|
| 133 | - 'languages' => json_encode($languages) |
|
| 134 | - ]); |
|
| 135 | - // Check if files and language not empty |
|
| 136 | - $noLang = $this->noLanguage($languages); |
|
| 137 | - if (!empty($files) && ($this->checkForAcceptedLanguages($languages) || $noLang)) { |
|
| 138 | - // language part: |
|
| 139 | - if ($noLang) { |
|
| 140 | - $languages = []; |
|
| 141 | - } |
|
| 142 | - // file part: |
|
| 143 | - $fileInfo = $this->fileService->buildFileInfo($files); |
|
| 144 | - foreach ($fileInfo as $fInfo) { |
|
| 145 | - // Check Shared |
|
| 146 | - $shared = $this->fileService->checkSharedWithInitiator($fInfo); |
|
| 147 | - $target = $this->fileService->buildTarget($fInfo, $shared); |
|
| 148 | - $source = $this->fileService->buildSource($fInfo, $shared); |
|
| 149 | - // set the running type |
|
| 150 | - $fType = $this->fileService->getCorrectType($fInfo); |
|
| 151 | - // create a temp file for ocr processing purposes |
|
| 152 | - $tempFile = $this->getTempFile($fType); |
|
| 153 | - // Create job object |
|
| 154 | - $job = new OcrJob(OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, |
|
| 155 | - false, $fInfo->getName(), null); |
|
| 156 | - // Init client and send task / job |
|
| 157 | - // Feed the worker |
|
| 158 | - $this->redisService->sendJob($job, $languages, \OC::$SERVERROOT); |
|
| 159 | - } |
|
| 160 | - return 'PROCESSING'; |
|
| 161 | - } else { |
|
| 162 | - throw new NotFoundException($this->l10n->t('Empty parameters passed.')); |
|
| 163 | - } |
|
| 164 | - } catch (Exception $e) { |
|
| 165 | - $this->handleException($e); |
|
| 166 | - } |
|
| 167 | - } |
|
| 120 | + /** |
|
| 121 | + * Processes and prepares the files for OCR. |
|
| 122 | + * Sends the stuff to the client in order to OCR async. |
|
| 123 | + * |
|
| 124 | + * @param string[] $languages |
|
| 125 | + * @param array $files |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function process($languages, $files) { |
|
| 129 | + try { |
|
| 130 | + $this->logger->debug('Will now process files: {files} with languages: {languages}', |
|
| 131 | + [ |
|
| 132 | + 'files' => json_encode($files), |
|
| 133 | + 'languages' => json_encode($languages) |
|
| 134 | + ]); |
|
| 135 | + // Check if files and language not empty |
|
| 136 | + $noLang = $this->noLanguage($languages); |
|
| 137 | + if (!empty($files) && ($this->checkForAcceptedLanguages($languages) || $noLang)) { |
|
| 138 | + // language part: |
|
| 139 | + if ($noLang) { |
|
| 140 | + $languages = []; |
|
| 141 | + } |
|
| 142 | + // file part: |
|
| 143 | + $fileInfo = $this->fileService->buildFileInfo($files); |
|
| 144 | + foreach ($fileInfo as $fInfo) { |
|
| 145 | + // Check Shared |
|
| 146 | + $shared = $this->fileService->checkSharedWithInitiator($fInfo); |
|
| 147 | + $target = $this->fileService->buildTarget($fInfo, $shared); |
|
| 148 | + $source = $this->fileService->buildSource($fInfo, $shared); |
|
| 149 | + // set the running type |
|
| 150 | + $fType = $this->fileService->getCorrectType($fInfo); |
|
| 151 | + // create a temp file for ocr processing purposes |
|
| 152 | + $tempFile = $this->getTempFile($fType); |
|
| 153 | + // Create job object |
|
| 154 | + $job = new OcrJob(OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, |
|
| 155 | + false, $fInfo->getName(), null); |
|
| 156 | + // Init client and send task / job |
|
| 157 | + // Feed the worker |
|
| 158 | + $this->redisService->sendJob($job, $languages, \OC::$SERVERROOT); |
|
| 159 | + } |
|
| 160 | + return 'PROCESSING'; |
|
| 161 | + } else { |
|
| 162 | + throw new NotFoundException($this->l10n->t('Empty parameters passed.')); |
|
| 163 | + } |
|
| 164 | + } catch (Exception $e) { |
|
| 165 | + $this->handleException($e); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Delete an ocr job for a given id and userId. |
|
| 171 | - * |
|
| 172 | - * @param |
|
| 173 | - * $jobId |
|
| 174 | - * @param string $userId |
|
| 175 | - * @return OcrJob |
|
| 176 | - */ |
|
| 177 | - public function deleteJob($jobId, $userId) { |
|
| 178 | - try { |
|
| 179 | - $job = $this->jobMapper->find($jobId); |
|
| 180 | - if ($job->getUserId() !== $userId) { |
|
| 181 | - throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.')); |
|
| 182 | - } else { |
|
| 183 | - $job = $this->jobMapper->delete($job); |
|
| 184 | - } |
|
| 185 | - $job->setTarget(null); |
|
| 186 | - $job->setSource(null); |
|
| 187 | - $job->setStatus(null); |
|
| 188 | - $job->setTempFile(null); |
|
| 189 | - $job->setType(null); |
|
| 190 | - $job->setUserId(null); |
|
| 191 | - $job->setErrorDisplayed(null); |
|
| 192 | - return $job; |
|
| 193 | - } catch (Exception $e) { |
|
| 194 | - if ($e instanceof DoesNotExistException) { |
|
| 195 | - $ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.')); |
|
| 196 | - $this->handleException($ex); |
|
| 197 | - } else { |
|
| 198 | - $this->handleException($e); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 169 | + /** |
|
| 170 | + * Delete an ocr job for a given id and userId. |
|
| 171 | + * |
|
| 172 | + * @param |
|
| 173 | + * $jobId |
|
| 174 | + * @param string $userId |
|
| 175 | + * @return OcrJob |
|
| 176 | + */ |
|
| 177 | + public function deleteJob($jobId, $userId) { |
|
| 178 | + try { |
|
| 179 | + $job = $this->jobMapper->find($jobId); |
|
| 180 | + if ($job->getUserId() !== $userId) { |
|
| 181 | + throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.')); |
|
| 182 | + } else { |
|
| 183 | + $job = $this->jobMapper->delete($job); |
|
| 184 | + } |
|
| 185 | + $job->setTarget(null); |
|
| 186 | + $job->setSource(null); |
|
| 187 | + $job->setStatus(null); |
|
| 188 | + $job->setTempFile(null); |
|
| 189 | + $job->setType(null); |
|
| 190 | + $job->setUserId(null); |
|
| 191 | + $job->setErrorDisplayed(null); |
|
| 192 | + return $job; |
|
| 193 | + } catch (Exception $e) { |
|
| 194 | + if ($e instanceof DoesNotExistException) { |
|
| 195 | + $ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.')); |
|
| 196 | + $this->handleException($ex); |
|
| 197 | + } else { |
|
| 198 | + $this->handleException($e); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * Gets all job objects for a specific user. |
|
| 205 | - * |
|
| 206 | - * @param string $userId |
|
| 207 | - * @return array |
|
| 208 | - */ |
|
| 209 | - public function getAllJobsForUser($userId) { |
|
| 210 | - try { |
|
| 211 | - $jobs = $this->jobMapper->findAll($userId); |
|
| 212 | - $jobsNew = array(); |
|
| 213 | - foreach ($jobs as $job) { |
|
| 214 | - $job->setTarget(null); |
|
| 215 | - $job->setSource(null); |
|
| 216 | - $job->setTempFile(null); |
|
| 217 | - $job->setType(null); |
|
| 218 | - $job->setUserId(null); |
|
| 219 | - $job->setErrorDisplayed(null); |
|
| 220 | - array_push($jobsNew, $job); |
|
| 221 | - } |
|
| 222 | - return $jobsNew; |
|
| 223 | - } catch (Exception $e) { |
|
| 224 | - $this->handleException($e); |
|
| 225 | - } |
|
| 226 | - } |
|
| 203 | + /** |
|
| 204 | + * Gets all job objects for a specific user. |
|
| 205 | + * |
|
| 206 | + * @param string $userId |
|
| 207 | + * @return array |
|
| 208 | + */ |
|
| 209 | + public function getAllJobsForUser($userId) { |
|
| 210 | + try { |
|
| 211 | + $jobs = $this->jobMapper->findAll($userId); |
|
| 212 | + $jobsNew = array(); |
|
| 213 | + foreach ($jobs as $job) { |
|
| 214 | + $job->setTarget(null); |
|
| 215 | + $job->setSource(null); |
|
| 216 | + $job->setTempFile(null); |
|
| 217 | + $job->setType(null); |
|
| 218 | + $job->setUserId(null); |
|
| 219 | + $job->setErrorDisplayed(null); |
|
| 220 | + array_push($jobsNew, $job); |
|
| 221 | + } |
|
| 222 | + return $jobsNew; |
|
| 223 | + } catch (Exception $e) { |
|
| 224 | + $this->handleException($e); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * The function checks if there are finished jobs to process finally. |
|
| 230 | - * |
|
| 231 | - * @throws NotFoundException |
|
| 232 | - */ |
|
| 233 | - public function checkForFinishedJobs() { |
|
| 234 | - try { |
|
| 235 | - $finishedJobs = $this->redisService->readingFinishedJobs(); |
|
| 236 | - foreach ($finishedJobs as $finishedJob) { |
|
| 237 | - $fJob = $this->transformJob($finishedJob); |
|
| 238 | - $this->logger->debug('The following job finished: {job}', |
|
| 239 | - [ |
|
| 240 | - 'job' => $fJob |
|
| 241 | - ]); |
|
| 242 | - $this->jobFinished($fJob->id, $fJob->error, $fJob->log); |
|
| 243 | - } |
|
| 244 | - } catch (Exception $e) { |
|
| 245 | - throw new NotFoundException($this->l10n->t('Reading the finished jobs from redis went wrong.')); |
|
| 246 | - } |
|
| 247 | - } |
|
| 228 | + /** |
|
| 229 | + * The function checks if there are finished jobs to process finally. |
|
| 230 | + * |
|
| 231 | + * @throws NotFoundException |
|
| 232 | + */ |
|
| 233 | + public function checkForFinishedJobs() { |
|
| 234 | + try { |
|
| 235 | + $finishedJobs = $this->redisService->readingFinishedJobs(); |
|
| 236 | + foreach ($finishedJobs as $finishedJob) { |
|
| 237 | + $fJob = $this->transformJob($finishedJob); |
|
| 238 | + $this->logger->debug('The following job finished: {job}', |
|
| 239 | + [ |
|
| 240 | + 'job' => $fJob |
|
| 241 | + ]); |
|
| 242 | + $this->jobFinished($fJob->id, $fJob->error, $fJob->log); |
|
| 243 | + } |
|
| 244 | + } catch (Exception $e) { |
|
| 245 | + throw new NotFoundException($this->l10n->t('Reading the finished jobs from redis went wrong.')); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * The function the worker will call in order to set the jobs status. |
|
| 251 | - * The worker should call it automatically after each processing step. |
|
| 252 | - * |
|
| 253 | - * @param integer $jobId |
|
| 254 | - * @param boolean $error |
|
| 255 | - * @param string $log |
|
| 256 | - */ |
|
| 257 | - public function jobFinished($jobId, $error, $log) { |
|
| 258 | - try { |
|
| 259 | - $job = $this->jobMapper->find($jobId); |
|
| 260 | - if (!$error) { |
|
| 261 | - $job->setStatus(OcrConstants::STATUS_PROCESSED); |
|
| 262 | - $this->jobMapper->update($job); |
|
| 263 | - } else { |
|
| 264 | - $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 265 | - $job->setErrorLog($log); |
|
| 266 | - $this->jobMapper->update($job); |
|
| 267 | - $this->logger->error($log); |
|
| 268 | - } |
|
| 269 | - } catch (Exception $e) { |
|
| 270 | - $this->handleException($e); |
|
| 271 | - } |
|
| 272 | - } |
|
| 249 | + /** |
|
| 250 | + * The function the worker will call in order to set the jobs status. |
|
| 251 | + * The worker should call it automatically after each processing step. |
|
| 252 | + * |
|
| 253 | + * @param integer $jobId |
|
| 254 | + * @param boolean $error |
|
| 255 | + * @param string $log |
|
| 256 | + */ |
|
| 257 | + public function jobFinished($jobId, $error, $log) { |
|
| 258 | + try { |
|
| 259 | + $job = $this->jobMapper->find($jobId); |
|
| 260 | + if (!$error) { |
|
| 261 | + $job->setStatus(OcrConstants::STATUS_PROCESSED); |
|
| 262 | + $this->jobMapper->update($job); |
|
| 263 | + } else { |
|
| 264 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 265 | + $job->setErrorLog($log); |
|
| 266 | + $this->jobMapper->update($job); |
|
| 267 | + $this->logger->error($log); |
|
| 268 | + } |
|
| 269 | + } catch (Exception $e) { |
|
| 270 | + $this->handleException($e); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Finishes all Processed files by copying them to the right path and deleteing the temp files. |
|
| 276 | - * Returns the number of processed files. |
|
| 277 | - * |
|
| 278 | - * @return array |
|
| 279 | - */ |
|
| 280 | - public function handleProcessed() { |
|
| 281 | - try { |
|
| 282 | - $this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.'); |
|
| 283 | - $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
| 284 | - foreach ($processed as $job) { |
|
| 285 | - if ($this->fileService->fileExists($job->getTempFile())) { |
|
| 286 | - // Save the tmp file with newname |
|
| 287 | - $this->view->file_put_contents($job->getTarget(), |
|
| 288 | - $this->fileService->getFileContents($job->getTempFile())); |
|
| 289 | - $this->jobMapper->delete($job); |
|
| 290 | - $this->fileService->execRemove($job->getTempFile()); |
|
| 291 | - } else { |
|
| 292 | - $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 293 | - $job->setErrorLog('Temp file does not exist.'); |
|
| 294 | - $this->jobMapper->update($job); |
|
| 295 | - throw new NotFoundException($this->l10n->t('Temp file does not exist.')); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - return $processed; |
|
| 299 | - } catch (Exception $e) { |
|
| 300 | - $this->handleException($e); |
|
| 301 | - } |
|
| 302 | - } |
|
| 274 | + /** |
|
| 275 | + * Finishes all Processed files by copying them to the right path and deleteing the temp files. |
|
| 276 | + * Returns the number of processed files. |
|
| 277 | + * |
|
| 278 | + * @return array |
|
| 279 | + */ |
|
| 280 | + public function handleProcessed() { |
|
| 281 | + try { |
|
| 282 | + $this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.'); |
|
| 283 | + $processed = $this->jobMapper->findAllProcessed($this->userId); |
|
| 284 | + foreach ($processed as $job) { |
|
| 285 | + if ($this->fileService->fileExists($job->getTempFile())) { |
|
| 286 | + // Save the tmp file with newname |
|
| 287 | + $this->view->file_put_contents($job->getTarget(), |
|
| 288 | + $this->fileService->getFileContents($job->getTempFile())); |
|
| 289 | + $this->jobMapper->delete($job); |
|
| 290 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 291 | + } else { |
|
| 292 | + $job->setStatus(OcrConstants::STATUS_FAILED); |
|
| 293 | + $job->setErrorLog('Temp file does not exist.'); |
|
| 294 | + $this->jobMapper->update($job); |
|
| 295 | + throw new NotFoundException($this->l10n->t('Temp file does not exist.')); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + return $processed; |
|
| 299 | + } catch (Exception $e) { |
|
| 300 | + $this->handleException($e); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * Handles all failed orders of ocr processing queue and returns the job objects. |
|
| 306 | - * |
|
| 307 | - * @return array |
|
| 308 | - */ |
|
| 309 | - public function handleFailed() { |
|
| 310 | - try { |
|
| 311 | - $failed = $this->jobMapper->findAllFailed($this->userId); |
|
| 312 | - foreach ($failed as $job) { |
|
| 313 | - // clean the tempfile |
|
| 314 | - $this->fileService->execRemove($job->getTempFile()); |
|
| 315 | - // set error displayed |
|
| 316 | - $job->setErrorDisplayed(true); |
|
| 317 | - $this->jobMapper->update($job); |
|
| 318 | - } |
|
| 319 | - $this->logger->debug('Following jobs failed: {failed}', |
|
| 320 | - [ |
|
| 321 | - 'failed' => json_encode($failed) |
|
| 322 | - ]); |
|
| 323 | - return $failed; |
|
| 324 | - } catch (Exception $e) { |
|
| 325 | - $this->handleException($e); |
|
| 326 | - } |
|
| 327 | - } |
|
| 304 | + /** |
|
| 305 | + * Handles all failed orders of ocr processing queue and returns the job objects. |
|
| 306 | + * |
|
| 307 | + * @return array |
|
| 308 | + */ |
|
| 309 | + public function handleFailed() { |
|
| 310 | + try { |
|
| 311 | + $failed = $this->jobMapper->findAllFailed($this->userId); |
|
| 312 | + foreach ($failed as $job) { |
|
| 313 | + // clean the tempfile |
|
| 314 | + $this->fileService->execRemove($job->getTempFile()); |
|
| 315 | + // set error displayed |
|
| 316 | + $job->setErrorDisplayed(true); |
|
| 317 | + $this->jobMapper->update($job); |
|
| 318 | + } |
|
| 319 | + $this->logger->debug('Following jobs failed: {failed}', |
|
| 320 | + [ |
|
| 321 | + 'failed' => json_encode($failed) |
|
| 322 | + ]); |
|
| 323 | + return $failed; |
|
| 324 | + } catch (Exception $e) { |
|
| 325 | + $this->handleException($e); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Gives a temp file name back depending on the type of the OCR. |
|
| 331 | - * Later in the worker this file is used as an output. |
|
| 332 | - * |
|
| 333 | - * @param integer $type |
|
| 334 | - * @return string |
|
| 335 | - */ |
|
| 336 | - private function getTempFile($type) { |
|
| 337 | - if ($type === OcrConstants::TESSERACT) { |
|
| 338 | - $fileName = $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), OcrConstants::TEMPFILE_PREFIX); |
|
| 339 | - $this->phpUtil->unlinkWrapper($fileName); |
|
| 340 | - $fileNameWithPostfix = $fileName . '.txt'; |
|
| 341 | - $this->phpUtil->touchWrapper($fileNameWithPostfix); |
|
| 342 | - $this->phpUtil->chmodWrapper($fileNameWithPostfix, 0600); |
|
| 343 | - return $fileNameWithPostfix; |
|
| 344 | - } else { |
|
| 345 | - return $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), 'ocr_'); |
|
| 346 | - } |
|
| 347 | - } |
|
| 329 | + /** |
|
| 330 | + * Gives a temp file name back depending on the type of the OCR. |
|
| 331 | + * Later in the worker this file is used as an output. |
|
| 332 | + * |
|
| 333 | + * @param integer $type |
|
| 334 | + * @return string |
|
| 335 | + */ |
|
| 336 | + private function getTempFile($type) { |
|
| 337 | + if ($type === OcrConstants::TESSERACT) { |
|
| 338 | + $fileName = $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), OcrConstants::TEMPFILE_PREFIX); |
|
| 339 | + $this->phpUtil->unlinkWrapper($fileName); |
|
| 340 | + $fileNameWithPostfix = $fileName . '.txt'; |
|
| 341 | + $this->phpUtil->touchWrapper($fileNameWithPostfix); |
|
| 342 | + $this->phpUtil->chmodWrapper($fileNameWithPostfix, 0600); |
|
| 343 | + return $fileNameWithPostfix; |
|
| 344 | + } else { |
|
| 345 | + return $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), 'ocr_'); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - /** |
|
| 350 | - * Takes care of transforming an incoming finished job into a php readable object. |
|
| 351 | - * |
|
| 352 | - * @param string $job |
|
| 353 | - * @throws NotFoundException |
|
| 354 | - * @return mixed |
|
| 355 | - */ |
|
| 356 | - private function transformJob($job) { |
|
| 357 | - $decoded = json_decode($job); |
|
| 358 | - if ($decoded !== null && isset($decoded->id)) { |
|
| 359 | - return $decoded; |
|
| 360 | - } else { |
|
| 361 | - throw new NotFoundException($this->l10n->t('The finished job retrieved by Redis was corrupt.')); |
|
| 362 | - } |
|
| 363 | - } |
|
| 349 | + /** |
|
| 350 | + * Takes care of transforming an incoming finished job into a php readable object. |
|
| 351 | + * |
|
| 352 | + * @param string $job |
|
| 353 | + * @throws NotFoundException |
|
| 354 | + * @return mixed |
|
| 355 | + */ |
|
| 356 | + private function transformJob($job) { |
|
| 357 | + $decoded = json_decode($job); |
|
| 358 | + if ($decoded !== null && isset($decoded->id)) { |
|
| 359 | + return $decoded; |
|
| 360 | + } else { |
|
| 361 | + throw new NotFoundException($this->l10n->t('The finished job retrieved by Redis was corrupt.')); |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Checks if the given languages are supported or not. |
|
| 367 | - * |
|
| 368 | - * @param string[] $languages |
|
| 369 | - * @return boolean |
|
| 370 | - */ |
|
| 371 | - private function checkForAcceptedLanguages($languages) { |
|
| 372 | - $installedLanguages = explode(';', $this->appConfigService->getAppValue('languages')); |
|
| 373 | - if (count(array_diff($languages, $installedLanguages)) === 0) { |
|
| 374 | - return true; |
|
| 375 | - } else { |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - } |
|
| 365 | + /** |
|
| 366 | + * Checks if the given languages are supported or not. |
|
| 367 | + * |
|
| 368 | + * @param string[] $languages |
|
| 369 | + * @return boolean |
|
| 370 | + */ |
|
| 371 | + private function checkForAcceptedLanguages($languages) { |
|
| 372 | + $installedLanguages = explode(';', $this->appConfigService->getAppValue('languages')); |
|
| 373 | + if (count(array_diff($languages, $installedLanguages)) === 0) { |
|
| 374 | + return true; |
|
| 375 | + } else { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Checks if the process should be initiated without any language specified. |
|
| 382 | - * |
|
| 383 | - * @param string[] $languages |
|
| 384 | - * @return boolean |
|
| 385 | - */ |
|
| 386 | - private function noLanguage($languages) { |
|
| 387 | - if (in_array('any', $languages)) { |
|
| 388 | - return true; |
|
| 389 | - } else { |
|
| 390 | - return false; |
|
| 391 | - } |
|
| 392 | - } |
|
| 380 | + /** |
|
| 381 | + * Checks if the process should be initiated without any language specified. |
|
| 382 | + * |
|
| 383 | + * @param string[] $languages |
|
| 384 | + * @return boolean |
|
| 385 | + */ |
|
| 386 | + private function noLanguage($languages) { |
|
| 387 | + if (in_array('any', $languages)) { |
|
| 388 | + return true; |
|
| 389 | + } else { |
|
| 390 | + return false; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - /** |
|
| 395 | - * Handle the possible thrown Exceptions from all methods of this class. |
|
| 396 | - * |
|
| 397 | - * @param Exception $e |
|
| 398 | - * @throws Exception |
|
| 399 | - * @throws NotFoundException |
|
| 400 | - */ |
|
| 401 | - private function handleException($e) { |
|
| 402 | - $this->logger->logException($e, |
|
| 403 | - [ |
|
| 404 | - 'message' => 'Exception during job service function processing' |
|
| 405 | - ]); |
|
| 406 | - throw $e; |
|
| 407 | - } |
|
| 394 | + /** |
|
| 395 | + * Handle the possible thrown Exceptions from all methods of this class. |
|
| 396 | + * |
|
| 397 | + * @param Exception $e |
|
| 398 | + * @throws Exception |
|
| 399 | + * @throws NotFoundException |
|
| 400 | + */ |
|
| 401 | + private function handleException($e) { |
|
| 402 | + $this->logger->logException($e, |
|
| 403 | + [ |
|
| 404 | + 'message' => 'Exception during job service function processing' |
|
| 405 | + ]); |
|
| 406 | + throw $e; |
|
| 407 | + } |
|
| 408 | 408 | } |
| 409 | 409 | \ No newline at end of file |
@@ -8,10 +8,10 @@ |
||
| 8 | 8 | * @copyright Janis Koehr 2017 |
| 9 | 9 | */ |
| 10 | 10 | style('ocr', [ |
| 11 | - 'ocrpersonal' |
|
| 11 | + 'ocrpersonal' |
|
| 12 | 12 | ]); |
| 13 | 13 | script('ocr', [ |
| 14 | - 'dist/ocrpersonal' |
|
| 14 | + 'dist/ocrpersonal' |
|
| 15 | 15 | ]); |
| 16 | 16 | ?> |
| 17 | 17 | |
@@ -8,47 +8,47 @@ |
||
| 8 | 8 | * @copyright Janis Koehr 2017 |
| 9 | 9 | */ |
| 10 | 10 | return [ |
| 11 | - 'routes' => [ |
|
| 12 | - [ |
|
| 13 | - 'name' => 'Job#process', |
|
| 14 | - 'url' => '/', |
|
| 15 | - 'verb' => 'POST' |
|
| 16 | - ], |
|
| 17 | - [ |
|
| 18 | - 'name' => 'Job#deleteJob', |
|
| 19 | - 'url' => '/', |
|
| 20 | - 'verb' => 'DELETE' |
|
| 21 | - ], |
|
| 22 | - [ |
|
| 23 | - 'name' => 'Job#getAllJobs', |
|
| 24 | - 'url' => '/', |
|
| 25 | - 'verb' => 'GET' |
|
| 26 | - ], |
|
| 27 | - [ |
|
| 28 | - 'name' => 'Status#getStatus', |
|
| 29 | - 'url' => '/status', |
|
| 30 | - 'verb' => 'GET' |
|
| 31 | - ], |
|
| 32 | - // settings |
|
| 33 | - [ |
|
| 34 | - 'name' => 'AdminSettings#setLanguages', |
|
| 35 | - 'url' => '/admin/languages', |
|
| 36 | - 'verb' => 'POST' |
|
| 37 | - ], |
|
| 38 | - [ |
|
| 39 | - 'name' => 'AdminSettings#setRedis', |
|
| 40 | - 'url' => '/admin/redis', |
|
| 41 | - 'verb' => 'POST' |
|
| 42 | - ], |
|
| 43 | - [ |
|
| 44 | - 'name' => 'AdminSettings#getLanguages', |
|
| 45 | - 'url' => '/languages', |
|
| 46 | - 'verb' => 'GET' |
|
| 47 | - ], |
|
| 48 | - [ |
|
| 49 | - 'name' => 'AdminSettings#evaluateRedisSettings', |
|
| 50 | - 'url' => '/redis', |
|
| 51 | - 'verb' => 'GET' |
|
| 52 | - ] |
|
| 53 | - ] |
|
| 11 | + 'routes' => [ |
|
| 12 | + [ |
|
| 13 | + 'name' => 'Job#process', |
|
| 14 | + 'url' => '/', |
|
| 15 | + 'verb' => 'POST' |
|
| 16 | + ], |
|
| 17 | + [ |
|
| 18 | + 'name' => 'Job#deleteJob', |
|
| 19 | + 'url' => '/', |
|
| 20 | + 'verb' => 'DELETE' |
|
| 21 | + ], |
|
| 22 | + [ |
|
| 23 | + 'name' => 'Job#getAllJobs', |
|
| 24 | + 'url' => '/', |
|
| 25 | + 'verb' => 'GET' |
|
| 26 | + ], |
|
| 27 | + [ |
|
| 28 | + 'name' => 'Status#getStatus', |
|
| 29 | + 'url' => '/status', |
|
| 30 | + 'verb' => 'GET' |
|
| 31 | + ], |
|
| 32 | + // settings |
|
| 33 | + [ |
|
| 34 | + 'name' => 'AdminSettings#setLanguages', |
|
| 35 | + 'url' => '/admin/languages', |
|
| 36 | + 'verb' => 'POST' |
|
| 37 | + ], |
|
| 38 | + [ |
|
| 39 | + 'name' => 'AdminSettings#setRedis', |
|
| 40 | + 'url' => '/admin/redis', |
|
| 41 | + 'verb' => 'POST' |
|
| 42 | + ], |
|
| 43 | + [ |
|
| 44 | + 'name' => 'AdminSettings#getLanguages', |
|
| 45 | + 'url' => '/languages', |
|
| 46 | + 'verb' => 'GET' |
|
| 47 | + ], |
|
| 48 | + [ |
|
| 49 | + 'name' => 'AdminSettings#evaluateRedisSettings', |
|
| 50 | + 'url' => '/redis', |
|
| 51 | + 'verb' => 'GET' |
|
| 52 | + ] |
|
| 53 | + ] |
|
| 54 | 54 | ]; |
| 55 | 55 | \ No newline at end of file |
@@ -38,106 +38,106 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class OcrJob extends Entity implements JsonSerializable { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $status; |
|
| 41 | + /** |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $status; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - protected $source; |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + protected $source; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - protected $target; |
|
| 53 | + /** |
|
| 54 | + * |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + protected $target; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - protected $tempFile; |
|
| 59 | + /** |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + protected $tempFile; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $type; |
|
| 65 | + /** |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $type; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $userId; |
|
| 71 | + /** |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $userId; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * |
|
| 79 | - * @var boolean |
|
| 80 | - */ |
|
| 81 | - protected $errorDisplayed; |
|
| 77 | + /** |
|
| 78 | + * |
|
| 79 | + * @var boolean |
|
| 80 | + */ |
|
| 81 | + protected $errorDisplayed; |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * |
|
| 85 | - * @var string |
|
| 86 | - */ |
|
| 87 | - protected $originalFilename; |
|
| 83 | + /** |
|
| 84 | + * |
|
| 85 | + * @var string |
|
| 86 | + */ |
|
| 87 | + protected $originalFilename; |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * |
|
| 91 | - * @var string |
|
| 92 | - */ |
|
| 93 | - protected $errorLog; |
|
| 89 | + /** |
|
| 90 | + * |
|
| 91 | + * @var string |
|
| 92 | + */ |
|
| 93 | + protected $errorLog; |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * OcrJob constructor. |
|
| 97 | - * |
|
| 98 | - * @param string $status |
|
| 99 | - * @param string $source |
|
| 100 | - * @param string $target |
|
| 101 | - * @param string $tempFile |
|
| 102 | - * @param string $type |
|
| 103 | - * @param string $userId |
|
| 104 | - * @param boolean $errorDisplayed |
|
| 105 | - * @param string $originalFilename |
|
| 106 | - * @param string $errorLog |
|
| 107 | - */ |
|
| 108 | - public function __construct($status = null, $source = null, $target = null, $tempFile = null, $type = null, $userId = null, |
|
| 109 | - $errorDisplayed = null, $originalFilename = null, $errorLog = null) { |
|
| 110 | - $this->setStatus($status); |
|
| 111 | - $this->setSource($source); |
|
| 112 | - $this->setTarget($target); |
|
| 113 | - $this->setTempFile($tempFile); |
|
| 114 | - $this->setType($type); |
|
| 115 | - $this->setUserId($userId); |
|
| 116 | - $this->setErrorDisplayed($errorDisplayed); |
|
| 117 | - $this->setOriginalFilename($originalFilename); |
|
| 118 | - $this->setErrorLog($errorLog); |
|
| 119 | - } |
|
| 95 | + /** |
|
| 96 | + * OcrJob constructor. |
|
| 97 | + * |
|
| 98 | + * @param string $status |
|
| 99 | + * @param string $source |
|
| 100 | + * @param string $target |
|
| 101 | + * @param string $tempFile |
|
| 102 | + * @param string $type |
|
| 103 | + * @param string $userId |
|
| 104 | + * @param boolean $errorDisplayed |
|
| 105 | + * @param string $originalFilename |
|
| 106 | + * @param string $errorLog |
|
| 107 | + */ |
|
| 108 | + public function __construct($status = null, $source = null, $target = null, $tempFile = null, $type = null, $userId = null, |
|
| 109 | + $errorDisplayed = null, $originalFilename = null, $errorLog = null) { |
|
| 110 | + $this->setStatus($status); |
|
| 111 | + $this->setSource($source); |
|
| 112 | + $this->setTarget($target); |
|
| 113 | + $this->setTempFile($tempFile); |
|
| 114 | + $this->setType($type); |
|
| 115 | + $this->setUserId($userId); |
|
| 116 | + $this->setErrorDisplayed($errorDisplayed); |
|
| 117 | + $this->setOriginalFilename($originalFilename); |
|
| 118 | + $this->setErrorLog($errorLog); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Specify data which should be serialized to JSON |
|
| 123 | - * |
|
| 124 | - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
| 125 | - * @return mixed data which can be serialized by <b>json_encode</b>, |
|
| 126 | - * which is a value of any type other than a resource. |
|
| 127 | - * @since 5.4.0 |
|
| 128 | - */ |
|
| 129 | - function jsonSerialize() { |
|
| 130 | - return [ |
|
| 131 | - 'id' => $this->id, |
|
| 132 | - 'status' => $this->status, |
|
| 133 | - 'source' => $this->source, |
|
| 134 | - 'target' => $this->target, |
|
| 135 | - 'tempFile' => $this->tempFile, |
|
| 136 | - 'type' => $this->type, |
|
| 137 | - 'userId' => $this->userId, |
|
| 138 | - 'errorDisplayed' => $this->errorDisplayed, |
|
| 139 | - 'originalFilename' => $this->originalFilename, |
|
| 140 | - 'errorLog' => $this->errorLog |
|
| 141 | - ]; |
|
| 142 | - } |
|
| 121 | + /** |
|
| 122 | + * Specify data which should be serialized to JSON |
|
| 123 | + * |
|
| 124 | + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
| 125 | + * @return mixed data which can be serialized by <b>json_encode</b>, |
|
| 126 | + * which is a value of any type other than a resource. |
|
| 127 | + * @since 5.4.0 |
|
| 128 | + */ |
|
| 129 | + function jsonSerialize() { |
|
| 130 | + return [ |
|
| 131 | + 'id' => $this->id, |
|
| 132 | + 'status' => $this->status, |
|
| 133 | + 'source' => $this->source, |
|
| 134 | + 'target' => $this->target, |
|
| 135 | + 'tempFile' => $this->tempFile, |
|
| 136 | + 'type' => $this->type, |
|
| 137 | + 'userId' => $this->userId, |
|
| 138 | + 'errorDisplayed' => $this->errorDisplayed, |
|
| 139 | + 'originalFilename' => $this->originalFilename, |
|
| 140 | + 'errorLog' => $this->errorLog |
|
| 141 | + ]; |
|
| 142 | + } |
|
| 143 | 143 | } |
| 144 | 144 | \ No newline at end of file |
@@ -21,18 +21,18 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Share extends Entity { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $fileTarget; |
|
| 24 | + /** |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $fileTarget; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Share constructor. |
|
| 32 | - * |
|
| 33 | - * @param null $fileTarget |
|
| 34 | - */ |
|
| 35 | - public function __construct($fileTarget = null) { |
|
| 36 | - $this->fileTarget = $fileTarget; |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * Share constructor. |
|
| 32 | + * |
|
| 33 | + * @param null $fileTarget |
|
| 34 | + */ |
|
| 35 | + public function __construct($fileTarget = null) { |
|
| 36 | + $this->fileTarget = $fileTarget; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -21,29 +21,29 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class ShareMapper extends Mapper { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * ShareMapper constructor. |
|
| 26 | - * |
|
| 27 | - * @param IDBConnection $db |
|
| 28 | - */ |
|
| 29 | - public function __construct(IDBConnection $db) { |
|
| 30 | - parent::__construct($db, 'share', 'OCA\Ocr\Db\Share'); |
|
| 31 | - } |
|
| 24 | + /** |
|
| 25 | + * ShareMapper constructor. |
|
| 26 | + * |
|
| 27 | + * @param IDBConnection $db |
|
| 28 | + */ |
|
| 29 | + public function __construct(IDBConnection $db) { |
|
| 30 | + parent::__construct($db, 'share', 'OCA\Ocr\Db\Share'); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Find the right name for a shared file |
|
| 35 | - * |
|
| 36 | - * @param integer $fileid |
|
| 37 | - * @param string $shareWith |
|
| 38 | - * @param string $owner |
|
| 39 | - * @return Share |
|
| 40 | - */ |
|
| 41 | - public function find($fileid, $shareWith, $owner) { |
|
| 42 | - $sql = 'SELECT file_target FROM *PREFIX*share WHERE file_source = ? AND share_with = ? AND uid_owner = ?'; |
|
| 43 | - return $this->findEntity($sql, [ |
|
| 44 | - $fileid, |
|
| 45 | - $shareWith, |
|
| 46 | - $owner |
|
| 47 | - ]); |
|
| 48 | - } |
|
| 33 | + /** |
|
| 34 | + * Find the right name for a shared file |
|
| 35 | + * |
|
| 36 | + * @param integer $fileid |
|
| 37 | + * @param string $shareWith |
|
| 38 | + * @param string $owner |
|
| 39 | + * @return Share |
|
| 40 | + */ |
|
| 41 | + public function find($fileid, $shareWith, $owner) { |
|
| 42 | + $sql = 'SELECT file_target FROM *PREFIX*share WHERE file_source = ? AND share_with = ? AND uid_owner = ?'; |
|
| 43 | + return $this->findEntity($sql, [ |
|
| 44 | + $fileid, |
|
| 45 | + $shareWith, |
|
| 46 | + $owner |
|
| 47 | + ]); |
|
| 48 | + } |
|
| 49 | 49 | } |
| 50 | 50 | \ No newline at end of file |
@@ -22,86 +22,86 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class OcrJobMapper extends Mapper { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * OcrJobMapper constructor. |
|
| 27 | - * |
|
| 28 | - * @param IDBConnection $db |
|
| 29 | - */ |
|
| 30 | - public function __construct(IDBConnection $db) { |
|
| 31 | - parent::__construct($db, 'ocr_jobs', 'OCA\Ocr\Db\OcrJob'); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * OcrJobMapper constructor. |
|
| 27 | + * |
|
| 28 | + * @param IDBConnection $db |
|
| 29 | + */ |
|
| 30 | + public function __construct(IDBConnection $db) { |
|
| 31 | + parent::__construct($db, 'ocr_jobs', 'OCA\Ocr\Db\OcrJob'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Find a specific job entity |
|
| 36 | - * |
|
| 37 | - * @param |
|
| 38 | - * $id |
|
| 39 | - * @return OcrJob |
|
| 40 | - */ |
|
| 41 | - public function find($id) { |
|
| 42 | - $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE id = ?'; |
|
| 43 | - return $this->findEntity($sql, [ |
|
| 44 | - $id |
|
| 45 | - ]); |
|
| 46 | - } |
|
| 34 | + /** |
|
| 35 | + * Find a specific job entity |
|
| 36 | + * |
|
| 37 | + * @param |
|
| 38 | + * $id |
|
| 39 | + * @return OcrJob |
|
| 40 | + */ |
|
| 41 | + public function find($id) { |
|
| 42 | + $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE id = ?'; |
|
| 43 | + return $this->findEntity($sql, [ |
|
| 44 | + $id |
|
| 45 | + ]); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Finds all user specific jobs entities |
|
| 50 | - * |
|
| 51 | - * @param |
|
| 52 | - * $userId |
|
| 53 | - * @return OcrJob[] |
|
| 54 | - */ |
|
| 55 | - public function findAll($userId) { |
|
| 56 | - $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ?'; |
|
| 57 | - return $this->findEntities($sql, [ |
|
| 58 | - $userId |
|
| 59 | - ]); |
|
| 60 | - } |
|
| 48 | + /** |
|
| 49 | + * Finds all user specific jobs entities |
|
| 50 | + * |
|
| 51 | + * @param |
|
| 52 | + * $userId |
|
| 53 | + * @return OcrJob[] |
|
| 54 | + */ |
|
| 55 | + public function findAll($userId) { |
|
| 56 | + $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ?'; |
|
| 57 | + return $this->findEntities($sql, [ |
|
| 58 | + $userId |
|
| 59 | + ]); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Finds all jobs PROCESSED entities for a given userid |
|
| 64 | - * |
|
| 65 | - * @param |
|
| 66 | - * $userId |
|
| 67 | - * @return OcrJob[] |
|
| 68 | - */ |
|
| 69 | - public function findAllProcessed($userId) { |
|
| 70 | - $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
|
| 71 | - return $this->findEntities($sql, [ |
|
| 72 | - $userId, |
|
| 73 | - OcrConstants::STATUS_PROCESSED |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 62 | + /** |
|
| 63 | + * Finds all jobs PROCESSED entities for a given userid |
|
| 64 | + * |
|
| 65 | + * @param |
|
| 66 | + * $userId |
|
| 67 | + * @return OcrJob[] |
|
| 68 | + */ |
|
| 69 | + public function findAllProcessed($userId) { |
|
| 70 | + $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
|
| 71 | + return $this->findEntities($sql, [ |
|
| 72 | + $userId, |
|
| 73 | + OcrConstants::STATUS_PROCESSED |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Finds all jobs PENDING entities for a given userid. |
|
| 79 | - * |
|
| 80 | - * @param |
|
| 81 | - * $userId |
|
| 82 | - * @return OcrJob[] |
|
| 83 | - */ |
|
| 84 | - public function findAllPending($userId) { |
|
| 85 | - $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
|
| 86 | - return $this->findEntities($sql, [ |
|
| 87 | - $userId, |
|
| 88 | - OcrConstants::STATUS_PENDING |
|
| 89 | - ]); |
|
| 90 | - } |
|
| 77 | + /** |
|
| 78 | + * Finds all jobs PENDING entities for a given userid. |
|
| 79 | + * |
|
| 80 | + * @param |
|
| 81 | + * $userId |
|
| 82 | + * @return OcrJob[] |
|
| 83 | + */ |
|
| 84 | + public function findAllPending($userId) { |
|
| 85 | + $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
|
| 86 | + return $this->findEntities($sql, [ |
|
| 87 | + $userId, |
|
| 88 | + OcrConstants::STATUS_PENDING |
|
| 89 | + ]); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Finds all jobs FAILED entities for a given userid, which were not displayed yet. |
|
| 94 | - * |
|
| 95 | - * @param |
|
| 96 | - * $userId |
|
| 97 | - * @return OcrJob[] |
|
| 98 | - */ |
|
| 99 | - public function findAllFailed($userId) { |
|
| 100 | - $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ? AND error_displayed = ?'; |
|
| 101 | - return $this->findEntities($sql, [ |
|
| 102 | - $userId, |
|
| 103 | - OcrConstants::STATUS_FAILED, |
|
| 104 | - false |
|
| 105 | - ]); |
|
| 106 | - } |
|
| 92 | + /** |
|
| 93 | + * Finds all jobs FAILED entities for a given userid, which were not displayed yet. |
|
| 94 | + * |
|
| 95 | + * @param |
|
| 96 | + * $userId |
|
| 97 | + * @return OcrJob[] |
|
| 98 | + */ |
|
| 99 | + public function findAllFailed($userId) { |
|
| 100 | + $sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ? AND error_displayed = ?'; |
|
| 101 | + return $this->findEntities($sql, [ |
|
| 102 | + $userId, |
|
| 103 | + OcrConstants::STATUS_FAILED, |
|
| 104 | + false |
|
| 105 | + ]); |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | \ No newline at end of file |
@@ -21,28 +21,28 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class FileMapper extends Mapper { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * FileMapper constructor. |
|
| 26 | - * ATTENTION: the common methods like 'delete' 'update' and things like that will not work because we join and |
|
| 27 | - * cleanup some columns!!! |
|
| 28 | - * |
|
| 29 | - * @param IDBConnection $db |
|
| 30 | - */ |
|
| 31 | - public function __construct(IDBConnection $db) { |
|
| 32 | - parent::__construct($db, 'filecache', 'OCA\Ocr\Db\File'); |
|
| 33 | - } |
|
| 24 | + /** |
|
| 25 | + * FileMapper constructor. |
|
| 26 | + * ATTENTION: the common methods like 'delete' 'update' and things like that will not work because we join and |
|
| 27 | + * cleanup some columns!!! |
|
| 28 | + * |
|
| 29 | + * @param IDBConnection $db |
|
| 30 | + */ |
|
| 31 | + public function __construct(IDBConnection $db) { |
|
| 32 | + parent::__construct($db, 'filecache', 'OCA\Ocr\Db\File'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Find a specific file entity |
|
| 37 | - * |
|
| 38 | - * @param |
|
| 39 | - * $fileid |
|
| 40 | - * @return File |
|
| 41 | - */ |
|
| 42 | - public function find($fileid) { |
|
| 43 | - $sql = 'SELECT f.fileid AS fileid, f.path AS path, f.name as name, m.mimetype AS mimetype, s.id AS storagename FROM *PREFIX*filecache AS f, *PREFIX*mimetypes AS m, *PREFIX*storages AS s WHERE f.fileid = ? AND f.mimetype = m.id AND f.storage = s.numeric_id'; |
|
| 44 | - return $this->findEntity($sql, [ |
|
| 45 | - $fileid |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 35 | + /** |
|
| 36 | + * Find a specific file entity |
|
| 37 | + * |
|
| 38 | + * @param |
|
| 39 | + * $fileid |
|
| 40 | + * @return File |
|
| 41 | + */ |
|
| 42 | + public function find($fileid) { |
|
| 43 | + $sql = 'SELECT f.fileid AS fileid, f.path AS path, f.name as name, m.mimetype AS mimetype, s.id AS storagename FROM *PREFIX*filecache AS f, *PREFIX*mimetypes AS m, *PREFIX*storages AS s WHERE f.fileid = ? AND f.mimetype = m.id AND f.storage = s.numeric_id'; |
|
| 44 | + return $this->findEntity($sql, [ |
|
| 45 | + $fileid |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -25,50 +25,50 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class File extends Entity { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * |
|
| 30 | - * @var integer |
|
| 31 | - */ |
|
| 32 | - protected $fileid; |
|
| 28 | + /** |
|
| 29 | + * |
|
| 30 | + * @var integer |
|
| 31 | + */ |
|
| 32 | + protected $fileid; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $path; |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $path; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - protected $name; |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + protected $name; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - protected $mimetype; |
|
| 46 | + /** |
|
| 47 | + * |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + protected $mimetype; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $storagename; |
|
| 52 | + /** |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $storagename; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * File constructor. |
|
| 60 | - * |
|
| 61 | - * @param null $fileid |
|
| 62 | - * @param null $path |
|
| 63 | - * @param null $name |
|
| 64 | - * @param null $mimetype |
|
| 65 | - * @param null $storagename |
|
| 66 | - */ |
|
| 67 | - public function __construct($fileid = null, $path = null, $name = null, $mimetype = null, $storagename = null) { |
|
| 68 | - $this->fileid = $fileid; |
|
| 69 | - $this->path = $path; |
|
| 70 | - $this->name = $name; |
|
| 71 | - $this->mimetype = $mimetype; |
|
| 72 | - $this->storagename = $storagename; |
|
| 73 | - } |
|
| 58 | + /** |
|
| 59 | + * File constructor. |
|
| 60 | + * |
|
| 61 | + * @param null $fileid |
|
| 62 | + * @param null $path |
|
| 63 | + * @param null $name |
|
| 64 | + * @param null $mimetype |
|
| 65 | + * @param null $storagename |
|
| 66 | + */ |
|
| 67 | + public function __construct($fileid = null, $path = null, $name = null, $mimetype = null, $storagename = null) { |
|
| 68 | + $this->fileid = $fileid; |
|
| 69 | + $this->path = $path; |
|
| 70 | + $this->name = $name; |
|
| 71 | + $this->mimetype = $mimetype; |
|
| 72 | + $this->storagename = $storagename; |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |