Node style override won't update effective style id if deleted

Katsuro

Member
Affected version
2.2.15
In XF\Entity\Style::_postDelete()
Developers made a effective style id reset like this:
PHP:
$db->update('xf_node', [
    'style_id' => 0,
    'effective_style_id' => 0
], "style_id = ? OR effective_style_id = ?", [$id, $id]);
so effective_style_id won't get recalculated, because XF\Entity\Node behavior XF:TreeStructured won't get triggered
I kinda understand why they made reset as above and shouldn't be that critical (but fix would be fine), but as per as I use the same feature for my own addon, I wanted to know the possible solution how would be better to solve this "feature" and made the correct reset of effective_style_id. Should I just iterate over each Node and set style_id within entity to behavior will get triggered, or there's some better solution?
 
How about this?
PHP:
$nodes = $this->finder('XF:Node')
    ->where('style_id', $id)
    ->fetch();

$db->beginTransaction();

/** @var \XF\Entity\Node $node */
foreach ($nodes AS $node)
{
    $node->style_id = 0;
    $node->save(true, false);
}

$db->commit();
 
Back
Top Bottom