Fix/file version event dispatch#12896
Conversation
aembler
left a comment
There was a problem hiding this comment.
getVersionToModify is not the appropriate place for this. The method's purpose is to get a new file version, but only if conditions allow it (e.g. the person working on the file is different that then previous version, or if the file version is older than a particular timestamp threshold.) The prefix and new file name do not belong here, and swapping method arguments isn't something we should do.
This should be done in a different way, without modifying this file and changing its arguments.
d0ff6c7 to
11f34af
Compare
|
I don't think it can be done without modifying getVersionToModify(), as duplicate() followed by approve() will always trigger on_file_version_approve with inconsistent data. Proposing this:
|
|
on_file_version_deleteon_file_version_approveIf I swap a file in the file manager, a new version is created in the
save()method ofconcrete/src/File/Import/FileImporter.php. In there thegetVersionToModify()executesduplicate()on the existing file version and thenapprove()on the duplicated file version (concrete/src/Entity/File/Version.php). Inapprove()the eventon_file_version_approveis fired. But unlessupdateFile()is called, the duplicated file has the old name and prefix but already the new file version id. This leads to a file version passed to the event with inconsistent data. So I movedupdateFile()togetVersionToModify()betweenduplicate()andapprove(). ForupdateFile()I need the new file name and the prefix. As the only call togetVersionToModify()which requests aforceCreateNewis from the file importer the impact of the change seemed reasonably small.