Pārlūkot izejas kodu

Ticket #4319 - Profiles: Improve Recommended profiles functionality: Fire additional updates.

AntonLV 3 gadi atpakaļ
vecāks
revīzija
c76626bfd7

+ 30 - 1
inc/classes/BxDolConnection.php

@@ -332,11 +332,36 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
         
         bx_alert($this->_sObject, 'connection_added', 0, bx_get_logged_profile_id(), $aAlertExtras);
 
-        $this->checkAllowedConnect ($iInitiator, $iContent, true, $iMutual, false);
+        $this->onAdded($iInitiator, $iContent, $iMutual);
 
         return true;
     }
 
+    public function onAdded($iInitiator, $iContent, $iMutual)
+    {
+        $this->checkAllowedConnect ($iInitiator, $iContent, true, $iMutual, false);
+
+        /**
+         * Update recommendations.
+         */
+        $bMutual = false;
+        if($this->_aObject['type'] == BX_CONNECTIONS_TYPE_ONE_WAY || ($bMutual = ($this->_aObject['type'] == BX_CONNECTIONS_TYPE_MUTUAL && $iMutual))) {
+            $oProfileQuery = BxDolProfileQuery::getInstance();
+
+            if($this->_aObject['profile_initiator']) {
+                $aInitiator = $oProfileQuery->getInfoById($iInitiator);
+                if(bx_srv($aInitiator['type'], 'act_as_profile'))
+                    BxDolRecommendation::updateData($iInitiator);
+            }
+
+            if($bMutual && $this->_aObject['profile_content']) {
+                $aContent = $oProfileQuery->getInfoById($iContent);
+                if(bx_srv($aContent['type'], 'act_as_profile'))
+                    BxDolRecommendation::updateData($iContent);
+            }
+        }
+    }
+
     /**
      * Remove connection.
      * @param $iInitiator initiator of the connection
@@ -358,9 +383,13 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
             'object' => $this,
         ));
 
+        $this->onRemoved($iInitiator, $iContent);
+
         return true;
     }
 
+    public function onRemoved($iInitiator, $iContent) {}
+
     /**
      * Compound function, which calls getCommonContent, getConnectedContent or getConnectedInitiators depending on $sContentType
      * @param $sContentType content type to get BX_CONNECTIONS_CONTENT_TYPE_CONTENT, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS or BX_CONNECTIONS_CONTENT_TYPE_COMMON

+ 8 - 3
inc/classes/BxDolCronQuery.php

@@ -58,13 +58,18 @@ class BxDolCronQuery extends BxDolDb implements iBxDolSingleton
         return (int)$this->query($sQuery) > 0;
     }
 
-	public function addTransientJobService($sName, $mixedService)
+    public function isTransientJobService($sName)
+    {
+        return (int)$this->getOne("SELECT `id` FROM `sys_cron_jobs` WHERE `name`=:name LIMIT 1", ['name' => $sName]) > 0; 
+    }
+
+    public function addTransientJobService($sName, $mixedService)
     {
     	if(is_array($mixedService))
-    		$mixedService = call_user_func_array('BxDolService::getSerializedService', $mixedService);
+            $mixedService = call_user_func_array('BxDolService::getSerializedService', $mixedService);
 
     	if(!BxDolService::isSerializedService($mixedService))
-    		return false;
+            return false;
 
     	$sQuery = $this->prepare("INSERT INTO `sys_cron_jobs` SET `name`=?, `time`='transient', `service_call`=?", $sName, $mixedService);
         return (int)$this->query($sQuery) > 0;

+ 5 - 1
inc/classes/BxDolRecommendation.php

@@ -69,7 +69,11 @@ class BxDolRecommendation extends BxDolFactory implements iBxDolFactoryObject
         if(!$iProfileId)
             $iProfileId = bx_get_logged_profile_id();
 
-        BxDolCronQuery::getInstance()->addTransientJobService('recommendations_for_' . $iProfileId, ['system', 'updateRecommendations', [$iProfileId], 'TemplServiceProfiles']);
+        $oCronQuery = BxDolCronQuery::getInstance();
+
+        $sName = 'recommendations_for_' . $iProfileId;
+        if(!$oCronQuery->isTransientJobService($sName))
+            $oCronQuery->addTransientJobService($sName, ['system', 'updateRecommendations', [$iProfileId], 'TemplServiceProfiles']);
     }
 
     public function getConnection()