Bug #78961
openExtbase removing one file reference not working
0%
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
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review almost 7 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
Updated by Gerrit Code Review over 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
Updated by Susanne Moog over 5 years ago
- Status changed from Under Review to Accepted
Patch has been abandoned.