Bug #22801 Clarification Requested

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

Version: 3.4.3 Reporter: Zeke Aasman

This is an archived bug report. If you are experiencing a similar issue, upgrade to the latest release and if that does not solve the problem, submit a new bug report

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;
      }
     }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases