Actions
Bug #78961
openExtbase removing one file reference not working
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
Actions