Issue with 9101 update

Created on 2 January 2024, 12 months ago

Problem/Motivation

After an updb command, I have this error message :

>  [notice] Update started: ui_patterns_views_style_update_9101
>  [warning] Undefined array key "options" UiPatternsViewsStyleUpdater.php:51
>  [error]  Drupal\ui_patterns_views_style\Service\UiPatternsViewsStyleUpdater::update9101PrepareNewSettings(): Argument #1 ($styleSettings) must be of type array, null given, called in /project/app/modules/contrib/ui_patterns_views_style/src/Service/UiPatternsViewsStyleUpdater.php on line 51 
>  [error]  Update failed: ui_patterns_views_style_update_9101

After add tests for line 51, i have other error in line 72

Undefined array key "line_folder" UiPatternsViewsStyleUpdater.php:72

Proposed resolution

Add some array_key_exists tests into the if in line 50 to prevent access to a nonexistent array key. And this for all key array access.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Nicoc
  • Status changed to Needs review 12 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work 12 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +        if (array_key_exists('display_options', $display) &&
    +          array_key_exists('style', $display['display_options']) &&
    +          array_key_exists('options', $display['display_options']['style']) &&
    +          !isset($display['display_options']['style']['options']['pattern_variant'])) {
    +                $displays[$key]['display_options']['style']['options'] = $this->update9101PrepareNewSettings($display['display_options']['style']['options']);
    

    isset($display['display_options']['style']['options']) is sufficient. There is no need to call array_key_exists() three times.

    +    if(array_key_exists($pattern, $styleSettings['variants'])) {
    +      $styleSettings['pattern_variant'] = $styleSettings['variants'][$pattern];
    +      unset($styleSettings['variants']);
    +    }
    

    Notice that array_key_exists() returns TRUE when the key is set to NULL. It is better to use isset(), which returns FALSE when the key is NULL.

Production build 0.71.5 2024