Project

General

Profile

Actions

Bug #99403

open

Reference count in the file list could be incorrect

Added by Dmitry Dulepov over 1 year ago. Updated about 1 year ago.

Status:
On Hold
Priority:
Should have
Assignee:
-
Category:
File Abstraction Layer (FAL)
Target version:
-
Start date:
2022-12-21
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

TYPO3\CMS\Filelist::getFileReferenceCount() uses sys_ref_index to find amount of references to the file but this number is not always correct. For example, creating or deleting file references in frontend usually does not update sys_ref_index. This causes not only wrong numbers in the UI but also prohibits file deletion if the file is unused but reference index is not updated.

It would be more practical to count records in sys_file_reference rather than in sys_refindex. Therefore I propose to change the above mentioned method to only count how many entries with uid_local = $file->getUid() in sys_file_reference, not in sys_refindex.

Basically:

    /**
     * Counts how often the given file is referenced. This is done by
     * looking up the file in the "sys_refindex" table, while excluding
     * sys_file_metadata relations as these are no such references.
     */
    protected function getFileReferenceCount2(File $file): int
    {
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
        return (int)$queryBuilder
            ->count('*')
            ->from('sys_file_reference')
            ->where(
                $queryBuilder->expr()->eq(
                    'uid_local',
                    $queryBuilder->createNamedParameter($file->getUid(), Connection::PARAM_INT)
                )
            )
            ->executeQuery()
            ->fetchOne();
    }
Actions

Also available in: Atom PDF