Completed
Push — master ( b9c55a...e58c6b )
by Maxence
08:16
created

FilesService::isSourceIndexable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
/**
3
 * Files_FullTextSearch - Index the content of your files
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2018
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Files_FullTextSearch\Service;
28
29
30
use Exception;
31
use OCA\Files_FullTextSearch\Exceptions\FileIsNotIndexableException;
32
use OCA\Files_FullTextSearch\Exceptions\KnownFileSourceException;
33
use OCA\Files_FullTextSearch\Model\FilesDocument;
34
use OCA\Files_FullTextSearch\Provider\FilesProvider;
35
use OCA\FullTextSearch\Exceptions\InterruptException;
36
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
37
use OCA\FullTextSearch\Model\Index;
38
use OCA\FullTextSearch\Model\IndexDocument;
39
use OCA\FullTextSearch\Model\Runner;
40
use OCP\Files\File;
41
use OCP\Files\FileInfo;
42
use OCP\Files\Folder;
43
use OCP\Files\InvalidPathException;
44
use OCP\Files\IRootFolder;
45
use OCP\Files\Node;
46
use OCP\Files\NotFoundException;
47
use OCP\Files\NotPermittedException;
48
use OCP\Files\StorageNotAvailableException;
49
use OCP\IUserManager;
50
use OCP\Share\IManager;
51
52
class FilesService {
53
54
	const MIMETYPE_TEXT = 'files_text';
55
	const MIMETYPE_PDF = 'files_pdf';
56
	const MIMETYPE_OFFICE = 'files_office';
57
	const MIMETYPE_IMAGE = 'files_image';
58
	const MIMETYPE_AUDIO = 'files_audio';
59
60
61
	/** @var IRootFolder */
62
	private $rootFolder;
63
64
	/** @var IUserManager */
65
	private $userManager;
66
67
	/** @var IManager */
68
	private $shareManager;
69
70
	/** @var ConfigService */
71
	private $configService;
72
73
	/** @var LocalFilesService */
74
	private $localFilesService;
75
76
	/** @var ExternalFilesService */
77
	private $externalFilesService;
78
79
	/** @var GroupFoldersService */
80
	private $groupFoldersService;
81
82
	/** @var MiscService */
83
	private $miscService;
84
85
86
	/**
87
	 * FilesService constructor.
88
	 *
89
	 * @param IRootFolder $rootFolder
90
	 * @param IUserManager $userManager
91
	 * @param IManager $shareManager
92
	 * @param ConfigService $configService
93
	 * @param LocalFilesService $localFilesService
94
	 * @param ExternalFilesService $externalFilesService
95
	 * @param GroupFoldersService $groupFoldersService
96
	 * @param MiscService $miscService
97
	 *
98
	 * @internal param IProviderFactory $factory
99
	 */
100
	public function __construct(
101
		IRootFolder $rootFolder, IUserManager $userManager, IManager $shareManager,
102
		ConfigService $configService,
103
		LocalFilesService $localFilesService,
104
		ExternalFilesService $externalFilesService,
105
		GroupFoldersService $groupFoldersService,
106
		MiscService $miscService
107
	) {
108
		$this->rootFolder = $rootFolder;
109
		$this->userManager = $userManager;
110
		$this->shareManager = $shareManager;
111
112
		$this->configService = $configService;
113
		$this->localFilesService = $localFilesService;
114
		$this->externalFilesService = $externalFilesService;
115
		$this->groupFoldersService = $groupFoldersService;
116
117
		$this->miscService = $miscService;
118
	}
119
120
121
	/**
122
	 * @param Runner $runner
123
	 * @param string $userId
124
	 *
125
	 * @return FilesDocument[]
126
	 * @throws InterruptException
127
	 * @throws InvalidPathException
128
	 * @throws NotFoundException
129
	 * @throws TickDoesNotExistException
130
	 */
