From 3fc95231ba85cc8c292b81bf502d4d7fab85ca8b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 21 Nov 2009 17:54:07 +0000 Subject: [PATCH] Now total received mails are reduced if no entry in user_stats_data is found --- inc/mysql-manager.php | 21 +++++++++++++++++---- inc/pool/pool-bonus.php | 6 +++--- inc/pool/pool-user.php | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 0e41c93d78..c9fad71c38 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -2083,16 +2083,29 @@ ORDER BY ur.refid ASC", // Recuce the amount of received emails for the receipients for given email function reduceRecipientReceivedMails ($column, $id, $count) { // Search for mail in database - $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s", + $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s", array($column, bigintval($id), $count), __FUNCTION__, __LINE__); // Are there entries? if (SQL_NUMROWS($result) > 0) { // Now load all userids for one big query! - // @TODO This can be somehow rewritten $userids = array(); - while (list($userid) = SQL_FETCHROW($result)) { - $userids[$userid] = $userid; + while ($data = SQL_FETCHARRAY($result)) { + // By default we want to reduce and have no mails found + $num = 0; + + // We must now look if he has already confirmed this mail, so might sound double, but it may resolve problems + // @TODO Rewrite this to a filter + if ((isset($data['stats_id'])) && ($data['stats_id'] > 0)) { + // User email + $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='mailid' AND `stats_data`=%s", bigintval($data['stats_id']))); + } elseif ((isset($data['bonus_id'])) && ($data['bonus_id'] > 0)) { + // Bonus mail + $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='bonusid' AND `stats_data`=%s", bigintval($data['bonus_id']))); + } + + // Reduce this users total received emails? + if ($num === 0) $userids[$data['userid']] = $data['userid']; } // END - while // Now update all user accounts diff --git a/inc/pool/pool-bonus.php b/inc/pool/pool-bonus.php index 9ab55f8806..6baa5b7705 100644 --- a/inc/pool/pool-bonus.php +++ b/inc/pool/pool-bonus.php @@ -125,7 +125,7 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) { if (getExtensionVersion('user') >= '0.1.4') { // Update mails received for receiver - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET emails_received=emails_received+1 WHERE `userid`=%s LIMIT 1", + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1", array(bigintval($userid)), __FILE__, __LINE__); } // END - if @@ -145,7 +145,7 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) { $P = $GLOBALS['pool_cnt']; if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2; //* DEBUG: */ print("+MEDIA/L:".__LINE__.'/'.$P."+
"); - updateMediadataEntry(array("total_send", "bonus_send"), 'add', $P); + updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P); } // END - if // Close sending system @@ -160,7 +160,7 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) { if (getExtensionVersion('mediadata') >= '0.0.4') { // Update entry (or add missing) //* DEBUG: */ print("*MEDIA/L:".__LINE__."*
"); - updateMediadataEntry(array("total_orders", "bonus_orders"), 'add', 1); + updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1); } // END - if } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) { // Update bonus pool diff --git a/inc/pool/pool-user.php b/inc/pool/pool-user.php index 7848cdc0e6..ed548551f5 100644 --- a/inc/pool/pool-user.php +++ b/inc/pool/pool-user.php @@ -153,7 +153,7 @@ if (SQL_NUMROWS($result_main) > 0) { if (getExtensionVersion('user') >= '0.1.4') { // Update mails received for receiver - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET emails_received=emails_received+1 WHERE `userid`=%s LIMIT 1", + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1", array(bigintval($userid)), __FILE__, __LINE__); } // END - if -- 2.39.5