Преглед изворни кода

Ticket #2298 - Changes in Market module.

AntonLV пре 7 година
родитељ
комит
3935c4ea46

+ 31 - 8
modules/boonex/market/classes/BxMarketCronPruning.php

@@ -9,26 +9,49 @@
  * @{
  * @{
  */
  */
 
 
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
 class BxMarketCronPruning extends BxDolCron
 class BxMarketCronPruning extends BxDolCron
 {
 {
-	protected $_sModule;
-	protected $_oModule;
+    protected $_sModule;
+    protected $_oModule;
 
 
-	public function __construct()
+    public function __construct()
     {
     {
-    	$this->_sModule = 'bx_market';
-    	$this->_oModule = BxDolModule::getInstance($this->_sModule);
+        $this->_sModule = 'bx_market';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
 
 
         parent::__construct();
         parent::__construct();
     }
     }
 
 
     function processing()
     function processing()
     {
     {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $oPayments = BxDolPayments::getInstance();
+
         $aLicenses = $this->_oModule->_oDb->getLicense(array('type' => 'expired'));
         $aLicenses = $this->_oModule->_oDb->getLicense(array('type' => 'expired'));
-        foreach($aLicenses as $aLicense)
-        	bx_alert($this->_oModule->getName(), 'license_expire', 0, false, $aLicense);
+        foreach($aLicenses as $aLicense) {
+            $aSubscription = $oPayments->getSubscriptionsInfo(array('subscription_id' => $aLicense['order']), true);
+            if(!empty($aSubscription) && is_array($aSubscription)) {
+                $aSubscription = array_shift($aSubscription);
+
+                if($aSubscription['data']['status'] == 'active') {
+                    $this->_oModule->_oDb->updateLicense(array('expired' => $aSubscription['data']['cperiod_end'] + 86400 * (int)getParam($CNF['OPTION_RECURRING_RESERVE'])), array('id' => $aLicense['id']));
+                    continue;
+                }
+                else {
+                    $oPayments->sendSubscriptionExpirationLetters($aSubscription['pending_id'], $aLicense['order']);
+
+                    $this->_oModule->_oDb->updateLicense(array('expired' => $aLicense['expired'] + 86400 * (int)getParam($CNF['OPTION_RECURRING_RESERVE'])), array('id' => $aLicense['id']));
+                    continue;
+                }
+            }
 
 
-        $this->_oModule->_oDb->processExpiredLicenses();
+            bx_alert($this->_oModule->getName(), 'license_expire', 0, false, $aLicense);
+            
+            $this->_oModule->_oDb->processExpiredLicense($aLicense);
+        }
     }
     }
 }
 }
 
 

+ 21 - 13
modules/boonex/market/classes/BxMarketDb.php

@@ -550,22 +550,30 @@ class BxMarketDb extends BxBaseModTextDb
         return $this->query($sQuery, $aWhereBindings) !== false;
         return $this->query($sQuery, $aWhereBindings) !== false;
     }
     }
 
 
-	function processExpiredLicenses()
-	{
-		$sWhereClause = "`type` = :type AND `added` < UNIX_TIMESTAMP() AND `expired` <> 0 AND `expired` < UNIX_TIMESTAMP()";
-    	$aWhereBindings = array(
-    		'type' => BX_MARKET_LICENSE_TYPE_RECURRING
-    	);
+    function processExpiredLicense($aLicense)
+    {
+        //--- Move to deleted licenses table with 'expire' as reason.  
+        $this->query("INSERT IGNORE INTO `" . $this->_oConfig->CNF['TABLE_LICENSES_DELETED'] . "` SET " . $this->arrayToSQL($aLicense));
 
 
-    	//--- Move to deleted licenses table with 'expire' as reason.  
-		$sQuery = "INSERT IGNORE INTO `" . $this->_oConfig->CNF['TABLE_LICENSES_DELETED'] . "` SELECT *, 'expire' AS `reason`, UNIX_TIMESTAMP() AS `deleted` FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE " . $sWhereClause;
-		$this->query($sQuery, $aWhereBindings);
+        return $this->query("DELETE FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE `id`=:id LIMIT 1", array('id' => $aLicense['id'])) !== false;
+    }
 
 
-		$sQuery = "DELETE FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE " . $sWhereClause;
-		return $this->query($sQuery, $aWhereBindings) !== false;	    
-	}
+    function processExpiredLicenses()
+    {
+        $sWhereClause = "`type` = :type AND `added` < UNIX_TIMESTAMP() AND `expired` <> 0 AND `expired` < UNIX_TIMESTAMP()";
+        $aWhereBindings = array(
+            'type' => BX_MARKET_LICENSE_TYPE_RECURRING
+        );
+
+        //--- Move to deleted licenses table with 'expire' as reason.  
+        $sQuery = "INSERT IGNORE INTO `" . $this->_oConfig->CNF['TABLE_LICENSES_DELETED'] . "` SELECT *, 'expire' AS `reason`, UNIX_TIMESTAMP() AS `deleted` FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE " . $sWhereClause;
+        $this->query($sQuery, $aWhereBindings);
+
+        $sQuery = "DELETE FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE " . $sWhereClause;
+        return $this->query($sQuery, $aWhereBindings) !== false;
+    }
 
 
-	protected function _deassociateAttachmentWithContent($sTable, $iContentId, $iFileId)
+    protected function _deassociateAttachmentWithContent($sTable, $iContentId, $iFileId)
     {
     {
         $sWhere = '';
         $sWhere = '';
         $aBindings = array();
         $aBindings = array();