TYPO3 CMS  TYPO3_7-6
FileRepository.php
Go to the documentation of this file.
1 <?php
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 
20 
26 {
34  protected $objectType = \TYPO3\CMS\Core\Resource\File::class;
35 
42  protected $table = 'sys_file';
43 
50  protected function createDomainObject(array $databaseRow)
51  {
52  return $this->factory->getFileObject($databaseRow['uid'], $databaseRow);
53  }
54 
65  public function findByRelation($tableName, $fieldName, $uid)
66  {
67  $itemList = [];
68  if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
69  throw new \InvalidArgumentException('UID of related record has to be an integer. UID given: "' . $uid . '"', 1316789798);
70  }
71  $referenceUids = null;
72  if ($this->getEnvironmentMode() === 'FE' && !empty($GLOBALS['TSFE']->sys_page)) {
74  $frontendController = $GLOBALS['TSFE'];
75  $references = $this->getDatabaseConnection()->exec_SELECTgetRows(
76  'uid',
77  'sys_file_reference',
78  'tablenames=' . $this->getDatabaseConnection()->fullQuoteStr($tableName, 'sys_file_reference') .
79  ' AND uid_foreign=' . (int)$uid .
80  ' AND fieldname=' . $this->getDatabaseConnection()->fullQuoteStr($fieldName, 'sys_file_reference')
81  . $frontendController->sys_page->enableFields('sys_file_reference', $frontendController->showHiddenRecords),
82  '',
83  'sorting_foreign',
84  '',
85  'uid'
86  );
87  if (!empty($references)) {
88  $referenceUids = array_keys($references);
89  }
90  } else {
92  $relationHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
93  $relationHandler->start(
94  '', 'sys_file_reference', '', $uid, $tableName,
95  \TYPO3\CMS\Backend\Utility\BackendUtility::getTcaFieldConfiguration($tableName, $fieldName)
96  );
97  if (!empty($relationHandler->tableArray['sys_file_reference'])) {
98  $referenceUids = $relationHandler->tableArray['sys_file_reference'];
99  }
100  }
101  if (!empty($referenceUids)) {
102  foreach ($referenceUids as $referenceUid) {
103  try {
104  // Just passing the reference uid, the factory is doing workspace
105  // overlays automatically depending on the current environment
106  $itemList[] = $this->factory->getFileReferenceObject($referenceUid);
107  } catch (ResourceDoesNotExistException $exception) {
108  // No handling, just omit the invalid reference uid
109  }
110  }
111  }
112  return $itemList;
113  }
114 
123  public function findFileReferenceByUid($uid)
124  {
125  if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
126  throw new \InvalidArgumentException('The UID of record has to be an integer. UID given: "' . $uid . '"', 1316889798);
127  }
128  try {
129  $fileReferenceObject = $this->factory->getFileReferenceObject($uid);
130  } catch (\InvalidArgumentException $exception) {
131  $fileReferenceObject = false;
132  }
133  return $fileReferenceObject;
134  }
135 
143  public function searchByName(Folder $folder, $fileName)
144  {
146  $fileFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
147 
148  $folders = $folder->getStorage()->getFoldersInFolder($folder, 0, 0, true, true);
149  $folders[$folder->getIdentifier()] = $folder;
150 
151  $fileRecords = $this->getFileIndexRepository()->findByFolders($folders, false, $fileName);
152 
153  $files = [];
154  foreach ($fileRecords as $fileRecord) {
155  try {
156  $files[] = $fileFactory->getFileObject($fileRecord['uid'], $fileRecord);
157  } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $ignoredException) {
158  continue;
159  }
160  }
161 
162  return $files;
163  }
164 
170  protected function getFileIndexRepository()
171  {
173  }
174 }
$uid
Definition: server.php:38
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']