TYPO3 CMS  TYPO3_6-2
FileRepository.php
Go to the documentation of this file.
1 <?php
3 
20 
29 
37  protected $objectType = 'TYPO3\\CMS\\Core\\Resource\\File';
38 
45  protected $table = 'sys_file';
46 
50  protected $indexerService = NULL;
51 
57  public function findByUid($uid) {
59  return ResourceFactory::getInstance()->getFileObject($uid);
60  }
61 
62 
69  protected function getIndexerService() {
70  if ($this->indexerService === NULL) {
71  $this->indexerService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService');
72  }
73  return $this->indexerService;
74  }
75 
82  protected function createDomainObject(array $databaseRow) {
83  return $this->factory->getFileObject($databaseRow['uid'], $databaseRow);
84  }
85 
93  public function addToIndex(File $fileObject) {
95  return $this->getIndexerService()->indexFile($fileObject, FALSE);
96  }
97 
106  public function getFileIndexStatus(File $fileObject) {
108  $storageUid = $fileObject->getStorage()->getUid();
109  $identifier = $fileObject->getIdentifier();
110  $row = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storageUid, $identifier);
111  return is_array($row) ? $row['uid'] : FALSE;
112  }
113 
121  public function getFileIndexRecord(File $fileObject) {
123  return $this->getFileIndexRepository()->findOneByFileObject($fileObject);
124  }
125 
133  public function getFileIndexRecordsForFolder(Folder $folder) {
135  return $this->getFileIndexRepository()->findByFolder($folder);
136  }
137 
146  public function findBySha1Hash($hash) {
148  $resultRows = $this->getFileIndexRepository()->findByContentHash($hash);
149 
150  $objects = array();
151  foreach ($resultRows as $row) {
152  $objects[] = $this->createDomainObject($row);
153  }
154  return $objects;
155  }
156 
167  public function findByRelation($tableName, $fieldName, $uid) {
168  $itemList = array();
169  if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
170  throw new \InvalidArgumentException('Uid of related record has to be an integer.', 1316789798);
171  }
172  $referenceUids = NULL;
173  if ($this->getEnvironmentMode() === 'FE' && !empty($GLOBALS['TSFE']->sys_page)) {
175  $frontendController = $GLOBALS['TSFE'];
176  $references = $this->getDatabaseConnection()->exec_SELECTgetRows(
177  'uid',
178  'sys_file_reference',
179  'tablenames=' . $this->getDatabaseConnection()->fullQuoteStr($tableName, 'sys_file_reference') .
180  ' AND uid_foreign=' . (int)$uid .
181  ' AND fieldname=' . $this->getDatabaseConnection()->fullQuoteStr($fieldName, 'sys_file_reference')
182  . $frontendController->sys_page->enableFields('sys_file_reference', $frontendController->showHiddenRecords),
183  '',
184  'sorting_foreign',
185  '',
186  'uid'
187  );
188  if (!empty($references)) {
189  $referenceUids = array_keys($references);
190  }
191  } else {
193  $relationHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler');
194  $relationHandler->start(
195  '', 'sys_file_reference', '', $uid, $tableName,
196  \TYPO3\CMS\Backend\Utility\BackendUtility::getTcaFieldConfiguration($tableName, $fieldName)
197  );
198  if (!empty($relationHandler->tableArray['sys_file_reference'])) {
199  $referenceUids = $relationHandler->tableArray['sys_file_reference'];
200  }
201  }
202  if (!empty($referenceUids)) {
203  foreach ($referenceUids as $referenceUid) {
204  try {
205  // Just passing the reference uid, the factory is doing workspace
206  // overlays automatically depending on the current environment
207  $itemList[] = $this->factory->getFileReferenceObject($referenceUid);
208  } catch (ResourceDoesNotExistException $exception) {
209  // No handling, just omit the invalid reference uid
210  }
211  }
212  }
213  return $itemList;
214  }
215 
224  public function findFileReferenceByUid($uid) {
225  if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
226  throw new \InvalidArgumentException('uid of record has to be an integer.', 1316889798);
227  }
228  try {
229  $fileReferenceObject = $this->factory->getFileReferenceObject($uid);
230  } catch (\InvalidArgumentException $exception) {
231  $fileReferenceObject = FALSE;
232  }
233  return $fileReferenceObject;
234  }
235 
243  public function update($modifiedObject) {
245  if ($modifiedObject instanceof File) {
246  $this->getFileIndexRepository()->update($modifiedObject);
247  }
248  }
249 
257  protected function createFileReferenceObject(array $databaseRow) {
258  return $this->factory->getFileReferenceObject($databaseRow['uid'], $databaseRow);
259  }
260 
266  protected function getFileIndexRepository() {
268  }
269 
270 }
$uid
Definition: server.php:36
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]