Bug #78961

Extbase removing one file reference not working

Added by Ruben Schmidmeister almost 2 years ago. Updated 9 months ago.

Status:
Under Review
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2016-12-12
Due date:
% Done:

0%

TYPO3 Version:
8
PHP Version:
7.0
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:

Description

After setting a property pointing to a file reference to NULL and persisting, the file_reference still exists in the database and is back when refreshing the page.
(Even with the @cascade remove annotation, the reference isn't deleted.)

// Relevant SQL

CREATE TABLE tx_experiments_domain_model_book (

  -- ...

  cover_image int(11) DEFAULT '0' NOT NULL,

  -- ...

)

// Relevant TCA

// ...

'cover_image' => [
    'label' => 'Cover Image',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('cover_image', [
        'maxitems' => 1,
        'minitems' => 0,
        'appearance' => [
            'createNewRelationLinkTitle' => 'LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.asset_references.addFileReference'
        ],
        'foreign_match_fields' => [
            'fieldname' => 'cover_image',
            'tablenames' => 'tx_experiments_domain_model_book',
            'table_local' => 'sys_file',
        ],
        'foreign_types' => $GLOBALS['TCA']['tt_content']['columns']['image']['config']['foreign_types']
    ], $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'])
],

// ...

// Model

class Book extends AbstractEntity
{
    // ...

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     * @cascade remove
     */
    protected $coverImage;

    // ...
}

// Controller

class BookController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
    // ...

    protected function updateAction(Book $book)
    {
        $model->setCoverImage(null);

        $this->bookRepository->update($book);

        // ...
    }

    // ...
}

After taking a look at TYPO3\CMS\Extbase\Persistence\Generic\Backend it was clear to me why it does not work:
In the persistObject method there's no clause to check for properties that have been changed from a DomainObject to null and have a @cascade remove annotation.

I have created a patch that would add the missing behaviour. (See Backend.patch)

Backend.patch View (1.68 KB) Ruben Schmidmeister, 2016-12-12 17:49

History

#1 Updated by Gerrit Code Review over 1 year 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/52067

#2 Updated by Gerrit Code Review 10 months ago

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

#3 Updated by Gerrit Code Review 9 months ago

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

Also available in: Atom PDF