AntonLV 5 anni fa
parent
commit
456600a9cc
2 ha cambiato i file con 36 aggiunte e 15 eliminazioni
  1. 32 11
      inc/classes/BxDolLiveUpdates.php
  2. 4 4
      template/scripts/BxBaseLiveUpdates.php

+ 32 - 11
inc/classes/BxDolLiveUpdates.php

@@ -32,7 +32,8 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
     protected $_iInterval;
     protected $_iInterval;
 
 
     protected $_oCacheObject;
     protected $_oCacheObject;
-    protected $_sCacheKey;
+    protected $_sCacheKeySystems;
+    protected $_sCacheKeyData;
     protected $_iCacheTTL;
     protected $_iCacheTTL;
 
 
     protected $_sJsClass;
     protected $_sJsClass;
@@ -40,6 +41,9 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
 
 
     protected function __construct()
     protected function __construct()
     {
     {
+        if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
+            trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
+
         parent::__construct();
         parent::__construct();
 
 
         /**
         /**
@@ -56,7 +60,8 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
         $this->_iInterval = (int)$this->_oQuery->getParam('sys_live_updates_interval');
         $this->_iInterval = (int)$this->_oQuery->getParam('sys_live_updates_interval');
         
         
         $this->_oCacheObject = $this->_oQuery->getDbCacheObject();
         $this->_oCacheObject = $this->_oQuery->getDbCacheObject();
-        $this->_sCacheKey = 'sys_live_updates_' . $this->_iProfileId;
+        $this->_sCacheKeySystems = 'sys_live_updates_systems';
+        $this->_sCacheKeyData = 'sys_live_updates_data_' . $this->_iProfileId;
         $this->_iCacheTTL = 86400;
         $this->_iCacheTTL = 86400;
 
 
         $this->_sJsClass = 'BxDolLiveUpdates';
         $this->_sJsClass = 'BxDolLiveUpdates';
@@ -67,6 +72,12 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
     	$this->_aSystemsTransient = array();
     	$this->_aSystemsTransient = array();
     }
     }
 
 
+    public function __clone()
+    {
+        if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
+            trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
+    }
+
     /**
     /**
      * get live updates instanse
      * get live updates instanse
      * @return ready to use class instance
      * @return ready to use class instance
@@ -89,7 +100,7 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
 
 
         $mixedCacheKey = bx_get('hash');
         $mixedCacheKey = bx_get('hash');
         if($mixedCacheKey !== false)
         if($mixedCacheKey !== false)
-            $this->_sCacheKey = base64_decode(bx_process_input($mixedCacheKey));
+            $this->_sCacheKeySystems = $this->_decodeHash(bx_process_input($mixedCacheKey));
 
 
         $mixedSystemsActive = bx_get('systems_active');
         $mixedSystemsActive = bx_get('systems_active');
         if($mixedSystemsActive !== false)
         if($mixedSystemsActive !== false)
@@ -143,7 +154,7 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
             return false;
             return false;
 
 
         if(empty($this->_aSystemsTransient))
         if(empty($this->_aSystemsTransient))
-            $this->_sCacheKey .= $this->_getPageId();
+            $this->_sCacheKeySystems .= $this->_getPageId();
 
 
         if(!in_array($sName, $this->_aSystemsTransient))
         if(!in_array($sName, $this->_aSystemsTransient))
             $this->_aSystemsTransient[] = $sName;
             $this->_aSystemsTransient[] = $sName;
@@ -174,18 +185,18 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
         return true;
         return true;
     }
     }
 
 
-    protected function _getCacheInfo()
+    protected function _getCacheInfo($sType)
     {
     {
     	return array(
     	return array(
             $this->_oCacheObject,
             $this->_oCacheObject,
-            $this->_oQuery->genDbCacheKey($this->_sCacheKey),
+            $this->_oQuery->genDbCacheKey($this->{'_sCacheKey' . ucfirst($sType)}),
             $this->_iCacheTTL
             $this->_iCacheTTL
     	);
     	);
     }
     }
 
 
     protected function _getCached($sType)
     protected function _getCached($sType)
     {
     {
-        list($oCache, $sCacheKey, $iCacheTtl) = $this->_getCacheInfo();
+        list($oCache, $sCacheKey, $iCacheTtl) = $this->_getCacheInfo($sType);
 
 
         $aCached = $oCache->getData($sCacheKey, $iCacheTtl);
         $aCached = $oCache->getData($sCacheKey, $iCacheTtl);
         if(empty($aCached[$sType])) {
         if(empty($aCached[$sType])) {
@@ -232,12 +243,12 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
         $oCache->delData($sCacheKey);
         $oCache->delData($sCacheKey);
     }
     }
 
 
-    protected function _updateCached($sKey, $aData)
+    protected function _updateCached($sType, $aData)
     {
     {
-    	list($oCache, $sCacheKey, $iCacheTtl) = $this->_getCacheInfo();
+    	list($oCache, $sCacheKey, $iCacheTtl) = $this->_getCacheInfo($sType);
 
 
     	$aCached = $oCache->getData($sCacheKey, $iCacheTtl);
     	$aCached = $oCache->getData($sCacheKey, $iCacheTtl);
-    	$aCached[$sKey] = $aData;
+    	$aCached[$sType] = $aData;
 
 
     	$oCache->setData($sCacheKey, $aCached, $iCacheTtl);
     	$oCache->setData($sCacheKey, $aCached, $iCacheTtl);
     }
     }
@@ -282,7 +293,17 @@ class BxDolLiveUpdates extends BxDolFactory implements iBxDolSingleton
         parse_str($_SERVER['QUERY_STRING'], $aPageParams);
         parse_str($_SERVER['QUERY_STRING'], $aPageParams);
         $aPageParams = array_diff_assoc($aPageParams, array('start', 'per_page', 'order', 'filter'));
         $aPageParams = array_diff_assoc($aPageParams, array('start', 'per_page', 'order', 'filter'));
 
 
-        return '_' . md5(bx_append_url_params($_SERVER['PHP_SELF'], $aPageParams));
+        return '_' . $this->_iProfileId . '_' . md5(bx_append_url_params($_SERVER['PHP_SELF'], $aPageParams));
+    }
+
+    protected function _encodeHash()
+    {
+        return base64_encode($this->_sCacheKeySystems);
+    }
+
+    protected function _decodeHash($sHash)
+    {
+        return base64_decode($sHash);
     }
     }
 }
 }
 
 

+ 4 - 4
template/scripts/BxBaseLiveUpdates.php

@@ -46,7 +46,7 @@ class BxBaseLiveUpdates extends BxDolLiveUpdates
             'aSystemsActive' => array_intersect_key($aCached, array_flip($this->_aSystemsActive)),
             'aSystemsActive' => array_intersect_key($aCached, array_flip($this->_aSystemsActive)),
             'aSystemsTransient' => array_flip($this->_aSystemsTransient),
             'aSystemsTransient' => array_flip($this->_aSystemsTransient),
             'bServerRequesting' => !empty($this->_aSystems),
             'bServerRequesting' => !empty($this->_aSystems),
-            'sHash' => base64_encode($this->_sCacheKey),
+            'sHash' => $this->_encodeHash(),
         ), $aParams);
         ), $aParams);
 
 
         $sContent = "var " . $this->_sJsObject . " = new " . $this->_sJsClass . "(" . json_encode($aParams) . ");";
         $sContent = "var " . $this->_sJsObject . " = new " . $this->_sJsClass . "(" . json_encode($aParams) . ");";
@@ -67,7 +67,7 @@ class BxBaseLiveUpdates extends BxDolLiveUpdates
      */
      */
     public function add($sName, $iFrequency, $sServiceCall, $bActive = true, $mixedValue = false)
     public function add($sName, $iFrequency, $sServiceCall, $bActive = true, $mixedValue = false)
     {
     {
-        $sCacheKey = $this->_sCacheKey;
+        $sCacheKeySystems = $this->_sCacheKeySystems;
 
 
         if(!$this->_addSystem($sName, $iFrequency, $sServiceCall, $bActive))
         if(!$this->_addSystem($sName, $iFrequency, $sServiceCall, $bActive))
             return '';
             return '';
@@ -84,8 +84,8 @@ class BxBaseLiveUpdates extends BxDolLiveUpdates
     	$this->_addData($sName, $iValue);
     	$this->_addData($sName, $iValue);
 
 
         $aParams = array('name' => $sName, 'value' => $iValue);
         $aParams = array('name' => $sName, 'value' => $iValue);
-        if($sCacheKey != $this->_sCacheKey)
-            $aParams['hash'] = base64_encode($this->_sCacheKey);
+        if($sCacheKeySystems != $this->_sCacheKeySystems)
+            $aParams['hash'] = $this->_encodeHash();
 
 
         $sContent = "if(" . $this->_sJsObject . " != undefined) " . $this->_sJsObject . ".add(" . json_encode($aParams) . ");";
         $sContent = "if(" . $this->_sJsObject . " != undefined) " . $this->_sJsObject . ".add(" . json_encode($aParams) . ");";
         return BxDolTemplate::getInstance()->_wrapInTagJsCode($sContent);
         return BxDolTemplate::getInstance()->_wrapInTagJsCode($sContent);