phpcontrollerfrontenddatamappertypo3-9.x

TYPO3 9.5 delete sys_file_reference Image


I have extension where user can upload/edit/delete images in frontend. Everything works fine, but I am not able to delete images. I have following code, but seems not working:

$data = array();
$data['sys_file_reference'][123]['delete'] = 1;

/** @var DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
$dataHandler->start($data, array());
$dataHandler->process_datamap();

What is correct datamapper for deleting fal images?


Solution

  • I solved it by using 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();