[TASK] Cleanup and deprecate TYPO3_DB occurrences
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / ResourceFactory.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
20 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Utility\MathUtility;
23 use TYPO3\CMS\Core\Utility\PathUtility;
24 use TYPO3\CMS\Extbase\Service\FlexFormService;
25 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
26
27 // @todo implement constructor-level caching
28 /**
29 * Factory class for FAL objects
30 */
31 class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\SingletonInterface
32 {
33 /**
34 * Gets a singleton instance of this class.
35 *
36 * @return ResourceFactory
37 */
38 public static function getInstance()
39 {
40 return GeneralUtility::makeInstance(__CLASS__);
41 }
42
43 /**
44 * @var ResourceStorage[]
45 */
46 protected $storageInstances = [];
47
48 /**
49 * @var Collection\AbstractFileCollection[]
50 */
51 protected $collectionInstances = [];
52
53 /**
54 * @var File[]
55 */
56 protected $fileInstances = [];
57
58 /**
59 * @var FileReference[]
60 */
61 protected $fileReferenceInstances = [];
62
63 /**
64 * A list of the base paths of "local" driver storages. Used to make the detection of base paths easier.
65 *
66 * @var array
67 */
68 protected $localDriverStorageCache = null;
69
70 /**
71 * @var Dispatcher
72 */
73 protected $signalSlotDispatcher;
74
75 /**
76 * Inject signal slot dispatcher
77 *
78 * @param Dispatcher $signalSlotDispatcher an instance of the signal slot dispatcher
79 */
80 public function __construct(Dispatcher $signalSlotDispatcher = null)
81 {
82 $this->signalSlotDispatcher = $signalSlotDispatcher ?: GeneralUtility::makeInstance(Dispatcher::class);
83 }
84
85 /**
86 * Creates a driver object for a specified storage object.
87 *
88 * @param string $driverIdentificationString The driver class (or identifier) to use.
89 * @param array $driverConfiguration The configuration of the storage
90 * @return Driver\DriverInterface
91 * @throws \InvalidArgumentException
92 */
93 public function getDriverObject($driverIdentificationString, array $driverConfiguration)
94 {
95 /** @var $driverRegistry Driver\DriverRegistry */
96 $driverRegistry = GeneralUtility::makeInstance(Driver\DriverRegistry::class);
97 $driverClass = $driverRegistry->getDriverClass($driverIdentificationString);
98 $driverObject = GeneralUtility::makeInstance($driverClass, $driverConfiguration);
99 return $driverObject;
100 }
101
102 /**
103 * Returns the Default Storage
104 *
105 * The Default Storage is considered to be the replacement for the fileadmin/ construct.
106 * It is automatically created with the setting fileadminDir from install tool.
107 * getDefaultStorage->getDefaultFolder() will get you fileadmin/user_upload/ in a standard
108 * TYPO3 installation.
109 *
110 * @return null|ResourceStorage
111 */
112 public function getDefaultStorage()
113 {
114 /** @var $storageRepository StorageRepository */
115 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
116
117 $allStorages = $storageRepository->findAll();
118 foreach ($allStorages as $storage) {
119 if ($storage->isDefault()) {
120 return $storage;
121 }
122 }
123 return null;
124 }
125 /**
126 * Creates an instance of the storage from given UID. The $recordData can
127 * be supplied to increase performance.
128 *
129 * @param int $uid The uid of the storage to instantiate.
130 * @param array $recordData The record row from database.
131 * @param string $fileIdentifier Identifier for a file. Used for auto-detection of a storage, but only if $uid === 0 (Local default storage) is used
132 *
133 * @throws \InvalidArgumentException
134 * @return ResourceStorage
135 */
136 public function getStorageObject($uid, array $recordData = [], &$fileIdentifier = null)
137 {
138 if (!is_numeric($uid)) {
139 throw new \InvalidArgumentException('The UID of storage has to be numeric. UID given: "' . $uid . '"', 1314085991);
140 }
141 $uid = (int)$uid;
142 if ($uid === 0 && $fileIdentifier !== null) {
143 $uid = $this->findBestMatchingStorageByLocalPath($fileIdentifier);
144 }
145 if (!$this->storageInstances[$uid]) {
146 $storageConfiguration = null;
147 $storageObject = null;
148 list($_, $uid, $recordData, $fileIdentifier) = $this->emitPreProcessStorageSignal($uid, $recordData, $fileIdentifier);
149 // If the built-in storage with UID=0 is requested:
150 if ($uid === 0) {
151 $recordData = [
152 'uid' => 0,
153 'pid' => 0,
154 'name' => 'Fallback Storage',
155 'description' => 'Internal storage, mounting the main TYPO3_site directory.',
156 'driver' => 'Local',
157 'processingfolder' => 'typo3temp/assets/_processed_/',
158 // legacy code
159 'configuration' => '',
160 'is_online' => true,
161 'is_browsable' => true,
162 'is_public' => true,
163 'is_writable' => true,
164 'is_default' => false,
165 ];
166 $storageConfiguration = [
167 'basePath' => '/',
168 'pathType' => 'relative'
169 ];
170 } elseif (count($recordData) === 0 || (int)$recordData['uid'] !== $uid) {
171 /** @var $storageRepository StorageRepository */
172 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
173 /** @var $storage ResourceStorage */
174 $storageObject = $storageRepository->findByUid($uid);
175 }
176 if (!$storageObject instanceof ResourceStorage) {
177 $storageObject = $this->createStorageObject($recordData, $storageConfiguration);
178 }
179 $this->emitPostProcessStorageSignal($storageObject);
180 $this->storageInstances[$uid] = $storageObject;
181 }
182 return $this->storageInstances[$uid];
183 }
184
185 /**
186 * Emits a signal before a resource storage was initialized
187 *
188 * @param int $uid
189 * @param array $recordData
190 * @param string $fileIdentifier
191 * @return mixed
192 */
193 protected function emitPreProcessStorageSignal($uid, $recordData, $fileIdentifier)
194 {
195 return $this->signalSlotDispatcher->dispatch(\TYPO3\CMS\Core\Resource\ResourceFactory::class, self::SIGNAL_PreProcessStorage, [$this, $uid, $recordData, $fileIdentifier]);
196 }
197
198 /**
199 * Emits a signal after a resource storage was initialized
200 *
201 * @param ResourceStorage $storageObject
202 */
203 protected function emitPostProcessStorageSignal(ResourceStorage $storageObject)
204 {
205 $this->signalSlotDispatcher->dispatch(self::class, self::SIGNAL_PostProcessStorage, [$this, $storageObject]);
206 }
207
208 /**
209 * Checks whether a file resides within a real storage in local file system.
210 * If no match is found, uid 0 is returned which is a fallback storage pointing to PATH_site.
211 *
212 * The file identifier is adapted accordingly to match the new storage's base path.
213 *
214 * @param string $localPath
215 *
216 * @return int
217 */
218 protected function findBestMatchingStorageByLocalPath(&$localPath)
219 {
220 if ($this->localDriverStorageCache === null) {
221 $this->initializeLocalStorageCache();
222 }
223
224 $bestMatchStorageUid = 0;
225 $bestMatchLength = 0;
226 foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
227 $matchLength = strlen(PathUtility::getCommonPrefix([$basePath, $localPath]));
228 $basePathLength = strlen($basePath);
229
230 if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
231 $bestMatchStorageUid = (int)$storageUid;
232 $bestMatchLength = $matchLength;
233 }
234 }
235 if ($bestMatchStorageUid !== 0) {
236 $localPath = substr($localPath, $bestMatchLength);
237 }
238 return $bestMatchStorageUid;
239 }
240
241 /**
242 * Creates an array mapping all uids to the basePath of storages using the "local" driver.
243 *
244 * @return void
245 */
246 protected function initializeLocalStorageCache()
247 {
248 /** @var $storageRepository StorageRepository */
249 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
250 /** @var $storageObjects ResourceStorage[] */
251 $storageObjects = $storageRepository->findByStorageType('Local');
252
253 $storageCache = [];
254 foreach ($storageObjects as $localStorage) {
255 $configuration = $localStorage->getConfiguration();
256 $storageCache[$localStorage->getUid()] = $configuration['basePath'];
257 }
258 $this->localDriverStorageCache = $storageCache;
259 }
260
261 /**
262 * Converts a flexform data string to a flat array with key value pairs
263 *
264 * @param string $flexFormData
265 * @return array Array with key => value pairs of the field data in the FlexForm
266 */
267 public function convertFlexFormDataToConfigurationArray($flexFormData)
268 {
269 $configuration = [];
270 if ($flexFormData) {
271 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
272 $configuration = $flexFormService->convertFlexFormContentToArray($flexFormData);
273 }
274 return $configuration;
275 }
276
277 /**
278 * Creates an instance of the collection from given UID. The $recordData can be supplied to increase performance.
279 *
280 * @param int $uid The uid of the collection to instantiate.
281 * @param array $recordData The record row from database.
282 *
283 * @throws \InvalidArgumentException
284 * @return Collection\AbstractFileCollection
285 */
286 public function getCollectionObject($uid, array $recordData = [])
287 {
288 if (!is_numeric($uid)) {
289 throw new \InvalidArgumentException('The UID of collection has to be numeric. UID given: "' . $uid . '"', 1314085999);
290 }
291 if (!$this->collectionInstances[$uid]) {
292 // Get mount data if not already supplied as argument to this function
293 if (empty($recordData) || $recordData['uid'] !== $uid) {
294 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_collection');
295 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
296 $recordData = $queryBuilder->select('*')
297 ->from('sys_file_collection')
298 ->where($queryBuilder->expr()->eq('uid', (int)$uid))
299 ->execute()
300 ->fetch();
301 if (empty($recordData)) {
302 throw new \InvalidArgumentException('No collection found for given UID: "' . $uid . '"', 1314085992);
303 }
304 }
305 $collectionObject = $this->createCollectionObject($recordData);
306 $this->collectionInstances[$uid] = $collectionObject;
307 }
308 return $this->collectionInstances[$uid];
309 }
310
311 /**
312 * Creates a collection object.
313 *
314 * @param array $collectionData The database row of the sys_file_collection record.
315 * @return Collection\AbstractFileCollection
316 */
317 public function createCollectionObject(array $collectionData)
318 {
319 /** @var $registry Collection\FileCollectionRegistry */
320 $registry = GeneralUtility::makeInstance(Collection\FileCollectionRegistry::class);
321
322 /** @var \TYPO3\CMS\Core\Collection\AbstractRecordCollection $class */
323 $class = $registry->getFileCollectionClass($collectionData['type']);
324
325 return $class::create($collectionData);
326 }
327
328 /**
329 * Creates a storage object from a storage database row.
330 *
331 * @param array $storageRecord
332 * @param array $storageConfiguration Storage configuration (if given, this won't be extracted from the FlexForm value but the supplied array used instead)
333 * @return ResourceStorage
334 */
335 public function createStorageObject(array $storageRecord, array $storageConfiguration = null)
336 {
337 if (!$storageConfiguration) {
338 $storageConfiguration = $this->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
339 }
340 $driverType = $storageRecord['driver'];
341 $driverObject = $this->getDriverObject($driverType, $storageConfiguration);
342 return GeneralUtility::makeInstance(ResourceStorage::class, $driverObject, $storageRecord);
343 }
344
345 /**
346 * Creates a folder to directly access (a part of) a storage.
347 *
348 * @param ResourceStorage $storage The storage the folder belongs to
349 * @param string $identifier The path to the folder. Might also be a simple unique string, depending on the storage driver.
350 * @param string $name The name of the folder (e.g. the folder name)
351 * @return Folder
352 */
353 public function createFolderObject(ResourceStorage $storage, $identifier, $name)
354 {
355 return GeneralUtility::makeInstance(Folder::class, $storage, $identifier, $name);
356 }
357
358 /**
359 * Creates an instance of the file given UID. The $fileData can be supplied
360 * to increase performance.
361 *
362 * @param int $uid The uid of the file to instantiate.
363 * @param array $fileData The record row from database.
364 *
365 * @throws \InvalidArgumentException
366 * @throws Exception\FileDoesNotExistException
367 * @return File
368 */
369 public function getFileObject($uid, array $fileData = [])
370 {
371 if (!is_numeric($uid)) {
372 throw new \InvalidArgumentException('The UID of file has to be numeric. UID given: "' . $uid . '"', 1300096564);
373 }
374 if (!$this->fileInstances[$uid]) {
375 // Fetches data in case $fileData is empty
376 if (empty($fileData)) {
377 $fileData = $this->getFileIndexRepository()->findOneByUid($uid);
378 if ($fileData === false) {
379 throw new Exception\FileDoesNotExistException('No file found for given UID: ' . $uid, 1317178604);
380 }
381 }
382 $this->fileInstances[$uid] = $this->createFileObject($fileData);
383 }
384 return $this->fileInstances[$uid];
385 }
386
387 /**
388 * Gets an file object from an identifier [storage]:[fileId]
389 *
390 * @param string $identifier
391 * @return File
392 * @throws \InvalidArgumentException
393 */
394 public function getFileObjectFromCombinedIdentifier($identifier)
395 {
396 if (!isset($identifier) || !is_string($identifier) || $identifier === '') {
397 throw new \InvalidArgumentException('Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) . '" given.', 1401732564);
398 }
399 $parts = GeneralUtility::trimExplode(':', $identifier);
400 if (count($parts) === 2) {
401 $storageUid = $parts[0];
402 $fileIdentifier = $parts[1];
403 } else {
404 // We only got a path: Go into backwards compatibility mode and
405 // use virtual Storage (uid=0)
406 $storageUid = 0;
407 $fileIdentifier = $parts[0];
408 }
409
410 // please note that getStorageObject() might modify $fileIdentifier when
411 // auto-detecting the best-matching storage to use
412 return $this->getFileObjectByStorageAndIdentifier($storageUid, $fileIdentifier);
413 }
414
415 /**
416 * Gets an file object from storage by file identifier
417 * If the file is outside of the process folder it gets indexed and returned as file object afterwards
418 * If the file is within processing folder the file object will be directly returned
419 *
420 * @param int $storageUid
421 * @param string $fileIdentifier
422 * @return NULL|File|ProcessedFile
423 */
424 public function getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier)
425 {
426 $storage = $this->getStorageObject($storageUid, [], $fileIdentifier);
427 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
428 $fileData = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
429 if ($fileData === false) {
430 $fileObject = $this->getIndexer($storage)->createIndexEntry($fileIdentifier);
431 } else {
432 $fileObject = $this->getFileObject($fileData['uid'], $fileData);
433 }
434 } else {
435 $fileObject = $this->getProcessedFileRepository()->findByStorageAndIdentifier($storage, $fileIdentifier);
436 }
437
438 return $fileObject;
439 }
440
441 /**
442 * Bulk function, can be used for anything to get a file or folder
443 *
444 * 1. It's a UID
445 * 2. It's a combined identifier
446 * 3. It's just a path/filename (coming from the oldstyle/backwards compatibility)
447 *
448 * Files, previously laid on fileadmin/ or something, will be "mapped" to the storage the file is
449 * in now. Files like typo3temp/ or typo3conf/ will be moved to the first writable storage
450 * in its processing folder
451 *
452 * $input could be
453 * - "2:myfolder/myfile.jpg" (combined identifier)
454 * - "23" (file UID)
455 * - "uploads/myfile.png" (backwards-compatibility, storage "0")
456 * - "file:23"
457 *
458 * @param string $input
459 * @return File|Folder
460 */
461 public function retrieveFileOrFolderObject($input)
462 {
463 // Remove PATH_site because absolute paths under Windows systems contain ':'
464 // This is done in all considered sub functions anyway
465 $input = str_replace(PATH_site, '', $input);
466
467 if (GeneralUtility::isFirstPartOfStr($input, 'file:')) {
468 $input = substr($input, 5);
469 return $this->retrieveFileOrFolderObject($input);
470 } elseif (MathUtility::canBeInterpretedAsInteger($input)) {
471 return $this->getFileObject($input);
472 } elseif (strpos($input, ':') > 0) {
473 list($prefix) = explode(':', $input);
474 if (MathUtility::canBeInterpretedAsInteger($prefix)) {
475 // path or folder in a valid storageUID
476 return $this->getObjectFromCombinedIdentifier($input);
477 } elseif ($prefix == 'EXT') {
478 $input = GeneralUtility::getFileAbsFileName($input);
479 if (empty($input)) {
480 return null;
481 }
482
483 $input = PathUtility::getRelativePath(PATH_site, PathUtility::dirname($input)) . PathUtility::basename($input);
484 return $this->getFileObjectFromCombinedIdentifier($input);
485 } else {
486 return null;
487 }
488 } else {
489 // this is a backwards-compatible way to access "0-storage" files or folders
490 // eliminate double slashes, /./ and /../
491 $input = PathUtility::getCanonicalPath(ltrim($input, '/'));
492 if (@is_file(PATH_site . $input)) {
493 // only the local file
494 return $this->getFileObjectFromCombinedIdentifier($input);
495 } else {
496 // only the local path
497 return $this->getFolderObjectFromCombinedIdentifier($input);
498 }
499 }
500 }
501
502 /**
503 * Gets a folder object from an identifier [storage]:[fileId]
504 *
505 * @TODO check naming, inserted by SteffenR while working on filelist
506 * @param string $identifier
507 * @return Folder
508 */
509 public function getFolderObjectFromCombinedIdentifier($identifier)
510 {
511 $parts = GeneralUtility::trimExplode(':', $identifier);
512 if (count($parts) === 2) {
513 $storageUid = $parts[0];
514 $folderIdentifier = $parts[1];
515 } else {
516 // We only got a path: Go into backwards compatibility mode and
517 // use virtual Storage (uid=0)
518 $storageUid = 0;
519
520 // please note that getStorageObject() might modify $folderIdentifier when
521 // auto-detecting the best-matching storage to use
522 $folderIdentifier = $parts[0];
523 // make sure to not use an absolute path, and remove PATH_site if it is prepended
524 if (GeneralUtility::isFirstPartOfStr($folderIdentifier, PATH_site)) {
525 $folderIdentifier = PathUtility::stripPathSitePrefix($parts[0]);
526 }
527 }
528 return $this->getStorageObject($storageUid, [], $folderIdentifier)->getFolder($folderIdentifier);
529 }
530
531 /**
532 * Gets a storage object from a combined identifier
533 *
534 * @param string $identifier An identifier of the form [storage uid]:[object identifier]
535 * @return ResourceStorage
536 */
537 public function getStorageObjectFromCombinedIdentifier($identifier)
538 {
539 $parts = GeneralUtility::trimExplode(':', $identifier);
540 $storageUid = count($parts) === 2 ? $parts[0] : null;
541 return $this->getStorageObject($storageUid);
542 }
543
544 /**
545 * Gets a file or folder object.
546 *
547 * @param string $identifier
548 *
549 * @throws Exception\ResourceDoesNotExistException
550 * @return FileInterface|Folder
551 */
552 public function getObjectFromCombinedIdentifier($identifier)
553 {
554 list($storageId, $objectIdentifier) = GeneralUtility::trimExplode(':', $identifier);
555 $storage = $this->getStorageObject($storageId);
556 if ($storage->hasFile($objectIdentifier)) {
557 return $storage->getFile($objectIdentifier);
558 } elseif ($storage->hasFolder($objectIdentifier)) {
559 return $storage->getFolder($objectIdentifier);
560 } else {
561 throw new Exception\ResourceDoesNotExistException('Object with identifier "' . $identifier . '" does not exist in storage', 1329647780);
562 }
563 }
564
565 /**
566 * Creates a file object from an array of file data. Requires a database
567 * row to be fetched.
568 *
569 * @param array $fileData
570 * @param ResourceStorage $storage
571 * @return File
572 */
573 public function createFileObject(array $fileData, ResourceStorage $storage = null)
574 {
575 /** @var File $fileObject */
576 if (array_key_exists('storage', $fileData) && MathUtility::canBeInterpretedAsInteger($fileData['storage'])) {
577 $storageObject = $this->getStorageObject((int)$fileData['storage']);
578 } elseif ($storage !== null) {
579 $storageObject = $storage;
580 $fileData['storage'] = $storage->getUid();
581 } else {
582 throw new \RuntimeException('A file needs to reside in a Storage', 1381570997);
583 }
584 $fileObject = GeneralUtility::makeInstance(File::class, $fileData, $storageObject);
585 return $fileObject;
586 }
587
588 /**
589 * Creates an instance of a FileReference object. The $fileReferenceData can
590 * be supplied to increase performance.
591 *
592 * @param int $uid The uid of the file usage (sys_file_reference) to instantiate.
593 * @param array $fileReferenceData The record row from database.
594 * @param bool $raw Whether to get raw results without performing overlays
595 * @return FileReference
596 * @throws \InvalidArgumentException
597 * @throws Exception\ResourceDoesNotExistException
598 */
599 public function getFileReferenceObject($uid, array $fileReferenceData = [], $raw = false)
600 {
601 if (!is_numeric($uid)) {
602 throw new \InvalidArgumentException(
603 'The reference UID for the file (sys_file_reference) has to be numeric. UID given: "' . $uid . '"',
604 1300086584
605 );
606 }
607 if (!$this->fileReferenceInstances[$uid]) {
608 // Fetches data in case $fileData is empty
609 if (empty($fileReferenceData)) {
610 $fileReferenceData = $this->getFileReferenceData($uid, $raw);
611 if (!is_array($fileReferenceData)) {
612 throw new Exception\ResourceDoesNotExistException(
613 'No file reference (sys_file_reference) was found for given UID: "' . $uid . '"',
614 1317178794
615 );
616 }
617 }
618 $this->fileReferenceInstances[$uid] = $this->createFileReferenceObject($fileReferenceData);
619 }
620 return $this->fileReferenceInstances[$uid];
621 }
622
623 /**
624 * Creates a file usage object from an array of fileReference data
625 * from sys_file_reference table.
626 * Requires a database row to be already fetched and present.
627 *
628 * @param array $fileReferenceData
629 * @return FileReference
630 */
631 public function createFileReferenceObject(array $fileReferenceData)
632 {
633 /** @var FileReference $fileReferenceObject */
634 $fileReferenceObject = GeneralUtility::makeInstance(FileReference::class, $fileReferenceData);
635 return $fileReferenceObject;
636 }
637
638 /**
639 * Gets data for the given uid of the file reference record.
640 *
641 * @param int $uid The uid of the file usage (sys_file_reference) to be fetched
642 * @param bool $raw Whether to get raw results without performing overlays
643 * @return NULL|array
644 */
645 protected function getFileReferenceData($uid, $raw = false)
646 {
647 if (!$raw && TYPO3_MODE === 'BE') {
648 $fileReferenceData = BackendUtility::getRecordWSOL('sys_file_reference', $uid);
649 } elseif (!$raw && is_object($GLOBALS['TSFE'])) {
650 $fileReferenceData = $GLOBALS['TSFE']->sys_page->checkRecord('sys_file_reference', $uid);
651 } else {
652 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
653 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
654 $fileReferenceData = $queryBuilder->select('*')
655 ->from('sys_file_reference')
656 ->where($queryBuilder->expr()->eq('uid', (int)$uid))
657 ->execute()
658 ->fetch();
659 }
660 return $fileReferenceData;
661 }
662
663 /**
664 * Returns an instance of the FileIndexRepository
665 *
666 * @return FileIndexRepository
667 */
668 protected function getFileIndexRepository()
669 {
670 return FileIndexRepository::getInstance();
671 }
672
673 /**
674 * Returns an instance of the ProcessedFileRepository
675 *
676 * @return ProcessedFileRepository
677 */
678 protected function getProcessedFileRepository()
679 {
680 return GeneralUtility::makeInstance(ProcessedFileRepository::class);
681 }
682
683 /**
684 * Returns an instance of the Indexer
685 *
686 * @param ResourceStorage $storage
687 * @return Index\Indexer
688 */
689 protected function getIndexer(ResourceStorage $storage)
690 {
691 return GeneralUtility::makeInstance(Index\Indexer::class, $storage);
692 }
693 }