From: Roland Häder Date: Sun, 30 Sep 2012 20:09:09 +0000 (+0000) Subject: Fixed 'payments' cache (all array elements must have 'id' based index) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b679042bd22371aa267e595db8d0e08941afc9eb;p=mailer.git Fixed 'payments' cache (all array elements must have 'id' based index) --- diff --git a/inc/loader/load-payments.php b/inc/loader/load-payments.php index c11c58f63f..b4a9375b2f 100644 --- a/inc/loader/load-payments.php +++ b/inc/loader/load-payments.php @@ -47,6 +47,25 @@ if (!defined('__SECURITY')) { if (($GLOBALS['cache_instance']->loadCacheFile('payments')) && ($GLOBALS['cache_instance']->extensionVersionMatches('payments'))) { // Load cache $GLOBALS['cache_array']['payments'] = $GLOBALS['cache_instance']->getArrayFromCache(); + + // Init temporary array + $paymentsData = array(); + + // Rewrite all to id + foreach ($GLOBALS['cache_array']['payments']['id'] as $key => $id) { + // Re-add key with id + foreach ($GLOBALS['cache_array']['payments'] as $key2 => $array) { + // Is key2 not 'id'? + if ($key2 != 'id') { + // Then Add it + $paymentsData[$id][$key2] = $GLOBALS['cache_array']['payments'][$key2][$key]; + } // END - if + } // END - foreach + } // END - foreach + + // Set the array back and remove temporary + $GLOBALS['cache_array']['payments'] = $paymentsData; + unset($paymentsData); } elseif (isHtmlOutputMode()) { // Create cache file $GLOBALS['cache_instance']->init(); diff --git a/inc/modules/admin/what-del_email.php b/inc/modules/admin/what-del_email.php index 2651db4b79..478b00bdde 100644 --- a/inc/modules/admin/what-del_email.php +++ b/inc/modules/admin/what-del_email.php @@ -57,7 +57,7 @@ if (isGetRequestElementSet('mid')) { $content = SQL_FETCHARRAY($result); // Get points we shall pay back per mail - $content['price'] = getPaymentPoints($content['payment_id'], 'price'); + $content['price'] = getPaymentData($content['payment_id'], 'price'); // @TODO Unused: cat_id, payment_id // Prepare data for the template diff --git a/inc/modules/member/what-order.php b/inc/modules/member/what-order.php index a44255e8ac..f87c555b36 100644 --- a/inc/modules/member/what-order.php +++ b/inc/modules/member/what-order.php @@ -253,7 +253,7 @@ LIMIT 1", } // END - if // Calculate used points - $usedPoints = $content['target_send'] * getPaymentPoints(bigintval(postRequestElement('mail_type'))); + $usedPoints = $content['target_send'] * getPaymentData(bigintval(postRequestElement('mail_type'))); // Fix empty zip code if (!isPostRequestElementSet('zip')) { diff --git a/inc/modules/order.php b/inc/modules/order.php index 484ba98daf..915500d4d7 100644 --- a/inc/modules/order.php +++ b/inc/modules/order.php @@ -95,7 +95,7 @@ if (empty($url)) { } // END - if // Calculate used points - $content['payed_points'] = $content['target_send'] * getPaymentPoints($content['payment_id']); + $content['payed_points'] = $content['target_send'] * getPaymentData($content['payment_id']); // Subtract them from the user's account and ignore return status subtractPoints('order', getMemberId(), $content['payed_points']); diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 06901af009..625598d66e 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -854,7 +854,7 @@ function getCategory ($cid) { $data['cat'] = '{--_CATEGORY_NONE--}'; } elseif ($cid > 0) { // Lookup the category in database - $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1", + $result = SQL_QUERY_ESC('SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1', array(bigintval($cid)), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Category found... :-) @@ -871,55 +871,47 @@ function getCategory ($cid) { // Get a string of "mail title" and price back function getPaymentTitlePrice ($pid, $full = false) { - // Default is not found - $ret = '{--_PAYMENT_404--}'; - - // Load payment data - $result = SQL_QUERY_ESC("SELECT `mail_title`,`price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1", - array( - bigintval($pid) - ), __FUNCTION__, __LINE__); - - // Do we have an entry? - if (SQL_NUMROWS($result) == 1) { - // Payment type found... :-) - $data = SQL_FETCHARRAY($result); - - // Only title or also including price? - if ($full === false) { - $ret = $data['mail_title']; - } else { - $ret = $data['mail_title'] . ' / {%pipe,translateComma=' . $data['price'] . '%} {?POINTS?}'; - } - } // END - if - - // Free result - SQL_FREERESULT($result); + // Only title or also including price? + if ($full === false) { + $ret = getPaymentData($pid, 'main_title'); + } else { + $ret = getPaymentData($pid, 'main_title') . ' / {%pipe,getPaymentData,translateComma=' . $pid . '%} {?POINTS?}'; + } // Return result return $ret; } -// Get (basicly) the price of given payment id -function getPaymentPoints ($pid, $lookFor = 'price') { +// "Getter" for payment data (cached) +function getPaymentData ($pid, $lookFor = 'price') { // Default value... - $data[$lookFor] = -1; + $data[$lookFor] = NULL; - // Search for it in database - $result = SQL_QUERY_ESC("SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1", - array( - $lookFor, - bigintval($pid) - ), __FUNCTION__, __LINE__); + // Do we have cache? + if (isset($GLOBALS['cache_array']['payments']['id'][$pid])) { + // Use it if found to save SQL queries + die('
'.print_r($GLOBALS['cache_array']['payments'],true).'
'); + $data[$lookFor] = $GLOBALS['cache_array']['payments'][$lookFor][$pid]; - // Is the entry there? - if (SQL_NUMROWS($result) == 1) { - // Payment type found... :-) - $data = SQL_FETCHARRAY($result); - } // END - if + // Update cache hits + incrementStatsEntry('cache_hits'); + } elseif (!isExtensionActive('cache')) { + // Search for it in database + $result = SQL_QUERY_ESC('SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1', + array( + $lookFor, + bigintval($pid) + ), __FUNCTION__, __LINE__); - // Free result - SQL_FREERESULT($result); + // Is the entry there? + if (SQL_NUMROWS($result) == 1) { + // Payment type found... :-) + $data = SQL_FETCHARRAY($result); + } // END - if + + // Free result + SQL_FREERESULT($result); + } // Return value return $data[$lookFor]; @@ -970,7 +962,7 @@ function removeReceiver (&$receivers, $key, $userid, $poolId, $statsId = 0, $isB // Update 'mails_sent' if sql_patches is updated if (isExtensionInstalledAndNewer('sql_patches', '0.7.4')) { // Update the pool - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1", + SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1', array(bigintval($poolId)), __FUNCTION__, __LINE__); } // END - if $ret = 'done'; @@ -998,14 +990,14 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen // Count or sum whole table? if ($countRows === true) { // Count whole table - $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`" . $add . ' LIMIT 1', + $result = SQL_QUERY_ESC('SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`' . $add . ' LIMIT 1', array( $lookFor, $tableName ), __FUNCTION__, __LINE__); } else { // Sum whole table - $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`" . $add . ' LIMIT 1', + $result = SQL_QUERY_ESC('SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`' . $add . ' LIMIT 1', array( $lookFor, $tableName diff --git a/inc/pool/pool-user.php b/inc/pool/pool-user.php index 83032754aa..01845b720c 100644 --- a/inc/pool/pool-user.php +++ b/inc/pool/pool-user.php @@ -178,8 +178,8 @@ if (!SQL_HASZERONUMS($result_main)) { $mailData['stats_id'] = bigintval($stats_id); // Prepare content - $mailData['time'] = getPaymentPoints($mailData['payment_id'], 'time'); - $mailData['points'] = getPaymentPoints($mailData['payment_id'], 'payment'); + $mailData['time'] = getPaymentData($mailData['payment_id'], 'time'); + $mailData['points'] = getPaymentData($mailData['payment_id'], 'payment'); // Load message template $mailText = loadEmailTemplate('member_user_pool_normal', $mailData, bigintval($userid)); @@ -230,7 +230,7 @@ if (!SQL_HASZERONUMS($result_main)) { 'cat_id' => $mailData['cat_id'], 'text' => $mailData['text'], 'url' => $mailData['url'], - 'expiration' => '{%pipe,createFancyTime=' . getPaymentPoints($mailData['payment_id'], 'time') . '%}' + 'expiration' => '{%pipe,createFancyTime=' . getPaymentData($mailData['payment_id'], 'time') . '%}' ); // Yes we do, so we notify admin and sender about fully sent mail! @@ -293,7 +293,7 @@ if (!SQL_HASZERONUMS($result_main)) { // Is the userid set? if (isValidUserId($userid)) { // User does not exists, pay points back - $points = getPaymentPoints($mailData['payment_id']); + $points = getPaymentData($mailData['payment_id']); initReferralSystem(); addPointsThroughReferralSystem('pool_payback', $mailData['sender_userid'], $points); diff --git a/mailid.php b/mailid.php index fb180602e9..5413d03bc0 100644 --- a/mailid.php +++ b/mailid.php @@ -149,8 +149,8 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr array(bigintval($pool)), __FILE__, __LINE__); if (SQL_NUMROWS($result) == 1) { list($pay) = SQL_FETCHROW($result); - $time = getPaymentPoints($pay, 'time'); - $payment = getPaymentPoints($pay, 'payment'); + $time = getPaymentData($pay, 'time'); + $payment = getPaymentData($pay, 'payment'); $isValid = true; } // END - if diff --git a/mailid_top.php b/mailid_top.php index 6b2ee7bc89..1d12575417 100644 --- a/mailid_top.php +++ b/mailid_top.php @@ -151,8 +151,8 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr // Entry found? if (SQL_NUMROWS($result) == 1) { list($pay) = SQL_FETCHROW($result); - $time = getPaymentPoints($pay, 'time'); - $payment = getPaymentPoints($pay, 'payment'); + $time = getPaymentData($pay, 'time'); + $payment = getPaymentData($pay, 'payment'); $isValid = true; } // END - if