Project

General

Profile

Actions

Bug #67091

closed

FAL returns wrong data when reading files in collection

Added by André Spindler almost 9 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
File Abstraction Layer (FAL)
Target version:
-
Start date:
2015-05-21
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

To fetch files in sys_file_collection, I use the following code (TYPO3 is 6.2.12 with php 5.3.10-1ubuntu3.18):

/** @var \TYPO3\CMS\Core\Resource\FileCollectionRepository $fileCollectionRepository */
$fileCollectionRepository = GeneralUtility::makeInstance('\\TYPO3\\CMS\\Core\\Resource\\FileCollectionRepository');

$collection = $fileCollectionRepository->findByUid($collectionUid);
$collection->loadContents();

$collectionFiles = $collection->getItems();
if (count($collectionFiles)) {
    /** @var \TYPO3\CMS\Core\Resource\File $singleFile */
    foreach ($collectionFiles as $singleFile) {
        $files[] = $singleFile->getUid();
    }
}

Intention is to receive the uids of all the files in one or more file collections.

Now I have two file collections. The first "collection-1" is of type "folder", the second "collection-2" is of type "static".

When my code is processed for "collection-1", I get all files in the directory and in "$singleFile" I have the file object. And I receive the Uid of the file.
Thats working all fine as it should.

Now I do this again for "collection-2", and here I get wrong results. The items of the collection I get are declared to be files, but they are a mixture of file and reference. To point this out - type declaration is "\TYPO3\CMS\Core\Resource\File" (in method "\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::getItems()"). But when I fetch the uid (of the file I think), I receive the uid of the reference record between the file and the collection. This goeas alongside when getting all properties of this object and retreiving the uid from the returned array.

So this is a misbehaviour when retreiving the items: In the returned array of items, some have the correct uid of the file, others have the uid of the relation to the file. That's wrong.

Actions #1

Updated by Stephan Großberndt almost 9 years ago

  • Subject changed from FAL returns wrong data whe nreading files in collection to FAL returns wrong data when reading files in collection
Actions #2

Updated by Frans Saris almost 9 years ago

  • Status changed from New to Needs Feedback

So the issue here is that the StaticFileCollection collects/returns FileReference objects instead of File objects, correct?

The problem is that with the FileReferences the editor can "extend" the file info. So removing this layer wouldn't be desirable. I think we should adjust the @PHPdoc of the AbstracFileCollection.

gr. Frans

Actions #3

Updated by André Spindler almost 9 years ago

Yes, I now have checked that in the Core.
\TYPO3\CMS\Core\Resource\Collection\StaticFileCollection::loadContents() calls \TYPO3\CMS\Core\Resource\FileRepository::findByRelation() which returns references.

Values in the reference should overwrite the ones in the file, that's right. But this should be limited to the fields an editor can enter. It doesn't make sense to overwrite the internal fields like tstamp, crdate and so on from the file with the values of the reference. And also the uid. Perhaps the most useful solution is to add the mixed values in plain, but also add ALL values from file and reference, but prefixed with "__file_" and "__rel_" or something else. Like localization does with some values.

At the moment I hve build up a workaround by reading all properties and extract the value from index "file". That contains in both cases (static and folder based) the uid of the file.

Actions #4

Updated by Frans Saris almost 9 years ago

but that's why you get an object back and not a plain array with values so you can check if it is a File of FileReference.

gr. Frans

Actions #5

Updated by André Spindler almost 9 years ago

Thats right. Is there any documentation about this?

What I mean: In my case I looked into the Core to find out what "getItems()" return. I found this:

/**
 * Gets the current available items.
 *
 * @return array
 */
public function getItems() {
    $itemArray = array();
    /** @var $item \TYPO3\CMS\Core\Resource\File */
    foreach ($this->storage as $item) {
        $itemArray[] = $item;
    }
    return $itemArray;
}

So i assumed that will be File objects - in any case. I stopped here and did no deeper search if there is returned sometimes something different.
So this type hint should be changed to FileInterface - that's the most common part between Files and FileReferences. And there should also be a comment in the core to mention this differnt return types.
With this modifications all information is given about what you get from here.

Actions #6

Updated by Alexander Opitz over 8 years ago

  • Status changed from Needs Feedback to New
Actions #7

Updated by Gerrit Code Review about 5 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59892

Actions #8

Updated by Gerrit Code Review about 5 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59896

Actions #9

Updated by Anonymous about 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #10

Updated by Benni Mack almost 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF