Review main Abandoned

71525[TASK] Replace file and folder actions with enumerations

Nikita Hovratov CR 0 V 0 Hard +374 −130 updated 11/04/21, 17:13

Commit message

There are tons of magic strings of file and folder
actions for FAL. In order to reduce the amount of
them, two new enumerations have been added:
FileAction and FolderAction. These two enumerations
hold all possible actions for their type
respectively.

Some part of the code could be extracted into the
methods "isReadAction" and "isWriteAction".

With this, passing invalid action names is now
deprecated.

In addition an interface has been added for File
and Folder to ensure polymorphic calls of the
checkActionPermission method.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 26

Show 6 more files

Review log 1113

  1. Nikita Hovratov uploaded patch set 1 10/10/21, 12:36

  2. core-ci voted on patch set 1 V +1 10/10/21, 12:57 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/17892

  3. Mathias Brodala commented on patch set 1 10/11/21, 07:28

    ResourceStorage.php:722

    Technically we must catch a possible "InvalidEnumerationValueException" here. In the first step we could turn this into an early return and deprecation message. In a second step (with v12) the exception could be allowed to bubble. Finally we could we require FileAction (and FolderAction) as type instead of string for $action altogether.
  4. Nikita Hovratov uploaded patch set 2 10/11/21, 10:48

  5. Nikita Hovratov commented on patch set 2 10/11/21, 10:54

    ResourceStorage.php:722 Reply

    Thanks for the review! I extended the code as you suggested. Internally now only enumeration objects are passed. In v12 strings can then be deprecated.
  6. Mathias Brodala commented on patch set 2 10/11/21, 10:59

    ResourceAction.php:34

    This should be dropped again and the constants be duplicated in FileAction/FolderAction. We do not need any de-duplication here since these constants belong to each enumeration separately. It's just coincidence that they have the same name/value.
  7. core-ci voted on patch set 2 V +1 10/11/21, 11:03 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/17908

  8. Nikita Hovratov commented on patch set 2 10/11/21, 11:18

    ResourceAction.php:34 Reply Unresolved

    I did this, because we have some instances, where File and Folder are called polymorphicly (the method "checkActionPermission"). This is just for convenience. Or else we would need to add a if ($fileOrFolder instanceof Folder) check everywhere (60 or so occurrences). So in fact it's not even a coincidence I would argue. Just the intersection of actions, that can be performed on both Files and Folders.
  9. Benni Mack commented on patch set 2 10/11/21, 14:53

    Hey Nikita. does this actually fix a bug? If not, I suggest we wait with this change, go with PHP 8.1 "Enum" built-in?
  10. Nikita Hovratov commented on patch set 2 10/11/21, 17:42

    Reply

    No, it's just housekeeping. Wow, enums in PHP 8.1 look very great! Do you think we will raise the minimum PHP version to 8.1 in TYPO3 v12 as well? Either way, let's wait with that until branching off.
  11. Oliver Hader commented on patch set 2 10/12/21, 09:02

    ElementInformationController.php:212

    Why are we still using `Enumeration::cast` instead of directly using the constant `ResourceAction::READ`?
  12. Nikita Hovratov commented on patch set 2 10/12/21, 09:05

    ElementInformationController.php:212 Reply Unresolved

    This should ensure, a valid object is passed as parameter instead of a string.
  13. Nikita Hovratov abandoned the change 11/04/21, 17:13

    Not so important. Can be picked up later in v12 maybe.