Parcourir la source

Ticket #4640 - Timeline: Update necessary data when content was moved to another author.

AntonLV il y a 2 ans
Parent
commit
2f01b1a98a

+ 24 - 5
modules/base/text/classes/BxBaseModTextModule.php

@@ -835,7 +835,7 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
 
         $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
 
-        $aParams = $this->_alertParams($aContentInfo);
+        $aParams = $this->_alertParamsEdit($aContentInfo);
         bx_alert($this->getName(), 'edited', $iId, false, $aParams);
     }
 
@@ -870,14 +870,33 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         $CNF = &$this->_oConfig->CNF;
 
         if(!empty($CNF['OBJECT_METATAGS']))
-            $aParams['timeline_group'] = array(
-                'by' => $this->getName() . '_' . abs((int)$aContentInfo[$CNF['FIELD_AUTHOR']]) . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
-                'field' => 'owner_id'
-            );
+            $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
+
+        return $aParams;
+    }
+
+    protected function _alertParamsEdit($aContentInfo)
+    {
+        $aParams = $this->_alertParams($aContentInfo);
+
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!empty($CNF['OBJECT_METATAGS']))
+            $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
 
         return $aParams;
     }
 
+    protected function _getAlertParamTimelineGroup($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        return [
+            'by' => $this->getName() . '_' . abs((int)$aContentInfo[$CNF['FIELD_AUTHOR']]) . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
+            'field' => 'owner_id'
+        ];
+    }
+
     public function getPollForm()
     {
         $CNF = &$this->_oConfig->CNF;

+ 26 - 8
modules/boonex/timeline/classes/BxTimelineResponse.php

@@ -111,7 +111,7 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 $aEvent = $this->$sMethod($oAlert, $aHandler);
                 if(empty($aEvent) || !is_array($aEvent))
                     break;
-
+//var_dump($oAlert->aExtras); exit;
                 $aContent = [];
                 if(!empty($aEvent['content']) && is_string($aEvent['content']))
                     $aContent = unserialize($aEvent['content']);
@@ -121,11 +121,10 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 $aParamsSet = ['content' => serialize($aContent)];
                 $aParamsSetBySource = [];
 
-                foreach(['status', 'status_admin'] as $sStatusKey)
-                    if(!empty($aContent[$sStatusKey])) {
-                        $aParamsSet[$sStatusKey] = $aContent[$sStatusKey];
-                        $aParamsSetBySource[$sStatusKey] = $aContent[$sStatusKey];
-                    }
+                if($iObjectAuthorId != $aEvent['object_owner_id']) {
+                    $aParamsSet['object_owner_id'] = $iObjectAuthorId;
+                    $aParamsSetBySource['object_owner_id'] = $iObjectAuthorId;
+                }
 
                 if($iObjectPrivacyView > 0)
                     $aParamsSet = array_merge($aParamsSet, [
@@ -138,6 +137,25 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                         'object_privacy_view' => $iObjectPrivacyView 
                     ]);
 
+                $bSource = false;
+                $sSource = $aEvent[$CNF['FIELD_SOURCE']];
+                if(($bSource = !empty($sSource)) !== false) {
+                    $sSourceNew = '';
+                    if(!empty($oAlert->aExtras['timeline_group']))
+                        $sSourceNew = $oAlert->aExtras['timeline_group']['by'];
+
+                    if($sSourceNew && strcmp($sSourceNew, $sSource) != 0) {
+                        $aParamsSet['source'] = $sSourceNew;
+                        $aParamsSetBySource['source'] = $sSourceNew;
+                    }
+                }
+
+                foreach(['status', 'status_admin'] as $sStatusKey)
+                    if(!empty($aContent[$sStatusKey])) {
+                        $aParamsSet[$sStatusKey] = $aContent[$sStatusKey];
+                        $aParamsSetBySource[$sStatusKey] = $aContent[$sStatusKey];
+                    }
+
                 $sMethod = 'get_timeline_update_data';
                 if(bx_is_srv($oAlert->sUnit, $sMethod)) 
                     list($aParamsSet, $aParamsSetBySource) = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent, [$aParamsSet, $aParamsSetBySource]]);
@@ -156,8 +174,8 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 $this->_oModule->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);              
 
                 //--- Update related events.
-                if(!empty($aEvent[$CNF['FIELD_SOURCE']]) && !empty($aParamsSetBySource)) {
-                    $aEventsBySource = $this->_oModule->_oDb->getEvents(['browse' => 'source', 'value' => $aEvent[$CNF['FIELD_SOURCE']]]);
+                if($bSource && !empty($aParamsSetBySource)) {
+                    $aEventsBySource = $this->_oModule->_oDb->getEvents(['browse' => 'source', 'value' => $sSource]);
                     foreach($aEventsBySource as $aEventBySource) {
                         if($aEventBySource[$CNF['FIELD_ID']] == $aEvent[$CNF['FIELD_ID']])
                             continue;