131
	public function getFilesFromUser(Runner $runner, $userId) {
132
133
		$this->externalFilesService->initExternalFilesForUser($userId);
134
		$this->groupFoldersService->initGroupSharesForUser($userId);
135
136
		/** @var Folder $files */
137
		$files = $this->rootFolder->getUserFolder($userId)
138
								  ->get('/');
139
		$result = $this->getFilesFromDirectory($runner, $userId, $files);
140
141
		return $result;
142
	}
143
144
145
	/**
146
	 * @param Runner $runner
147
	 * @param string $userId
148
	 * @param Folder $node
149
	 *
150
	 * @return FilesDocument[]
151
	 * @throws InterruptException
152
	 * @throws InvalidPathException
153
	 * @throws NotFoundException
154
	 * @throws TickDoesNotExistException
155
	 */
156
	public function getFilesFromDirectory(Runner $runner, $userId, Folder $node) {
157
		$documents = [];
158
159
		try {
160
			if ($node->nodeExists('.noindex')) {
161
				return $documents;
162
			}
163
		} catch (StorageNotAvailableException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\StorageNotAvailableException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
164
			return $documents;
165
		}
166
167
		$files = $node->getDirectoryListing();
168
		foreach ($files as $file) {
169
			$runner->update('getFilesFromDirectory');
170
171
			try {
172
				$documents[] = $this->generateFilesDocumentFromFile($file, $userId);
173
			} catch (FileIsNotIndexableException $e) {
174
				continue;
175
			}
176
177
			if ($file->getType() === FileInfo::TYPE_FOLDER) {
178
				/** @var $file Folder */
179
				$documents =
180
					array_merge($documents, $this->getFilesFromDirectory($runner, $userId, $file));
181
			}
182
		}
183
184
		return $documents;
185
	}
186
187
188
	/**
189
	 * @param Node $file
190
	 *
191
	 * @param string $viewerId
192
	 *
193
	 * @return FilesDocument
194
	 * @throws FileIsNotIndexableException
195
	 * @throws InvalidPathException
196
	 * @throws NotFoundException
197
	 * @throws Exception
198
	 */
199
	private function generateFilesDocumentFromFile(Node $file, $viewerId) {
200
201
		$source = $this->getFileSource($file);
202
		$document = new FilesDocument(FilesProvider::FILES_PROVIDER_ID, $file->getId());
203
204
		$ownerId = $file->getOwner()
205
						->getUID();
206
207
		$document->setType($file->getType())
208
				 ->setSource($source)
209
				 ->setOwnerId($ownerId)
210
				 ->setPath($this->getPathFromViewerId($file->getId(), $viewerId))
211
				 ->setViewerId($viewerId)
212
				 ->setModifiedTime($file->getMTime())
213
				 ->setMimetype($file->getMimetype());
214
215
		return $document;
216
	}
217
218
219
	/**
220
	 * @param Node $file
221
	 *
222
	 * @return string
223
	 * @throws FileIsNotIndexableException
224
	 * @throws NotFoundException
225
	 */
226
	private function getFileSource(Node $file) {
227
		$source = '';
228
229
		try {
230
			$this->localFilesService->getFileSource($file, $source);
231
			$this->externalFilesService->getFileSource($file, $source);
232
			$this->groupFoldersService->getFileSource($file, $source);
233
		} catch (KnownFileSourceException $e) {
234
			/** we know the source, just leave. */
235
		}
236
237
		return $source;
238
	}
239
240
241
	/**
242
	 * @param string $userId
243
	 * @param string $path
244
	 *
245
	 * @return Node
246
	 * @throws NotFoundException
247
	 */
248
	public function getFileFromPath($userId, $path) {
249
		return $this->rootFolder->getUserFolder($userId)
250
								->get($path);
251
	}
252
253
254
	/**
255
	 * @param string $userId
256
	 * @param int $fileId
257
	 *
258
	 * @return Node
259
	 */
