Review main Merged

84609[TASK] Migrate CommandUtility from exec() to Symfony Process

Mathias Bolt Lesniak CR +2 V +2 Normal +99 −66 updated 07/12/24, 12:35

Commit message

Replaces execution of PHP's `exec()` function with Symfony's Process
component within `TYPO3\CMS\Core\Utility\CommandUtility` while
maintaining compatibility with the previous implementation.

Migrating to Symfony Process implements a more widely compatible
solution to command execution, simplifying installation in more limited
environments.

Because it is recommended best practice when using Symfony Process, this
patch also adds the possibility to supply an array to the `$command`
argument `TYPO3\CMS\Core\Utility\CommandUtility::exec()`.

This patch also adds `symfony/process` as a direct dependency of
`typo3/cms-core`.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Benni Mack +2
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 3045

Show 1220 earlier messages
  1. Mathias Bolt Lesniak uploaded patch set 1 06/11/24, 11:00

  2. core-ci voted on patch set 1 V -1 06/11/24, 11:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59164

  3. Mathias Bolt Lesniak uploaded patch set 2 V -1 06/11/24, 11:40

  4. core-ci voted on patch set 2 V -1 06/11/24, 11:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59172

  5. Andreas Kienast commented on patch set 2 06/11/24, 11:51

    You have to require symfony/process for the main composer.json as well. However, this creates a mix of Symfony 7.0 and 7.1 right now, let's clean this up at first.
  6. Andreas Kienast commented on patch set 2 06/11/24, 11:53

  7. Rozbeh Chiryai Sharahi uploaded patch set 3 V -1 06/11/24, 12:14

  8. core-ci voted on patch set 3 V -1 06/11/24, 12:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59180

  9. Rozbeh Chiryai Sharahi uploaded patch set 4 V -1 06/11/24, 12:25

  10. core-ci voted on patch set 4 V +1 06/11/24, 12:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59184

  11. Rozbeh Chiryai Sharahi uploaded patch set 5 V +1 06/11/24, 12:33

  12. core-ci voted on patch set 5 V +1 06/11/24, 12:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59185

  13. Rozbeh Chiryai Sharahi uploaded patch set 6 V +1 06/11/24, 12:40

  14. core-ci voted on patch set 6 V +1 06/11/24, 12:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59186

  15. Andreas Kienast uploaded patch set 7 V +1 06/11/24, 13:24

  16. Andreas Kienast uploaded patch set 8 06/11/24, 13:25

  17. core-ci voted on patch set 7 V -1 06/11/24, 13:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59193

  18. core-ci voted on patch set 8 V +1 06/11/24, 13:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59194

  19. Georg Ringer voted on patch set 8 CR +1 V +1 06/11/24, 19:55

  20. Simon Schaufelberger uploaded patch set 9 CR +1 V +1 06/17/24, 19:59

  1. Simon Schaufelberger voted on patch set 9 CR +1 V +1 06/17/24, 20:00

  2. core-ci voted on patch set 9 V +1 06/17/24, 20:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59751

  3. Mathias Bolt Lesniak uploaded patch set 10 CR +1 V +1 06/24/24, 08:55

  4. core-ci voted on patch set 10 V -1 06/24/24, 08:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60162

  5. Andreas Kienast uploaded patch set 11 V -1 06/24/24, 09:08

  6. core-ci voted on patch set 11 V +1 06/24/24, 09:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60164

  7. Benni Mack commented on patch set 11 06/25/24, 06:06

    CommandUtility.php:100

    this seemed so easy :) But now, this method returns "false", on typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php line 321 because "git rev-parse --short HEAD" returns return code 128 (thus, this method returns false). We might just keep the bw/compat and then add a todo to introduce a new wrapper method or the like to call it "CommandUtility::process" which is much more strict with the return type?
  8. Benni Mack voted on patch set 11 CR -1 06/25/24, 06:32

  9. Mathias Bolt Lesniak commented on patch set 11 06/25/24, 07:40

    CommandUtility.php:100 Reply

    Looks like we're missing some test case coverage here. ;-) I'll have a look at possible implementations that better reproduce the expected output. I'm thinking that the ultimate goal would be to replace every method in CommandUtility with direct Process implementations, so CommandUtility::process would be the backwards compatible version that later becomes deprecated. This because I'm interested in ways to avoid the "exec() doesn't exist" errors for new installations on limited hosts. Thoughts?
  10. Benni Mack commented on patch set 11 06/25/24, 11:13

    CommandUtility.php:100 Reply

    tbh, returning "false" does not seem to be used in conjunction with the return code: https://www.php.net/manual/en/function.exec.php (see PHP 8.0 change) and https://github.com/php/php-src/blob/master/ext/standard/exec.c#L199C2-L199C14 I'd skip this here
  11. Mathias Bolt Lesniak uploaded patch set 12 CR -1 V +1 07/06/24, 08:38

  12. core-ci voted on patch set 12 V +1 07/06/24, 08:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61087

  13. Mathias Bolt Lesniak uploaded patch set 13 V +1 07/06/24, 12:43

  14. core-ci voted on patch set 13 V +1 07/06/24, 12:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61097

  15. Mathias Bolt Lesniak commented on patch set 13 07/06/24, 14:01

    CommandUtility.php:100 Reply

    @benni@typo3.org After reading the exec() command's C code and the code of contributing functions, it looks like the command returns false on failure. Where C functions normally return -1. This looks like the same behavior as the RuntimeException of Symfony Process. Thus, I have implemented a catch for Process's RuntimeExceptions as the reason for returning false. I think this makes sense. What do you think.
  16. Benni Mack commented on patch set 13 07/12/24, 05:58

    CommandUtility.php:100 Reply

    I think that's really good!
  17. Mathias Bolt Lesniak uploaded patch set 14 V +1 07/12/24, 06:26

  18. Mathias Bolt Lesniak commented on patch set 14 07/12/24, 06:28

    CommandUtility.php:100 Reply

    Great! I pushed a new patchset to fix the merge conflict.
  19. core-ci voted on patch set 14 V +1 07/12/24, 06:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61450

  20. Benni Mack commented on patch set 14 CR +1 V +1 07/12/24, 11:39

    works for me now. thank you!
  21. Simon Schaufelberger uploaded patch set 15 CR +1 V +1 07/12/24, 11:49

  22. Simon Schaufelberger commented on patch set 15 CR +1 V +1 07/12/24, 11:50

    Reply

    Resolved merge conflict. Please revote.
  23. core-ci voted on patch set 15 V +1 07/12/24, 11:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61481

  24. Benni Mack voted on patch set 15 CR +2 V +2 07/12/24, 12:35

  25. Benni Mack merged patch set 16 07/12/24, 12:35