Issue Bug Closed

#101725Please execute FileDeletionAspect regardless if file is missing or not

Stefan Froemken 08/22/23, 08:30 updated 07/09/24, 15:19

Description

Hello,

I have a command to delete a lot of related files of a customers table.
The command should remove files older than 3 years.
In some cases the file is already deleted, but the sys_file_reference, sys_file_metadata and maybe the processed data is still available in DB.
While deleting such a record with missing file over official API I get following error message:

You are not allowed to delete the file "pictures/2019/hockey.jpg"

This message is not correct and it has nothing to do with insufficient permissions.

This is my TYPO3 API call:

$fileReference = $resourceFactory->getFileReferenceObject(
    $sysFileReferenceRecord['uid'],
    $sysFileReferenceRecord
);

$fileReference->getOriginalFile()->getStorage()->deleteFile($fileReference->getOriginalFile());

This is the problem IMO in TYPO3 core. ResourceStorage::checkFileActionPermission

// Check 5: Check the capabilities of the storage (and the driver)
if ($isWriteCheck && ($isMissing || !$this->isWritable())) {
    return false;
}

Just a missing file, is not a indication of missing permissions. IMO, we should split these two conditions into separate ones with different return values or throw an exception, if file is missing.

Reviews 2

History 47

  1. Stefan Froemken commented 08/22/23, 08:31

    As a short solution for other developers. You can instantiate the FileDeletionAspect on your own and call “removeFromRepository” with the file object as argument.

  2. Gerrit Code Review pushed patch set 1 for main to change 80613 status New Under Review 08/22/23, 08:54

  3. Stefan Froemken changed assigned to Stefan Froemken Complexity easy 08/22/23, 08:56

  4. Gerrit Code Review pushed patch set 2 for main to change 80613 09/19/23, 21:20

  5. Gerrit Code Review pushed patch set 1 for 12.4 to change 81067 09/20/23, 09:39

  6. Stefan Froemken commented and changed status Under Review Resolved done 0 % 100 % 09/20/23, 09:40

    Applied in changeset commit:c274c26b68290cf826cbcb8fc630d1dc42abe841.

  7. Benni Mack changed status Resolved Closed 07/09/24, 15:19