Просмотр исходного кода

Ticket #4558 - Build-in API support: Timeline events grouping for validation.

AntonLV 1 год назад
Родитель
Сommit
40bcd63a56

+ 1 - 1
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -774,7 +774,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
         $sSqlMaskUnion = '(' . implode(') UNION (', $aSqlParts) . ')';
         if($bValidate)
-            $sSqlMaskUnion = 'SELECT MAX(`tu`.`id`) AS `id` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
+            $sSqlMaskUnion = 'SELECT MIN(`tu`.`id`) AS `min_id`, MAX(`tu`.`id`) AS `max_id` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
         else
             $sSqlMaskUnion = 'SELECT *, GROUP_CONCAT(`owner_id`) AS `owner_id_grouped` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
         $sSqlMaskUnion .= ' {order} {limit}';

+ 20 - 1
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -5736,8 +5736,27 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
             $iIds = 0;
             $aIds = [];
+            $sModule = $this->_oConfig->getName();
             foreach($aEventsIds as $aEventId) {
-                $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['id']]);
+                $aEvent = [];
+                if((int)$aEventId['min_id'] != (int)$aEventId['max_id']) {
+                    $aEs = [
+                        $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['min_id']]),
+                        $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['max_id']])
+                    ];
+
+                    foreach($aEs as $aE) {
+                        $bEs = (int)$aE['system'] != 0;
+                        if(($bEs ? $aE['type'] : $sModule) . '_' . abs($aE['object_owner_id']) . '_' . ($bEs ? $aE['object_id'] : $aE['id']) != $aE['source']) 
+                            continue;
+
+                        $aEvent = $aE;
+                        break;
+                    }
+                }
+                else 
+                    $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['min_id']]);
+
                 if(empty($aEvent) || !is_array($aEvent))
                     continue;