Project

General

Profile

Actions

Bug #78961

open

Extbase removing one file reference not working

Added by Deleted Account over 7 years ago. Updated 11 months ago.

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

0%

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

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)


Files

Backend.patch (1.68 KB) Backend.patch Deleted Account, 2016-12-12 17:49
Actions #1

Updated by Gerrit Code Review about 7 years 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

Actions #2

Updated by Gerrit Code Review about 6 years 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

Actions #3

Updated by Gerrit Code Review about 6 years 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

Actions #4

Updated by Susanne Moog about 5 years ago

  • Status changed from Under Review to Accepted

Patch has been abandoned.

Actions #5

Updated by Benni Mack 11 months ago

  • Sprint Focus set to Stabilization Sprint
Actions

Also available in: Atom PDF