Bug #22801 Clarification Requested

The ChannelEntry model caches tab fields, which causes issue with multiple model instances.

Version: 3.4.3 Reporter: Zeke Aasman

I have a module function that iterates over a group of channel entries making some value changes. I’m using the ChannelEntry model to interface with the data, but I run into problems because of how the model is saving default fields.

At line 651 of EllisLab\ExpressionEngine\Model\Channel\ChannelEntry, the model saves it’s default fields within the static variable $default_fields in such a way that the variable is only set once (ie cached). The problem is that it also saves module tab fields, which include not just default values but the specific entry’s data as well. So, in my case, every subsequent instance of ChannelEntry references tab values from the first entry, and on ChannelEntry::save I end up overwriting any/all module tab values to that of the first instance.

The fix is simple: move the module tab block (lines 829 - 837) out of and below the if statement, effectively stopping those values from being cached. I’m hoping you agree and can incorporate this (or another fix) into a future release.

Thanks! Zeke

Fix, lines 829 - 838:

$module_tabs = $this->getTabFields();

      foreach ($module_tabs as $tab_id => $fields)
      {
       foreach ($fields as $key => $field)
       {
        $default_fields[$tab_id . '__' . $key] = $field;
       }
      }
     }

Becomes:

}

     $module_tabs = $this->getTabFields();

     foreach ($module_tabs as $tab_id => $fields)
     {
      foreach ($fields as $key => $field)
      {
       $default_fields[$tab_id . '__' . $key] = $field;
      }
     }
  • Hi Zeke,

    Sure, we should be able find a way to fix this for you. Can you give me an example of what’s triggering the issue exactly? Are you saying you query for some existing ChannelEntry objects, and when you re-save them, they all get the value of the very first ChannelEntry’s tab values? And only the tab values do this?

    Kevin Cupp
    06th December, 2016 at 11:20am

You must be signed in to comment on a bug report.

ExpressionEngine News

#eecms, #events, #releases