7530d8247cebf9c45aefa578d153db3836ff023a
[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(
299 $queryBuilder->expr()->eq(
300 'uid',
301 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
302 )
303 )
304 ->execute()
305 ->fetch();
306 if (empty($recordData)) {
307 throw new \InvalidArgumentException('No collection found for given UID: "' . $uid . '"', 1314085992);
308 }
309 }
310 $collectionObject = $this->createCollectionObject($recordData);
311 $this->collectionInstances[$uid] = $collectionObject;
312 }
313 return $this->collectionInstances[$uid];
314 }
315
316 /**
317 * Creates a collection object.
318 *
319 * @param array $collectionData The database row of the sys_file_collection record.
320 * @return Collection\AbstractFileCollection
321 */
322 public function createCollectionObject(array $collectionData)
323 {
324 /** @var $registry Collection\FileCollectionRegistry */
325 $registry = GeneralUtility::makeInstance(Collection\FileCollectionRegistry::class);
326
327 /** @var \TYPO3\CMS\Core\Collection\AbstractRecordCollection $class */
328 $class = $registry->getFileCollectionClass($collectionData['type']);
329
330 return $class::create($collectionData);
331 }
332
333 /**
334 * Creates a storage object from a storage database row.
335 *
336 * @param array $storageRecord
337 * @param array $storageConfiguration Storage configuration (if given, this won't be extracted from the FlexForm value but the supplied array used instead)
338 * @return ResourceStorage
339 */
340 public function createStorageObject(array $storageRecord, array $storageConfiguration = null)
341 {
342 if (!$storageConfiguration) {
343 $storageConfiguration = $this->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
344 }
345 $driverType = $storageRecord['driver'];
346 $driverObject = $this->getDriverObject($driverType, $storageConfiguration);
347 return GeneralUtility::makeInstance(ResourceStorage::class, $driverObject, $storageRecord);
348 }
349
350 /**
351 * Creates a folder to directly access (a part of) a storage.
352 *
353 * @param ResourceStorage $storage The storage the folder belongs to
354 * @param string $identifier The path to the folder. Might also be a simple unique string, depending on the storage driver.
355 * @param string $name The name of the folder (e.g. the folder name)
356 * @return Folder
357 */
358 public function createFolderObject(ResourceStorage $storage, $identifier, $name)
359 {
360 return GeneralUtility::makeInstance(Folder::class, $storage, $identifier, $name);
361 }
362
363 /**
364 * Creates an instance of the file given UID. The $fileData can be supplied
365 * to increase performance.
366 *
367 * @param int $uid The uid of the file to instantiate.
368 * @param array $fileData The record row from database.
369 *
370 * @throws \InvalidArgumentException
371 * @throws Exception\FileDoesNotExistException
372 * @return File
373 */
374 public function getFileObject($uid, array $fileData = [])
375 {
376 if (!is_numeric($uid)) {
377 throw new \InvalidArgumentException('The UID of file has to be numeric. UID given: "' . $uid . '"', 1300096564);
378 }
379 if (!$this->fileInstances[$uid]) {
380 // Fetches data in case $fileData is empty
381 if (empty($fileData)) {
382 $fileData = $this->getFileIndexRepository()->findOneByUid($uid);
383 if ($fileData === false) {
384 throw new Exception\FileDoesNotExistException('No file found for given UID: ' . $uid, 1317178604);
385 }
386 }
387 $this->fileInstances[$uid] = $this->createFileObject($fileData);
388 }
389 return $this->fileInstances[$uid];
390 }
391
392 /**
393 * Gets an file object from an identifier [storage]:[fileId]
394 *
395 * @param string $identifier
396 * @return File
397 * @throws \InvalidArgumentException
398 */
399 public function getFileObjectFromCombinedIdentifier($identifier)
400 {
401 if (!isset($identifier) || !is_string($identifier) || $identifier === '') {
402 throw new \InvalidArgumentException('Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) . '" given.', 1401732564);
403 }
404 $parts = GeneralUtility::trimExplode(':', $identifier);
405 if (count($parts) === 2) {
406 $storageUid = $parts[0];
407 $fileIdentifier = $parts[1];
408 } else {
409 // We only got a path: Go into backwards compatibility mode and
410 // use virtual Storage (uid=0)
411 $storageUid = 0;
412 $fileIdentifier = $parts[0];
413 }
414
415 // please note that getStorageObject() might modify $fileIdentifier when
416 // auto-detecting the best-matching storage to use
417 return $this->getFileObjectByStorageAndIdentifier($storageUid, $fileIdentifier);
418 }
419
420 /**
421 * Gets an file object from storage by file identifier
422 * If the file is outside of the process folder it gets indexed and returned as file object afterwards
423 * If the file is within processing folder the file object will be directly returned
424 *
425 * @param int $storageUid
426 * @param string $fileIdentifier
427 * @return NULL|File|ProcessedFile
428 */
429 public function getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier)
430 {
431 $storage = $this->getStorageObject($storageUid, [], $fileIdentifier);
432 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
433 $fileData = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
434 if ($fileData === false) {
435 $fileObject = $this->getIndexer($storage)->createIndexEntry($fileIdentifier);
436 } else {
437 $fileObject = $this->getFileObject($fileData['uid'], $fileData);
438 }
439 } else {
440 $fileObject = $this->getProcessedFileRepository()->findByStorageAndIdentifier($storage, $fileIdentifier);
441 }
442
443 return $fileObject;
444 }
445
446 /**
447 * Bulk function, can be used for anything to get a file or folder
448 *
449 * 1. It's a UID
450 * 2. It's a combined identifier
451 * 3. It's just a path/filename (coming from the oldstyle/backwards compatibility)
452 *
453 * Files, previously laid on fileadmin/ or something, will be "mapped" to the storage the file is
454 * in now. Files like typo3temp/ or typo3conf/ will be moved to the first writable storage
455 * in its processing folder
456 *
457 * $input could be
458 * - "2:myfolder/myfile.jpg" (combined identifier)
459 * - "23" (file UID)
460 * - "uploads/myfile.png" (backwards-compatibility, storage "0")
461 * - "file:23"
462 *
463 * @param string $input
464 * @return File|Folder
465 */
466 public function retrieveFileOrFolderObject($input)
467 {
468 // Remove PATH_site because absolute paths under Windows systems contain ':'
469 // This is done in all considered sub functions anyway
470 $input = str_replace(PATH_site, '', $input);
471
472 if (GeneralUtility::isFirstPartOfStr($input, 'file:')) {
473 $input = substr($input, 5);
474 return $this->retrieveFileOrFolderObject($input);
475 } elseif (MathUtility::canBeInterpretedAsInteger($input)) {
476 return $this->getFileObject($input);
477 } elseif (strpos($input, ':') > 0) {
478 list($prefix) = explode(':', $input);
479 if (MathUtility::canBeInterpretedAsInteger($prefix)) {
480 // path or folder in a valid storageUID
481 return $this->getObjectFromCombinedIdentifier($input);
482 } elseif ($prefix == 'EXT') {
483 $input = GeneralUtility::getFileAbsFileName($input);
484 if (empty($input)) {
485 return null;
486 }
487
488 $input = PathUtility::getRelativePath(PATH_site, PathUtility::dirname($input)) . PathUtility::basename($input);
489 return $this->getFileObjectFromCombinedIdentifier($input);
490 } else {
491 return null;
492 }
493 } else {
494 // this is a backwards-compatible way to access "0-storage" files or folders
495 // eliminate double slashes, /./ and /../
496 $input = PathUtility::getCanonicalPath(ltrim($input, '/'));
497 if (@is_file(PATH_site . $input)) {
498 // only the local file
499 return $this->getFileObjectFromCombinedIdentifier($input);
500 } else {
501 // only the local path
502 return $this->getFolderObjectFromCombinedIdentifier($input);
503 }
504 }
505 }
506
507 /**
508 * Gets a folder object from an identifier [storage]:[fileId]
509 *
510 * @TODO check naming, inserted by SteffenR while working on filelist
511 * @param string $identifier
512 * @return Folder
513 */
514 public function getFolderObjectFromCombinedIdentifier($identifier)
515 {
516 $parts = GeneralUtility::trimExplode(':', $identifier);
517 if (count($parts) === 2) {
518 $storageUid = $parts[0];
519 $folderIdentifier = $parts[1];
520 } else {
521 // We only got a path: Go into backwards compatibility mode and
522 // use virtual Storage (uid=0)
523 $storageUid = 0;
524
525 // please note that getStorageObject() might modify $folderIdentifier when
526 // auto-detecting the best-matching storage to use
527 $folderIdentifier = $parts[0];
528 // make sure to not use an absolute path, and remove PATH_site if it is prepended
529 if (GeneralUtility::isFirstPartOfStr($folderIdentifier, PATH_site)) {
530 $folderIdentifier = PathUtility::stripPathSitePrefix($parts[0]);
531 }
532 }
533 return $this->getStorageObject($storageUid, [], $folderIdentifier)->getFolder($folderIdentifier);
534 }
535
536 /**
537 * Gets a storage object from a combined identifier
538 *
539 * @param string $identifier An identifier of the form [storage uid]:[object identifier]
540 * @return ResourceStorage
541 */
542 public function getStorageObjectFromCombinedIdentifier($identifier)
543 {
544 $parts = GeneralUtility::trimExplode(':', $identifier);
545 $storageUid = count($parts) === 2 ? $parts[0] : null;
546 return $this->getStorageObject($storageUid);
547 }
548
549 /**
550 * Gets a file or folder object.
551 *
552 * @param string $identifier
553 *
554 * @throws Exception\ResourceDoesNotExistException
555 * @return FileInterface|Folder
556 */
557 public function getObjectFromCombinedIdentifier($identifier)
558 {
559 list($storageId, $objectIdentifier) = GeneralUtility::trimExplode(':', $identifier);
560 $storage = $this->getStorageObject($storageId);
561 if ($storage->hasFile($objectIdentifier)) {
562 return $storage->getFile($objectIdentifier);
563 } elseif ($storage->hasFolder($objectIdentifier)) {
564 return $storage->getFolder($objectIdentifier);
565 } else {
566 throw new Exception\ResourceDoesNotExistException('Object with identifier "' . $identifier . '" does not exist in storage', 1329647780);
567 }
568 }
569
570 /**
571 * Creates a file object from an array of file data. Requires a database
572 * row to be fetched.
573 *
574 * @param array $fileData
575 * @param ResourceStorage $storage
576 * @return File
577 */
578 public function createFileObject(array $fileData, ResourceStorage $storage = null)
579 {
580 /** @var File $fileObject */
581 if (array_key_exists('storage', $fileData) && MathUtility::canBeInterpretedAsInteger($fileData['storage'])) {
582 $storageObject = $this->getStorageObject((int)$fileData['storage']);
583 } elseif ($storage !== null) {
584 $storageObject = $storage;
585 $fileData['storage'] = $storage->getUid();
586 } else {
587 throw new \RuntimeException('A file needs to reside in a Storage', 1381570997);
588 }
589 $fileObject = GeneralUtility::makeInstance(File::class, $fileData, $storageObject);
590 return $fileObject;
591 }
592
593 /**
594 * Creates an instance of a FileReference object. The $fileReferenceData can
595 * be supplied to increase performance.
596 *
597 * @param int $uid The uid of the file usage (sys_file_reference) to instantiate.
598 * @param array $fileReferenceData The record row from database.
599 * @param bool $raw Whether to get raw results without performing overlays
600 * @return FileReference
601 * @throws \InvalidArgumentException
602 * @throws Exception\ResourceDoesNotExistException
603 */
604 public function getFileReferenceObject($uid, array $fileReferenceData = [], $raw = false)
605 {
606 if (!is_numeric($uid)) {
607 throw new \InvalidArgumentException(
608 'The reference UID for the file (sys_file_reference) has to be numeric. UID given: "' . $uid . '"',
609 1300086584
610 );
611 }
612 if (!$this->fileReferenceInstances[$uid]) {
613 // Fetches data in case $fileData is empty
614 if (empty($fileReferenceData)) {
615 $fileReferenceData = $this->getFileReferenceData($uid, $raw);
616 if (!is_array($fileReferenceData)) {
617 throw new Exception\ResourceDoesNotExistException(
618 'No file reference (sys_file_reference) was found for given UID: "' . $uid . '"',
619 1317178794
620 );
621 }
622 }
623 $this->fileReferenceInstances[$uid] = $this->createFileReferenceObject($fileReferenceData);
624 }
625 return $this->fileReferenceInstances[$uid];
626 }
627
628 /**
629 * Creates a file usage object from an array of fileReference data
630 * from sys_file_reference table.
631 * Requires a database row to be already fetched and present.
632 *
633 * @param array $fileReferenceData
634 * @return FileReference
635 */
636 public function createFileReferenceObject(array $fileReferenceData)
637 {
638 /** @var FileReference $fileReferenceObject */
639 $fileReferenceObject = GeneralUtility::makeInstance(FileReference::class, $fileReferenceData);
640 return $fileReferenceObject;
641 }
642
643 /**
644 * Gets data for the given uid of the file reference record.
645 *
646 * @param int $uid The uid of the file usage (sys_file_reference) to be fetched
647 * @param bool $raw Whether to get raw results without performing overlays
648 * @return NULL|array
649 */
650 protected function getFileReferenceData($uid, $raw = false)
651 {
652 if (!$raw && TYPO3_MODE === 'BE') {
653 $fileReferenceData = BackendUtility::getRecordWSOL('sys_file_reference', $uid);
654 } elseif (!$raw && is_object($GLOBALS['TSFE'])) {
655 $fileReferenceData = $GLOBALS['TSFE']->sys_page->checkRecord('sys_file_reference', $uid);
656 } else {
657 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
658 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
659 $fileReferenceData = $queryBuilder->select('*')
660 ->from('sys_file_reference')
661 ->where(
662 $queryBuilder->expr()->eq(
663 'uid',
664 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
665 )
666 )
667 ->execute()
668 ->fetch();
669 }
670 return $fileReferenceData;
671 }
672
673 /**
674 * Returns an instance of the FileIndexRepository
675 *
676 * @return FileIndexRepository
677 */
678 protected function getFileIndexRepository()
679 {
680 return FileIndexRepository::getInstance();
681 }
682
683 /**
684 * Returns an instance of the ProcessedFileRepository
685 *
686 * @return ProcessedFileRepository
687 */
688 protected function getProcessedFileRepository()
689 {
690 return GeneralUtility::makeInstance(ProcessedFileRepository::class);
691 }
692
693 /**
694 * Returns an instance of the Indexer
695 *
696 * @param ResourceStorage $storage
697 * @return Index\Indexer
698 */
699 protected function getIndexer(ResourceStorage $storage)
700 {
701 return GeneralUtility::makeInstance(Index\Indexer::class, $storage);
702 }
703 }