TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FileRepository.php
Go to the documentation of this file.
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 
26 
32 {
40  protected $objectType = File::class;
41 
48  protected $table = 'sys_file';
49 
56  protected function createDomainObject(array $databaseRow)
57  {
58  return $this->factory->getFileObject($databaseRow['uid'], $databaseRow);
59  }
60 
71  public function findByRelation($tableName, $fieldName, $uid)
72  {
73  $itemList = [];
75  throw new \InvalidArgumentException(
76  'UID of related record has to be an integer. UID given: "' . $uid . '"',
77  1316789798
78  );
79  }
80  $referenceUids = [];
81  if ($this->getEnvironmentMode() === 'FE' && !empty($GLOBALS['TSFE']->sys_page)) {
82  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
83  ->getQueryBuilderForTable('sys_file_reference');
84 
85  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
86  if ($GLOBALS['TSFE']->sys_page->showHiddenRecords) {
87  $queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
88  }
89 
90  $res = $queryBuilder
91  ->select('uid')
92  ->from('sys_file_reference')
93  ->where(
94  $queryBuilder->expr()->eq(
95  'uid_foreign',
96  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
97  ),
98  $queryBuilder->expr()->eq(
99  'tablenames',
100  $queryBuilder->createNamedParameter($tableName, \PDO::PARAM_STR)
101  ),
102  $queryBuilder->expr()->eq(
103  'fieldname',
104  $queryBuilder->createNamedParameter($fieldName, \PDO::PARAM_STR)
105  )
106  )
107  ->orderBy('sorting_foreign')
108  ->execute();
109 
110  while ($row = $res->fetch()) {
111  $referenceUids[] = $row['uid'];
112  }
113  } else {
115  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
116  $relationHandler->start(
117  '', 'sys_file_reference', '', $uid, $tableName,
118  BackendUtility::getTcaFieldConfiguration($tableName, $fieldName)
119  );
120  if (!empty($relationHandler->tableArray['sys_file_reference'])) {
121  $referenceUids = $relationHandler->tableArray['sys_file_reference'];
122  }
123  }
124  if (!empty($referenceUids)) {
125  foreach ($referenceUids as $referenceUid) {
126  try {
127  // Just passing the reference uid, the factory is doing workspace
128  // overlays automatically depending on the current environment
129  $itemList[] = $this->factory->getFileReferenceObject($referenceUid);
130  } catch (ResourceDoesNotExistException $exception) {
131  // No handling, just omit the invalid reference uid
132  }
133  }
134  }
135 
136  return $itemList;
137  }
138 
147  public function findFileReferenceByUid($uid)
148  {
150  throw new \InvalidArgumentException('The UID of record has to be an integer. UID given: "' . $uid . '"', 1316889798);
151  }
152  try {
153  $fileReferenceObject = $this->factory->getFileReferenceObject($uid);
154  } catch (\InvalidArgumentException $exception) {
155  $fileReferenceObject = false;
156  }
157  return $fileReferenceObject;
158  }
159 
167  public function searchByName(Folder $folder, $fileName)
168  {
170  $fileFactory = GeneralUtility::makeInstance(ResourceFactory::class);
171 
172  $folders = $folder->getStorage()->getFoldersInFolder($folder, 0, 0, true, true);
173  $folders[$folder->getIdentifier()] = $folder;
174 
175  $fileRecords = $this->getFileIndexRepository()->findByFolders($folders, false, $fileName);
176 
177  $files = [];
178  foreach ($fileRecords as $fileRecord) {
179  try {
180  $files[] = $fileFactory->getFileObject($fileRecord['uid'], $fileRecord);
181  } catch (Exception\FileDoesNotExistException $ignoredException) {
182  continue;
183  }
184  }
185 
186  return $files;
187  }
188 
194  protected function getFileIndexRepository()
195  {
197  }
198 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)