una
una copied to clipboard
Timeline: Improve events grouping
Use 'source' field in SQL queries instead of serialized 'timeline_group' => ['by' => '...', 'field' => 'owner_id'] in PHP.
Update code with "TODO: Should be updated when GROUP BY source will be used in sub selects."
Now group by 'source' is used in Validation query.
In the next update add the following code:
$oDb = BxDolDb::getInstance();
$aEvents = $oDb->getAll("SELECT * FROM `bx_timeline_events` WHERE `source`='' AND `content` LIKE '%timeline_group%'");
foreach($aEvents as $aEvent) {
$aContent = unserialize($aEvent['content']);
if(!empty($aContent['timeline_group']) && is_array($aContent['timeline_group']))
$oDb->query("UPDATE `bx_timeline_events` SET `source`=:source WHERE `id`=:id", [
'id' => $aEvent['id'],
'source' => $aContent['timeline_group']['by']
]);
It may be useful for old records which don't have a value in source field.