Review main Merged

64478[TASK] Add new file object to AfterFileCopiedEvent

Benni Mack CR +2 V +2 Easy +27 −2 updated 05/22/20, 19:57

Commit message

The PSR-14 event "AfterFileCopiedEvent" in FAL now also
has the possibility to return the newly created file
and the identifier.

Review

  • Code review CR +2 Done
    • Susi Moog +2
    • Daniel Goerz +1
  • Verified V +2 Done
    • Susi Moog +2
    • Daniel Goerz +1
    • TYPO3com +1 CI

Issues 1

Files 3

Review log 1418

  1. Benni Mack uploaded patch set 1 05/12/20, 20:01

  2. TYPO3com voted on patch set 1 V +1 05/12/20, 20:13 Completed build in 12m 00s on Tue, 12 May, 08:13 PM Test Summary: 73708 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3346

  3. Daniel Goerz voted on patch set 1 V +1 CR +1 05/12/20, 20:55

  4. Susi Moog voted on patch set 1 CR +1 05/13/20, 05:13

  5. Benni Mack updated the commit message in patch set 2 05/13/20, 05:28

  6. TYPO3com voted on patch set 2 V -1 05/13/20, 05:42 Completed build in 13m 35s on Wed, 13 May, 05:42 AM Test Summary: 73077 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3360

  7. TYPO3com voted on patch set 2 V +1 05/13/20, 06:33 Completed build in 1h 18m 08s on Wed, 13 May, 06:33 AM Test Summary: 73708 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3360

  8. Daniel Goerz voted on patch set 2 V +1 CR +1 05/13/20, 07:50

  9. Benjamin Franzke commented on patch set 2 CR -1 05/13/20, 08:56

    AfterFileCopiedEvent.php:52

    Isn't $newFileIdentifier redundant with $newFile->getProperty('name')? To be fair, I actually wonder why there is nothing like FileInterface::getName(), while FileInterface::getNameWithoutExtension() and FileInterface:getExtension() exist.

    AfterFileCopiedEvent.php:52

    Why is it AbstractFile and not FileInterface? Why is it nullable? getFileObjectByStorageAndIdentifier states via docblock that it may return null, yes, but ProcessedFile::copyFile declares that it always returns a FileInterface, not null. Therefore the event could use `FileInterface $newFile` as well, no? I mean, if there is really no new file (null), the event should probably not be dispatched(?)
  10. Daniel Goerz commented on patch set 2 05/13/20, 09:26

    AfterFileCopiedEvent.php:52 Reply Unresolved

    I think it is completely fine for this particular event to offer this particular shortcut for convenience. As an API it makes sense.

    AfterFileCopiedEvent.php:52 Reply

    I thought about this as well. And came to the conclusion that we continue with the stated return type from getFileObjectByStorageAndIdentifier() in the event. I am not completely certain under what conditions we can get null back here tbh. If we are sure that his never happens we can assume an AbstractFile or FileInterface. But if there is a setup where null is actually returned here we will run into an Exception then, which is not desirable. Not dispatching the event in case of null is not an option IMO because the new file was not part of the whole event until know so the event should not depend on it suddenly (we have the legacy slot replacement in place as a listener, that also does not know anything about the new file). So to be safe it seems a valid way to allow null in the event and make listeners check for an actual object. We could add a hasNewFile(): bool API to the Event, too. Switching to FileInterface should be fine, though.
  11. Daniel Goerz commented on patch set 2 05/21/20, 17:11

    AfterFileCopiedEvent.php:52 Reply

    Had another look, and getFileObjectByStorageAndIdentifier() returns File|ProcessedFile|null. File and ProcessedFile both extend AbstractFile (which implements FileInterface). Going with AbstractFile offers a little bit more API than going with FileInterface, so I actually would leave the patch as is, although switching to the Interface would be OK as well, I guess. Could you please reconsider blocking it, because I need this for another patch.
  12. Susi Moog commented on patch set 2 05/22/20, 19:09

    AfterFileCopiedEvent.php:52 Reply

    The null case as far as I got that is there when copying a file within the processing folder for whatever reason which has not been processed. That's a weird case and would also lead to subsequent errors if I rely on the API of ResourceStorage::copyFile as documented. For the same reason (consistency) I'd use the interface here (as that is the documented type of the $fileObject) - and probably throw an(other) exception in case null is returned for the processed file thing.
  13. Susi Moog commented on patch set 2 05/22/20, 19:30

    AfterFileCopiedEvent.php:52 Reply

    On the other hand: this issue is about adding info to the event mirroring current behaviour. Handling the null case in a different way should / could be done in another patch if necessary (and yes, I can reproduce getting null from that method). For now I'd go for: ?FileInterface...
  14. Daniel Goerz uploaded patch set 3 05/22/20, 19:36

  15. TYPO3com voted on patch set 3 V +1 05/22/20, 19:48 Completed build in 12m 08s on Fri, 22 May, 07:48 PM Test Summary: 73804 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3496

  16. Daniel Goerz voted on patch set 3 V +1 CR +1 05/22/20, 19:51

  17. Susi Moog commented on patch set 3 V +2 CR +2 05/22/20, 19:57

    AfterFileCopiedEvent.php:52 Reply Unresolved

    For completeness sake on skipping the event in the null case: there _is_ in fact a copy of the file created, we just don't get a new file object in this case (so a file was copied, but no file object was created as the file is stored in _processed_). I think the current version is an acceptable compromise for this event so I'll merge this now.
  18. Susi Moog merged patch set 4 05/22/20, 19:57