When using Panels caching with a pane that adds JavaScript settings that include numeric keys, this data can be corrupted before being stored in the cache. The pane is displayed correctly on the first view when the cache is generated, but is displayed incorrectly on subsequent views when using cached data.

An example of settings data that would be corrupted due to the numeric keys (0, 1, 2) is:

array(
  'totals' => array(
    'funding' => array(
      0 => '1000000',
      1 => '2000000',
      2 => '3000000',
    ),
  ),
)

This settings data is stored in cache as:

array(
  'totals' => array(
    'funding' => array(
      0 => '1000000',
      1 => '2000000',
      2 => '3000000',
      3 => '1000000',
      4 => '2000000',
      5 => '3000000',
    ),
  ),
)

I believe this issue was introduced by the patch committed for #1762290: PHP 5.4 Issue with array_diff_assoc in plugins.inc, and is due to the use of drupal_array_merge_deep(), which does not merge items with matching keys if the keys are numeric, and rather adds them as new items. See: http://cgit.drupalcode.org/panels/tree/includes/plugins.inc?h=7.x-3.x#n193

On further review, it appears that this use of drupal_array_merge_deep() is superfluous, as the arguments provided should be identical in all cases.

Comments

arithmetric’s picture

Status: Active » Needs review
StatusFileSize
new671 bytes

Attached is a patch that removes this use of drupal_array_merge_deep() and uses one of the identical values being merged instead. This avoids the corruption that occurs when the JavaScript settings arrays are merged.

fago’s picture

Status: Needs review » Reviewed & tested by the community

After updating Panels on a site I ran into this issue as well and tracked it down to the same commit introducing the problem:

http://cgit.drupalcode.org/panels/commit/includes/plugins.inc?id=baed7ee...
of #1762290: PHP 5.4 Issue with array_diff_assoc in plugins.inc

Before the PHP 5.4, the settings array were not merged. However, in the PHP 5.4 fix issue it was change to merge the settings arrays as well what introduces issues. In my case, it broke views_slideshow on cached pages.

Adding this deep-merge of JS settings seems to be out of scope of a PHP 5.4 fix issue to me. The change introduced issues with numerical keys, leads to duplicate items and potentially bogus settings as my issue with views_slideshow revealed. That merging behaviour change should be reverted, as the patch in #1 does correctly.

I tested #1 on my site and works fine, caching works correctly again now.

japerry’s picture

Status: Reviewed & tested by the community » Needs review

Hmm so what you're saying makes sense to me, but I'm a little worried we're missing something here. I'd love to get das-peter's comments on this before committing.

fago’s picture

Still running this without any further issues on a site making use of panels & panelizer heavily :)

japerry’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.