260
	public function getFileFromId($userId, $fileId) {
261
262
		try {
263
			$files = $this->rootFolder->getUserFolder($userId)
264
									  ->getById($fileId);
265
		} catch (Exception $e) {
266
			return null;
267
		}
268
269
		if (sizeof($files) === 0) {
270
			return null;
271
		}
272
273
		$file = array_shift($files);
274
275
		return $file;
276
	}
277
278
279
	/**
280
	 * @param int $fileId
281
	 * @param string $viewerId
282
	 *
283
	 * @throws Exception
284
	 * @return string
285
	 */
286
	private function getPathFromViewerId($fileId, $viewerId) {
287
288
		$viewerFiles = $this->rootFolder->getUserFolder($viewerId)
289
										->getById($fileId);
290
291
		if (sizeof($viewerFiles) === 0) {
292
			return '';
293
		}
294
295
		$file = array_shift($viewerFiles);
296
297
		// TODO: better way to do this : we remove the '/userid/files/'
298
		$path = MiscService::noEndSlash(substr($file->getPath(), 8 + strlen($viewerId)));
299
300
		return $path;
301
	}
302
303
304
	/**
305
	 * @param FilesDocument $document
306
	 */
307
	public function setDocumentInfo(FilesDocument $document) {
308
309
		$viewerId = $document->getAccess()
310
							 ->getViewerId();
311
312
		$viewerFiles = $this->rootFolder->getUserFolder($viewerId)
313
										->getById($document->getId());
314
315
		if (sizeof($viewerFiles) === 0) {
316
			return;
317
		}
318
		// we only take the first file
319
		$file = array_shift($viewerFiles);
320
321
		// TODO: better way to do this : we remove the '/userId/files/'
322
		$path = MiscService::noEndSlash(substr($file->getPath(), 7 + strlen($viewerId)));
323
324
		$document->setPath($path);
325
		$document->setFileName($file->getName());
326
	}
327
328
329
	/**
330
	 * @param FilesDocument $document
331
	 */
332
	public function setDocumentTitle(FilesDocument $document) {
333
		$document->setTitle($document->getPath());
334
	}
335
336
337
	/**
338
	 * @param FilesDocument $document
339
	 */
340
	public function setDocumentLink(FilesDocument $document) {
341
342
		$path = $document->getPath();
343
		$filename = $document->getFileName();
344
		$dir = substr($path, 0, -strlen($filename));
345
346
		$document->setLink(
347
			\OC::$server->getURLGenerator()
348
						->linkToRoute(
349
							'files.view.index',
350
							[
351
								'dir'      => $dir,
352
								'scrollto' => $filename,
353
							]
354
						)
355
		);
356
	}
357
358
359
	/**
360
	 * @param FilesDocument $document
361
	 *
362
	 * @throws InvalidPathException
363
	 * @throws NotFoundException
364
	 */
365
	public function setDocumentMore(FilesDocument $document) {
366
367
		$access = $document->getAccess();
368
		$file = $this->getFileFromId($access->getViewerId(), $document->getId());
369
370
		if ($file === null) {
371
			return;
372
		}
373
374
		// TODO: better way to do this : we remove the '/userid/files/'
375
		$path =
376
			MiscService::noEndSlash(substr($file->getPath(), 7 + strlen($access->getViewerId())));
377
378
		$more = [
379
			'webdav'             => $this->getWebdavId($document->getId()),
380
			'path'               => $path,
381
			'timestamp'          => $file->getMTime(), // FIXME: get the creation date of the file
382
			'mimetype'           => $file->getMimetype(),
383
			'modified_timestamp' => $file->getMTime(),
384
			'etag'               => $file->getEtag(),
385
			'permissions'        => $file->getPermissions(),
386
			'size'               => $file->getSize(),
387
			'favorite'           => false // FIXME: get the favorite status
388
		];
389
390
		$document->setMore($more);
391
	}
392
393
394
	/**
395
	 * @param FilesDocument[] $documents
396
	 *
397
	 * @return FilesDocument[]
398
	 */
