TYPO3 9.5 删除 sys_file_reference 图片

TYPO3 9.5 delete sys_file_reference Image

我有扩展程序,用户可以在前端使用 upload/edit/delete 图片。一切正常,但我无法删除图像。我有以下代码,但似乎不起作用:

    $data['sys_file_reference'][123]['delete'] = 1;
    // Get an instance of the DataHandler and process the data
    /** @var DataHandler $dataHandler */
    $dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler');
    $dataHandler->start($data, array());
    $dataHandler->process_datamap();

删除错误图像的正确数据映射器是什么?

我用queryBuilder解决了

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
$queryBuilder
->update('sys_file_reference')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($dat->getLogo()->getUid()))
)
->set('deleted', '1')
->execute();

使用 start() 方法的第二个参数 ($cmd) 应该可以解决问题。

$cmd['sys_file_reference'][$uid]['delete'] = 1;
/** @var DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler:class);
$dataHandler->start([], $cmd);
$dataHandler->admin = true; // Use this line with caution!
$dataHandler->process_cmdmap();