]> git.mxchange.org Git - mailer.git/commitdiff
Fixed 'payments' cache (all array elements must have 'id' based index)
authorRoland Häder <roland@mxchange.org>
Sun, 30 Sep 2012 20:09:09 +0000 (20:09 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 30 Sep 2012 20:09:09 +0000 (20:09 +0000)
inc/loader/load-payments.php
inc/modules/admin/what-del_email.php
inc/modules/member/what-order.php
inc/modules/order.php
inc/mysql-manager.php
inc/pool/pool-user.php
mailid.php
mailid_top.php

index c11c58f63f11391e85e8d20d47763e0f9952baaa..b4a9375b2fc8fbce310329f0712b5ca6c7505c68 100644 (file)
@@ -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();
index 2651db4b79215d083b2e2afe29551bfd4189e206..478b00bddecebd2ca14ae5185ab9858e4c9134a2 100644 (file)
@@ -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
index a44255e8acd9c33f61eadf0d3560a1fa403ad89d..f87c555b36622607d644252c06210bca5f51c8e7 100644 (file)
@@ -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')) {
index 484ba98daff96555d28ba2feef79bbd101586848..915500d4d7aba0bf78abef0429f65ad1d269ac77 100644 (file)
@@ -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']);
index 06901af009f4f6394d02650ac406bb8be74958f6..625598d66e02d782deb982ea8f7e4dc04783304a 100644 (file)
@@ -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('<pre>'.print_r($GLOBALS['cache_array']['payments'],true).'</pre>');
+               $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
index 83032754aaa984f6f3b02368d5040088563817b5..01845b720c590cf5131eda1f1b2c3c9e230b96ae 100644 (file)
@@ -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);
 
index fb180602e9ee55348b297e5995ee4db1a699d4a3..5413d03bc0db94d89b766c230375520e8916bc23 100644 (file)
@@ -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
 
index 6b2ee7bc89faeb5bac20aa584966a987140d3e99..1d125754178a75a4dd0b32c55c6112cb4a227d51 100644 (file)
@@ -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