399
	public function generateDocuments($documents) {
400
401
		$index = [];
402
403
		foreach ($documents as $document) {
404
			if (!($document instanceof FilesDocument)) {
405
				continue;
406
			}
407
408
			try {
409
				$this->updateFilesDocument($document);
410
			} catch (Exception $e) {
411
				// TODO - update $document with a error status instead of just ignore !
412
				$document->getIndex()
413
						 ->setStatus(Index::INDEX_IGNORE);
414
				echo 'Exception: ' . json_encode($e->getTrace()) . ' - ' . $e->getMessage() . "\n";
415
			}
416
417
			$index[] = $document;
418
		}
419
420
		return $index;
421
	}
422
423
424
	/**
425
	 * @param Index $index
426
	 *
427
	 * @return FilesDocument
428
	 * @throws FileIsNotIndexableException
429
	 * @throws InvalidPathException
430
	 * @throws NotFoundException
431
	 * @throws NotPermittedException
432
	 */
433
	private function generateDocumentFromIndex(Index $index) {
434
		$file = $this->getFileFromId($index->getOwnerId(), $index->getDocumentId());
435
436
		if ($file === null) {
437
			$index->setStatus(Index::INDEX_REMOVE);
438
			$document = new FilesDocument($index->getProviderId(), $index->getDocumentId());
439
			$document->setIndex($index);
440
441
			return $document;
442
		}
443
444
		$document = $this->generateFilesDocumentFromFile($file, $index->getOwnerId());
445
		$document->setIndex($index);
446
447
		$this->updateFilesDocumentFromFile($document, $file);
448
449
		return $document;
450
	}
451
452
453
	/**
454
	 * @param IndexDocument $document
455
	 *
456
	 * @return bool
457
	 */
458
	public function isDocumentUpToDate($document) {
459
		$index = $document->getIndex();
460
461
		if (!$this->configService->compareIndexOptions($index)) {
462
			$index->setStatus(Index::INDEX_CONTENT);
463
			$document->setIndex($index);
464
465
			return false;
466
		}
467
468
		if ($index->getStatus() !== Index::INDEX_OK) {
469
			return false;
470
		}
471
472
		if ($index->getLastIndex() >= $document->getModifiedTime()) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $index->getLastIn...ent->getModifiedTime();.
Loading history...
473
			return true;
474
		}
475
476
		return false;
477
	}
478
479
480
	/**
481
	 * @param Index $index
482
	 *
483
	 * @return FilesDocument
0 ignored issues
show
Documentation introduced by
Should the return type not be FilesDocument|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
484
	 * @throws InvalidPathException
485
	 * @throws NotFoundException
486
	 * @throws NotPermittedException
487
	 */
488
	public function updateDocument(Index $index) {
489
		try {
490
			$document = $this->generateDocumentFromIndex($index);
491
492
			return $document;
493
		} catch (FileIsNotIndexableException $e) {
494
			return null;
495
		}
496
	}
497
498
499
	/**
500
	 * @param FilesDocument $document
501
	 *
502
	 * @throws InvalidPathException
503
	 * @throws NotFoundException
504
	 * @throws NotPermittedException
505
	 */
506
	private function updateFilesDocument(FilesDocument $document) {
507
		$userFolder = $this->rootFolder->getUserFolder($document->getViewerId());
508
		$file = $userFolder->get($document->getPath());
509
510
		try {
511
			$this->updateFilesDocumentFromFile($document, $file);
512
		} catch (FileIsNotIndexableException $e) {
513
			$document->getIndex()
514
					 ->setStatus(Index::INDEX_IGNORE);
515
		}
516
	}
517
518
519
	/**
520
	 * @param FilesDocument $document
521
	 * @param Node $file
522
	 *
523
	 * @throws InvalidPathException
524
	 * @throws NotFoundException
525
	 * @throws NotPermittedException
526
	 */
