Index: in-auction/units/helpers/ebay_helper.php =================================================================== --- in-auction/units/helpers/ebay_helper.php (revision 13152) +++ in-auction/units/helpers/ebay_helper.php (working copy) @@ -13,11 +13,11 @@ defined('FULL_PATH') or die('restricted access!'); - if (class_exists('SoapClient')) { + if (class_exists('SoapClient')) { k4_include_once(dirname(__FILE__).'/ebay_soap.php'); } else { k4_include_once(dirname(__FILE__).'/ebay_no_soap.php'); - } + } class eBayHelper extends kHelper { @@ -71,7 +71,7 @@ if (!class_exists('SoapClient')) { return; } - + $this->soap_enabled = 1; // Create and configure session @@ -121,7 +121,7 @@ public function __call($function, $args) { static $client = null; - + $request_time = adodb_mktime(); if (!$this->soap_enabled) { $fields_hash = Array ( @@ -132,9 +132,9 @@ 'AnswerStatus' => 'Error', 'Errors' => 'PHP doesn\'t have SOAP module enabled' ); - + $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'eBayErrorLog'); - return; + return; } if (!isset($client)) { @@ -256,11 +256,8 @@ function CheckItemsLimits($request_time, $quantity) { // get limits + $a_counters = unserialize( $this->Application->getDBCache('call_counters') ); - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache - WHERE VarName = '.$this->Conn->qstr('call_counters'); - $a_counters = unserialize($this->Conn->GetOne($sql)); - if (!is_array($a_counters)) { return 'overall'; @@ -298,11 +295,8 @@ function CheckCallLimits($request_time) { // get limits + $a_counters = unserialize( $this->Application->getDBCache('call_counters') ); - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache - WHERE VarName = '.$this->Conn->qstr('call_counters'); - $a_counters = unserialize($this->Conn->GetOne($sql)); - if (!is_array($a_counters)) { return 'overall'; @@ -341,13 +335,7 @@ // save counters $a_counters['LastCallTime'] = $request_time; - $sql = 'REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) - VALUES ( - '.$this->Conn->qstr('call_counters').', - '.$this->Conn->qstr(serialize($a_counters)).', - '.adodb_mktime().' - )'; - $this->Conn->Query($sql); + $this->Application->setDBCache('call_counters', serialize($a_counters)); } function RemoveToken() @@ -389,8 +377,12 @@ function ClearConfigCache() { - $sql = 'DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = \'configs_parsed\''; - $this->Conn->Query($sql); + if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $this->Application->deleteCache('master:configs_parsed'); + } + else { + $this->Application->deleteDBCache('configs_parsed'); + } } function RuName() Index: in-auction/units/sections/ebay_eh.php =================================================================== --- in-auction/units/sections/ebay_eh.php (revision 13152) +++ in-auction/units/sections/ebay_eh.php (working copy) @@ -2591,7 +2591,7 @@ { // Get last usage time - $last_usage_time = $this->GetCacheValue($cache_name); + $last_usage_time = $this->Application->getDBCache($cache_name); if ($last_usage_time == 0) { @@ -2674,7 +2674,7 @@ { $a_items = Array($a_items); } - $this->SetCacheValue('get_list_time', $curr_gmt_time); + $this->Application->setDBCache('get_list_time', $curr_gmt_time); foreach ($a_items AS $Item) { $this->UpdateListing($Item); @@ -2910,7 +2910,7 @@ } - $this->SetCacheValue('get_transactions_time', $curr_gmt_time); + $this->Application->setDBCache('get_transactions_time', $curr_gmt_time); foreach ($a_transactions AS $Transaction) { // Locate for order item. If not present - create it @@ -2961,27 +2961,13 @@ } } - function GetCacheValue($var_name) + function resetAgents() { - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache - WHERE VarName = '.$this->Conn->qstr($var_name); - return $this->Conn->GetOne($sql); - } - - function SetCacheValue($var_name, $data) - { - $sql = 'REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) - VALUES ( - '.$this->Conn->qstr($var_name).', - '.$this->Conn->qstr($data).', - '.adodb_mktime().' - )'; + $sql = 'UPDATE ' . TABLE_PREFIX . 'Agents + SET NextRunOn = NULL'; $this->Conn->Query($sql); } - - - /** * Create Item Unpaid disputes on e-Bay * @@ -3336,7 +3322,7 @@ return; } - $this->SetCacheValue('call_counters', $call_counters); + $this->Application->setDBCache('call_counters', $call_counters); } @@ -3366,14 +3352,17 @@ $this->ClearConfigCache(); // clear cache to process all eBay interaction with new token - $this->SetCacheValue('RegularEventRuns', ''); - + $this->resetAgents(); } function ClearConfigCache() { - $sql = 'DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = \'configs_parsed\''; - $this->Conn->Query($sql); + if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $this->Application->deleteCache('master:configs_parsed'); + } + else { + $this->Application->deleteDBCache('configs_parsed'); + } } /** @@ -3423,7 +3412,7 @@ /* @var $eBayHelper eBayHelper*/ $a_params = Array( - 'SessionID' => $this->GetCacheValue('ebay_token_sid'), + 'SessionID' => $this->Application->getDBCache('ebay_token_sid'), ); $Answer = $eBayHelper->FetchToken($a_params); @@ -3447,8 +3436,7 @@ $this->ClearConfigCache(); // clear cache to process all eBay interaction with new token - $this->SetCacheValue('RegularEventRuns', ''); - + $this->resetAgents(); } /** @@ -3504,7 +3492,7 @@ } } - $this->SetCacheValue('ebay_token_sid', $sid); + $this->Application->setDBCache('ebay_token_sid', $sid); $ebay_url = 'https://signin.'.(($this->Application->ConfigValue('eBay_ConnectionMode') == EBAY_PRODUCTION_CONNECTION) ? '' : 'sandbox.').'ebay.com/ws/eBayISAPI.dll?SignIn&runame='.$eBayHelper->RuName().(($this->Application->ConfigValue('eBay_UseFetchToken') == 1) ? '&sid='.$sid : ''); header("location: ".$ebay_url); exit; Index: in-auction/units/sections/ebay_tp.php =================================================================== --- in-auction/units/sections/ebay_tp.php (revision 13152) +++ in-auction/units/sections/ebay_tp.php (working copy) @@ -75,9 +75,7 @@ function PrintCallsArray($params) { - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache - WHERE VarName = '.$this->Conn->qstr('call_counters'); - return var_export(unserialize($this->Conn->GetOne($sql)), true); + return var_export(unserialize( $this->Application->getDBCache('call_counters') ), true); } } \ No newline at end of file Index: in-commerce/units/currencies/currency_rates.php =================================================================== --- in-commerce/units/currencies/currency_rates.php (revision 13152) +++ in-commerce/units/currencies/currency_rates.php (working copy) @@ -17,31 +17,41 @@ var $RateSource; var $ExchangeRates = Array(); - var $PrimaryCurrency; function kCurrencyRates() { - $this->Application =& kApplication::Instance(); + parent::kBase(); + $this->GetRatesData(); } function GetRatesData() { - // written :) just check that it's correct - $conn =& $this->Application->GetADODBConnection(); - $table = $this->Application->getUnitOption('curr', 'TableName'); - $primary = $this->GetPrimaryCurrency(); - $sql = 'SELECT "'.$primary.'" AS TARGET, ISO AS ID, RateToPrimary As RATE, 1 AS UNITS FROM '.$table.' WHERE 1'; - $rates = $conn->Query($sql); - foreach ($rates as $a_rate) { - $this->SetRate($primary, $a_rate['ID'], $a_rate['RATE']); + $cache_key = 'currency_rates[%CurrSerial%]'; + $rates = $this->Application->getCache($cache_key); + $primary = $this->Application->GetPrimaryCurrency(); + + if ($rates === false) { + $conn =& $this->Application->GetADODBConnection(); + + $conn->nextQueryCachable = true; + $sql = 'SELECT ISO, RateToPrimary + FROM ' . $this->Application->getUnitOption('curr', 'TableName') . ' + WHERE Status = ' . STATUS_ACTIVE; + $rates = $conn->Query($sql); + + $this->Application->setCache($cache_key, $rates); } + + foreach ($rates as $rate) { + $this->SetRate($primary, $rate['ISO'], $rate['RateToPrimary']); + } } function GetRate($source_cur, $target_cur, $units = 1) { - $source_cur = ($source_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $source_cur; - $target_cur = ($target_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $target_cur; + $source_cur = ($source_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $source_cur; + $target_cur = ($target_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $target_cur; if($source_cur == $target_cur) { return 1; @@ -76,18 +86,6 @@ $this->ExchangeRates[$target_cur]['UNITS'] = $units; } - function GetPrimaryCurrency() - { - if(!$this->PrimaryCurrency) - { - $conn =& $this->Application->GetADODBConnection(); - $table = $this->Application->getUnitOption('curr', 'TableName'); - $sql = 'SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'; - $this->PrimaryCurrency = $conn->GetOne($sql); - } - return $this->PrimaryCurrency; - } - function StoreRates($currencies=null) { $curr_object =& $this->Application->recallObject('curr', null, Array ('skip_autoload' => true)); @@ -127,7 +125,6 @@ function GetRatesData() { - $this->GetPrimaryCurrency(); $xml_parser = xml_parser_create(); $curl_helper =& $this->Application->recallObject('CurlHelper'); @@ -179,7 +176,6 @@ function GetRatesData() { - $this->GetPrimaryCurrency(); $xml_parser = xml_parser_create(); $curl_helper =& $this->Application->recallObject('CurlHelper'); @@ -225,7 +221,6 @@ $curl_helper =& $this->Application->recallObject('CurlHelper'); /* @var $curl_helper kCurlHelper */ - $this->GetPrimaryCurrency(); for($i = 0; $i < 10; $i++) { $time = adodb_mktime() - $i * 3600 * 24; Index: in-commerce/units/products/products_item.php =================================================================== --- in-commerce/units/products/products_item.php (revision 13152) +++ in-commerce/units/products/products_item.php (working copy) @@ -34,34 +34,51 @@ */ function getPrimaryPricing() { - if (!$this->Application->isAdminUser) { - $user_id = $this->Application->RecallVar('user_id'); - $primary_group = $user_id != -2 ? $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PrimaryGroup = 1 AND PortalUserId = '.$user_id) : false; + // product + pricing based + $cache_key = 'product_primary_pricing[%PIDSerial:' . $this->GetID() . '%][%PrIDSerial:ProductId:' . $this->GetID() . '%]'; - if ($primary_group) { + if (!$this->Application->isAdmin && $this->Application->LoggedIn()) { + // also group based + $primary_group = (int)$this->Application->Session->GetField('GroupId'); + $cache_key .= ':group=' . $primary_group; + } + + $price_info = $this->Application->getCache($cache_key); + + if ($price_info === false) { + if (!$this->Application->isAdmin && $this->Application->LoggedIn()) { + // logged in user on front-end + $this->Conn->nextQueryCachable = true; $sql = 'SELECT Price, Cost - FROM '.TABLE_PREFIX.'ProductsPricing - WHERE (ProductId = '.$this->GetID().') AND (GroupId = '.$primary_group.') - ORDER BY MinQty'; - $a_values = $this->Conn->GetRow($sql); + FROM ' . TABLE_PREFIX . 'ProductsPricing + WHERE (ProductId = ' . $this->GetID() . ') AND (GroupId = ' . $primary_group . ') + ORDER BY MinQty'; + $price_info = $this->Conn->GetRow($sql); - if ($a_values !== false) { - return $a_values; + if ($price_info !== false) { + $this->Application->setCache($cache_key, $price_info); + + return $price_info; } } - } - $pr_table = $this->Application->getUnitOption('pr', 'TableName'); + // not logged-in user on front-end or in administrative console + $pr_table = $this->Application->getUnitOption('pr', 'TableName'); - if ($this->mode == 't') { - $pr_table = $this->Application->GetTempName($pr_table, 'prefix:'.$this->Prefix); + if ($this->IsTempTable()) { + $pr_table = $this->Application->GetTempName($pr_table, 'prefix:' . $this->Prefix); + } + + $this->Conn->nextQueryCachable = true; + $sql = 'SELECT Price, Cost + FROM ' . $pr_table . ' + WHERE (' . $this->IDField . ' = ' . $this->GetID() . ') AND (IsPrimary = 1)'; + $price_info = $this->Conn->GetRow($sql); + + $this->Application->setCache($cache_key, $price_info); } - $sql = 'SELECT Price, Cost - FROM '.$pr_table.' - WHERE ('.$this->IDField.' = '.$this->GetID().') AND (IsPrimary = 1)'; - - return $this->Conn->GetRow($sql); + return $price_info; } } \ No newline at end of file Index: in-commerce/units/shipping_quote_engines/shipping_quote_collector.php =================================================================== --- in-commerce/units/shipping_quote_engines/shipping_quote_collector.php (revision 13152) +++ in-commerce/units/shipping_quote_engines/shipping_quote_collector.php (working copy) @@ -27,11 +27,10 @@ $db =& $this->Application->GetADODBConnection(); $cached_var_name = 'ShippingQuotes'.crc32(serialize($params)); - $day_ago = adodb_mktime() - 3600*24; - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$cached_var_name.'" - AND Cached > '.$day_ago; - if($shipping_types = $db->GetOne($sql)) - { + + $shipping_types = $this->Application->getDBCache($cached_var_name); + + if ($shipping_types) { return unserialize($shipping_types); } @@ -76,11 +75,8 @@ } $shipping_types = $available_types; - $sql = 'DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName LIKE "ShippingQuotes%" AND Cached < '.$day_ago; - $db->Query($sql); - $sql = 'INSERT INTO '.TABLE_PREFIX.'Cache(VarName, Data, Cached) - VALUES("'.$cached_var_name.'", '.$db->qstr(serialize($shipping_types)).', '.adodb_mktime().')'; - $db->Query($sql); + $this->Application->setDBCache($cached_var_name, serialize($shipping_types), 24 * 3600); + return $shipping_types; } Index: in-link/units/link_validation/link_validation_tp.php =================================================================== --- in-link/units/link_validation/link_validation_tp.php (revision 13152) +++ in-link/units/link_validation/link_validation_tp.php (working copy) @@ -40,19 +40,27 @@ $object =& $this->getObject($params); $category_id = isset($params['cat_id']) ? $params['cat_id'] : $object->GetDBField('CategoryId'); - $category_path = $this->Application->getCache('category_paths', $category_id); + $cache_key = 'category_paths[%CIDSerial:' . $category_id . '%]'; + + if ($category_id == 0) { + // home category name is phrase AND phrase name is defined in configuration + $cache_key .= '[%PhrasesSerial%][%ConfSerial%]'; + } + + $category_path = $this->Application->getCache($cache_key); + if ($category_path === false) { - // not chached if ($category_id > 0) { - $cached_navbar = preg_replace('/^(Content&\|&|Content)/i', '', $object->GetDBField('CachedNavbar')); $category_path = trim($this->CategoryName( Array('cat_id' => 0) ).' > '.str_replace('&|&', ' > ', $cached_navbar), ' > '); } else { $category_path = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') ); } - $this->Application->setCache('category_paths', $category_id, $category_path); + + $this->Application->setCache($cache_key, $category_path); } + return $category_path; } } \ No newline at end of file