Review 9.5 Merged

62974[BUGFIX] Prevent PHP type error and stale language cache

Andreas Kienast CR +2 V +2 Easy +2 −11 updated 05/14/20, 07:29

Commit message

PHP is raising an error if $pageId cannot be resolved to an
integer value as required by method signature.

Additionally, an internally cached array is built based on a
dynamic value but the internal cache is not keyed by this
value or flushed when the value changes.

This patch:

* Casts an unresolved page ID to integer zero.
* Removes the internal cache of languages since the array
  now depends entirely on a unique input value, $pageId.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Alexander Schnitzler +1
    • Frank Nägler +1
  • Verified V +2 Done
    • Benni Mack +2
    • Alexander Schnitzler +1
    • TYPO3com +1 CI

Issues 2

Files 1

Review log 1517

  1. Andreas Kienast commented on patch set 1 01/21/20, 09:13

    Cherry Picked from branch master.
  2. TYPO3com voted on patch set 1 V +1 01/21/20, 09:24 Completed build in 10m 48s on Tue, 21 Jan, 09:24 AM Test Summary: 73979 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC95-1898

  3. Oliver Klee commented on patch set 1 01/21/20, 11:36

    GridDataService.php:596

    According to the signature of getSystemLanguageValue, $pageId already is an integer. So either we need to change the @param annotation here to int|string (or int|null or whatever other type is passed), or we should move the type cast to the caller(s) instead. Otherwise, when this method here gets type annotations, we will get type errors again. What do you think?
  4. Andreas Kienast commented on patch set 1 01/21/20, 11:57

    GridDataService.php:596 Reply

    We can do that, but not in this patch please since it's just a backport.
  5. Oliver Klee voted on patch set 1 CR +1 01/21/20, 12:14

  6. Benni Mack commented on patch set 1 01/31/20, 17:00

    GridDataService.php:596 Reply

    I think for the backport this is fine, we had a similar issue recently around that area where "" depending on the RDBMs did not show anything in the workspaces module because of that.
  7. Oliver Hader commented on patch set 1 CR -1 02/02/20, 08:59

    GridDataService.php:618 Unresolved

    That leads to fetching sys_language records for each workspace record that is not contained in a page-branch that has a Site configuration (which is different to the v10 behavior). Instead local cache could be extended to contain $pageId partition which has been introduced first in https://review.typo3.org/c/Packages/TYPO3.CMS/+/61571 (9.5). e.g. $this->systemLanguages[$pageId] = ...
  8. Benni Mack commented on patch set 1 04/30/20, 07:40

    I'll abandon this change now - there hasn't been any movement in the last months on this topic, and no votes. And it works in TYPO3 v10. If somebody finds people working on that, this change can be restored later-on.
  9. Benni Mack abandoned the change 04/30/20, 07:40

    no movement
  10. Benni Mack restored the change 05/05/20, 13:49

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

  12. TYPO3com voted on patch set 2 V +1 05/05/20, 14:02 Completed build in 11m 56s on Tue, 5 May, 02:02 PM Test Summary: 74834 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC95-566

  13. Benni Mack voted on patch set 2 CR +1 05/05/20, 14:59

  14. Frank Nägler voted on patch set 2 CR +1 05/11/20, 07:11

  15. Alexander Schnitzler commented on patch set 2 V +1 CR +1 05/13/20, 17:30

    GridDataService.php:596 Reply Unresolved

    Since I am working on type safety via phpstan as well at the moment I'd like to say that I would not change the method signature to a union type because of two reasons: - Accepting anything other than int does not make sense here as we need $pageId to be an int as soon as it is passed into getSystemLanguages - Widening the types makes it hard to have a type safe method unless version 11.0 will have PHP 8.0 as minimum dependency (which allows native union types) I think the solution chosen here is exactly right. phpstan will tell me if the doc block is actually safe or not and I will create a patch accordingly. And as soon as we are able to automatically add type declarations we can also automatically remove superfluous castings.
  16. Benni Mack voted on patch set 2 V +2 CR +2 05/14/20, 07:29

  17. Benni Mack merged patch set 3 05/14/20, 07:29