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