1

In my extension I read Folders and Images. But in the result always the meta data from sys_file_metadata is missing and I found nothing how to load it.

The database entries are there so the file is indexed and everything seems to be ok. BE is working fine.

Here some code:

Controller-Action:

$storageId = 1;
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
$storage = $storageRepository->findByUid($storageId);
$singleFile = $storage->getFile('/user_upload/my_file.pdf');
$singleFile = true;
$this->view->assign('singleFile', $singleFile);

If I do a f:debug it showns me this:

Extbase Variable Dump

TYPO3\CMS\Core\Resource\Fileprototypeobject
   metaDataLoaded => FALSE
   metaDataProperties => array(empty)
   indexingInProgress => FALSE
   updatedProperties => array(empty)
   indexerService => NULL
   properties => array(15 items)
   storage => TYPO3\CMS\Core\Resource\ResourceStorageprototypeobject
   identifier => '/user_upload/my_file.pdf' (24 chars)
   name => 'my_file.pdf' (11 chars)
   deleted => FALSE

As you can see there is a field metaDataProperties and metaDataLoaded, so its not loaded.

Does anybody know how to load it?

Tobias Gaertner
  • 1,155
  • 12
  • 30

2 Answers2

6

You can try to use this in fluid

{singleFile.properties.description}, {singleFile.properties.title} or {singleFile.properties.alternative}

or this one to get all Properties

$singleFile->_getMetaData()

this can also be helpfull $singleFile->getProperty('description')

Mario Naether
  • 1,122
  • 11
  • 22
  • perfect! works great. I'm wondering why the data is not included in the debug output and you don't have to load them explicit inside controller action like you do with collections. – Tobias Gaertner Nov 05 '15 at 07:17
  • Documentation for that would be nice... :-) – Tobias Gaertner Nov 05 '15 at 07:18
  • In BE its possible to add releations to other files (maybe this field comes from "filemetadata" core-extension) – Tobias Gaertner Nov 11 '15 at 08:18
  • I had installed the "filemetadata" Extension and TYPO3 6.2.15.There a no releation field to other Files. What is the name of this field? – Mario Naether Nov 11 '15 at 10:37
  • The field is called related_files. I found a TCA-overwrite in the "media" extension. I can access file.properties.related_files, but this filed contains the count of related files. Not the ids and not the objects. So I'm wondering if it is possible to get the related files (objects) somehow. Thankful for any hint :-) – Tobias Gaertner Nov 11 '15 at 12:31
  • Ok I did now an SELECT Query and joined all needed tabels. I post the code in an other answer, but Marios answer stays the accepted one for it answers the main question. – Tobias Gaertner Nov 11 '15 at 14:21
  • sowas könnte vielleicht auch helfen/funktioniere... {relatedFile} oder {file.properties.related_files.0} – Mario Naether Nov 11 '15 at 14:23
  • Thanks Mario for all your help and ideas!! I tried that before, but its also not working. I posted a (bit complicated but working) solution below. Your answer is still the accepted one because it answers the main question. – Tobias Gaertner Nov 11 '15 at 14:36
0

For reading related files (provided by the "media" extension) one solution would be the following code. This is for complete the problem in the comments above.

private function getRelatedFiles($fileId) {
    $items = array();
    $resSub = 'SELECT sys_file_reference.uid_local '.
        ' FROM sys_file_reference LEFT JOIN sys_file_metadata ON sys_file_reference.uid_foreign = sys_file_metadata.uid LEFT JOIN sys_file ON sys_file.uid = sys_file_metadata.file '.
        ' WHERE sys_file.uid = '.$fileId;

    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_file.identifier',
        'sys_file',
        'sys_file.uid IN ('.$resSub.')'
    );

    while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)){
        $items[] = $this->getDocumentStorage()->getFile($row['identifier']);
    }

    return $items;
}
Tobias Gaertner
  • 1,155
  • 12
  • 30