527
	private function updateFilesDocumentFromFile(FilesDocument $document, Node $file) {
528
		$this->updateDocumentAccess($document, $file);
529
		$this->updateShareNames($document, $file);
530
		$this->updateContentFromFile($document, $file);
531
532
		$document->addTag($document->getSource());
533
	}
534
535
536
	/**
537
	 * @param FilesDocument $document
538
	 * @param Node $file
539
	 */
540
	private function updateDocumentAccess(FilesDocument $document, Node $file) {
541
542
		$index = $document->getIndex();
543
		if (!$index->isStatus(Index::INDEX_FULL)
544
			&& !$index->isStatus(FilesDocument::STATUS_FILE_ACCESS)) {
545
			return;
546
		}
547
548
		$this->localFilesService->updateDocumentAccess($document, $file);
549
		$this->externalFilesService->updateDocumentAccess($document, $file);
550
		$this->groupFoldersService->updateDocumentAccess($document, $file);
551
	}
552
553
554
	/**
555
	 * @param FilesDocument $document
556
	 * @param Node $file
557
	 *
558
	 * @throws InvalidPathException
559
	 * @throws NotFoundException
560
	 * @throws NotPermittedException
561
	 */
562
	private function updateContentFromFile(FilesDocument $document, Node $file) {
563
564
		$document->setTitle($document->getPath());
565
566
		if (!$document->getIndex()
567
					  ->isStatus(Index::INDEX_CONTENT)
568
			|| $file->getType() !== FileInfo::TYPE_FILE) {
569
			return;
570
		}
571
572
		/** @var File $file */
573
		if ($file->getSize() <
574
			($this->configService->getAppValue(ConfigService::FILES_SIZE) * 1024 * 1024)) {
575
			$this->extractContentFromFileText($document, $file);
576
			$this->extractContentFromFileOffice($document, $file);
577
			$this->extractContentFromFilePDF($document, $file);
578
		}
579
580
		if ($document->getContent() === null) {
581
			$document->getIndex()
582
					 ->unsetStatus(Index::INDEX_CONTENT);
583
		}
584
	}
585
586
587
	/**
588
	 * @param FilesDocument $document
589
	 * @param Node $file
590
	 *
591
	 * @return array
592
	 */
593
	private function updateShareNames(FilesDocument $document, Node $file) {
594
595
		$users = [];
596
		$this->localFilesService->getShareUsers($document, $file, $users);
597
		$this->externalFilesService->getShareUsers($document, $users);
598
		$this->groupFoldersService->getShareUsers($document, $users);
599
600
		$shareNames = [];
601
		foreach ($users as $user) {
602
			try {
603
				$shareNames[MiscService::secureUsername($user)] =
604
					$this->getPathFromViewerId($file->getId(), $user);
605
			} catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
606
			}
607
		}
608
609
		$document->setInfo('share_names', $shareNames);
610
611
//			if ($file->getStorage()
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
612
//					 ->isLocal() === false) {
613
//				$shares = $this->externalFilesService->getAllSharesFromExternalFile($access);
614
//			} else {
615
//				$shares = $this->getAllSharesFromFile($file);
616
//			}
617
//
618
//			foreach ($shares as $user) {
619
//				try {
620
//					$shareNames[$user] = $this->getPathFromViewerId($file->getId(), $user);
621
//				} catch (Exception $e) {
622
//				}
623
//			}
624
//
625
		return $shareNames;
626
627
	}
628
629
	/**
630
	 * @param int $fileId
631
	 *
632
	 * @return string
633
	 */
634
	private function getWebdavId($fileId) {
635
		$instanceId = $this->configService->getSystemValue('instanceid');
636
637
		return sprintf("%08s", $fileId) . $instanceId;
638
	}
639
640
641
	/**
642
	 * @param string $mimeType
643
	 *
644
	 * @return string
645
	 */
