Browse Source

Ticket #258 - Prolong recurring license.

AntonLV 10 years ago
parent
commit
575379f7b0

+ 41 - 4
modules/boonex/market/classes/BxMarketDb.php

@@ -325,6 +325,26 @@ class BxMarketDb extends BxBaseModTextDb
     {
     	$CNF = &$this->_oConfig->CNF;
 
+    	$bRegistered = (int)$this->getOne("SELECT `id` FROM `" . $CNF['TABLE_LICENSES'] . "` WHERE `profile_id` = :profile_id AND `product_id` = :product_id AND `order` = :order LIMIT 1", array(
+    		'profile_id' => $iProfileId,
+    		'product_id' => $iProductId,
+    		'order' => $sOrder,
+    	)) > 0;
+
+    	$sMethod = $bRegistered ? '_prolongLicense' : '_registerLicense';
+    	return $this->$sMethod($iProfileId, $iProductId, $iCount, $sOrder, $sLicense, $sType, $sDuration);
+    }
+
+    public function unregisterLicense($iProfileId, $iProductId, $sOrder, $sLicense, $sType)
+    {
+    	$sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE `profile_id` = ? AND `product_id` = ? AND `order` = ? AND `license` = ?", $iProfileId, $iProductId, $sOrder, $sLicense);
+        return (int)$this->query($sQuery) > 0;
+    }
+
+    protected function _registerLicense($iProfileId, $iProductId, $iCount, $sOrder, $sLicense, $sType, $sDuration = '')
+    {
+    	$CNF = &$this->_oConfig->CNF;
+
     	$aQueryParams = array(
     		'profile_id' => $iProfileId,
     		'product_id' => $iProductId,
@@ -335,16 +355,33 @@ class BxMarketDb extends BxBaseModTextDb
     	);
 
 		$sExpireParam = ''; 
-		if(!empty($sDuration))
+		if(!empty($sDuration) && isset($this->_aRecurringDurations[$sDuration]))
 			$sExpireParam = ', `expired`=UNIX_TIMESTAMP(DATE_ADD(DATE_ADD(NOW(), ' . $this->_aRecurringDurations[$sDuration] . '), INTERVAL ' . (int)$this->getParam($CNF['OPTION_RECURRING_RESERVE']) . ' DAY))';
 
-    	$sQuery = $this->prepare("INSERT INTO `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` SET " . $this->arrayToSQL($aQueryParams) . ", `added`=UNIX_TIMESTAMP()" . $sExpireParam);
+    	$sQuery = $this->prepare("INSERT INTO `" . $CNF['TABLE_LICENSES'] . "` SET " . $this->arrayToSQL($aQueryParams) . ", `added`=UNIX_TIMESTAMP()" . $sExpireParam);
         return (int)$this->query($sQuery) > 0;
     }
 
-    public function unregisterLicense($iProfileId, $iProductId, $sOrder, $sLicense, $sType)
+    protected function _prolongLicense($iProfileId, $iProductId, $iCount, $sOrder, $sLicense, $sType, $sDuration = '')
     {
-    	$sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_LICENSES'] . "` WHERE `profile_id` = ? AND `product_id` = ? AND `order` = ? AND `license` = ?", $iProfileId, $iProductId, $sOrder, $sLicense);
+    	$CNF = &$this->_oConfig->CNF;
+
+    	if($sType == BX_MARKET_LICENSE_TYPE_SINGLE)
+    		return true;
+
+    	if(empty($sDuration) || empty($this->_aRecurringDurations[$sDuration]))
+    		return false;
+
+    	$sQuery = $this->prepare("UPDATE 
+    			`" . $CNF['TABLE_LICENSES'] . "` 
+    		SET 
+    			`expired`=UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`expired`), " . $this->_aRecurringDurations[$sDuration] . ")) 
+    		WHERE 
+    			`profile_id` = ? AND 
+    			`product_id` = ? AND 
+    			`order` = ? 
+    		LIMIT 1", $iProfileId, $iProductId, $sOrder);
+
         return (int)$this->query($sQuery) > 0;
     }
 

+ 1 - 1
modules/boonex/market/install/sql/uninstall.sql

@@ -19,7 +19,7 @@ DELETE FROM `sys_form_display_inputs` WHERE `display_name` IN ('bx_market_entry_
 -- PRE-VALUES
 DELETE FROM `sys_form_pre_lists` WHERE `module` = 'bx_market';
 
-DELETE FROM `sys_form_pre_values` WHERE `Key` IN('bx_market_cats');
+DELETE FROM `sys_form_pre_values` WHERE `Key` IN('bx_market_cats', 'bx_market_prices', 'bx_market_durations');
 
 -- COMMENTS
 DELETE FROM `sys_objects_cmts` WHERE `Name` = 'bx_market';