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