646
	private function parseMimeType($mimeType) {
647
648
		// text file
649
		if ($mimeType === 'application/octet-stream'
650
			|| substr($mimeType, 0, 5) === 'text/') {
651
			return self::MIMETYPE_TEXT;
652
		}
653
654
		// PDF file
655
		if ($mimeType === 'application/pdf') {
656
			return self::MIMETYPE_PDF;
657
		}
658
659
		// Office file
660
		$officeMimes = [
661
			'application/msword',
662
			'application/vnd.oasis.opendocument',
663
			'application/vnd.sun.xml',
664
			'application/vnd.openxmlformats-officedocument',
665
			'application/vnd.ms-word',
666
			'application/vnd.ms-powerpoint',
667
			'application/vnd.ms-excel'
668
		];
669
670
		foreach ($officeMimes as $mime) {
671
			if (strpos($mimeType, $mime) === 0) {
672
				return self::MIMETYPE_OFFICE;
673
			}
674
		}
675
676
		return '';
677
	}
678
679
680
	/**
681
	 * @param FilesDocument $document
682
	 * @param File $file
683
	 *
684
	 * @throws NotPermittedException
685
	 */
686
	private function extractContentFromFileText(FilesDocument $document, File $file) {
687
		if ($this->parseMimeType($document->getMimeType()) !== self::MIMETYPE_TEXT) {
688
			return;
689
		}
690
691
		if (!$this->isSourceIndexable($document)) {
692
			return;
693
		}
694
695
		// on simple text file, elastic search+attachment pipeline can still detect language, useful ?
696
//		$document->setContent($file->getContent(), IndexDocument::NOT_ENCODED);
697
698
		// We try to avoid error with some base encoding of the document:
699
		$content = $file->getContent();
700
701
		$document->setContent(base64_encode($content), IndexDocument::ENCODED_BASE64);
702
	}
703
704
705
	/**
706
	 * @param FilesDocument $document
707
	 * @param File $file
708
	 *
709
	 * @throws NotPermittedException
710
	 */
711 View Code Duplication
	private function extractContentFromFilePDF(FilesDocument $document, File $file) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
712
		if ($this->parseMimeType($document->getMimeType()) !== self::MIMETYPE_PDF) {
713
			return;
714
		}
715
716
		$this->configService->setDocumentIndexOption($document, ConfigService::FILES_PDF);
717
		if (!$this->isSourceIndexable($document)) {
718
			return;
719
		}
720
721
		if ($this->configService->getAppValue(ConfigService::FILES_PDF) !== '1') {
722
			$document->setContent('');
723
724
			return;
725
		}
726
727
		$document->setContent(base64_encode($file->getContent()), IndexDocument::ENCODED_BASE64);
728
	}
729
730
731
	/**
732
	 * @param FilesDocument $document
733
	 * @param File $file
734
	 *
735
	 * @throws NotPermittedException
736
	 */
737 View Code Duplication
	private function extractContentFromFileOffice(FilesDocument $document, File $file) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
738
		if ($this->parseMimeType($document->getMimeType()) !== self::MIMETYPE_OFFICE) {
739
			return;
740
		}
741
742
		$this->configService->setDocumentIndexOption($document, ConfigService::FILES_OFFICE);
743
		if (!$this->isSourceIndexable($document)) {
744
			return;
745
		}
746
747
		if ($this->configService->getAppValue(ConfigService::FILES_OFFICE) !== '1') {
748
			$document->setContent('');
749
750
			return;
751
		}
752
753
		$document->setContent(base64_encode($file->getContent()), IndexDocument::ENCODED_BASE64);
754
	}
755
756
757
	/**
758
	 * @param FilesDocument $document
759
	 *
760
	 * @return bool
761
	 */
762
	private function isSourceIndexable(FilesDocument $document) {
763
		$this->configService->setDocumentIndexOption($document, $document->getSource());
764
		if ($this->configService->getAppValue($document->getSource()) !== '1') {
765
			$document->setContent('');
766
767
			return false;
768
		}
769
770
		return true;
771
	}
772
773
}
774