Required fix for NULL vs. 0 in user_points
authorRoland Häder <roland@mxchange.org>
Mon, 4 Jul 2011 01:27:20 +0000 (01:27 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 4 Jul 2011 01:27:20 +0000 (01:27 +0000)
.gitattributes
doubler.php
inc/extensions/ext-user.php
inc/filter/online_filter.php
inc/fix_user_points.php [new file with mode: 0644]
inc/functions.php
inc/libs/register_functions.php
inc/mysql-manager.php
ref.php

index 5000e2d9d759cb68211f7dc33f9c537041d09316..5b6d0608692ef7d0f1aeff251ec03d0c7dc04ef6 100644 (file)
@@ -224,6 +224,7 @@ inc/filter/user_filter.php svneol=native#text/plain
 inc/filters.php svneol=native#text/plain
 inc/fix_filters.php svneol=native#text/plain
 inc/fix_menu.php svneol=native#text/plain
+inc/fix_user_points.php svneol=native#text/plain
 inc/footer.php svneol=native#text/plain
 inc/functions.php svneol=native#text/plain
 inc/gen_mediadata.php svneol=native#text/plain
index 16aceb6e3eaf93baa3566f8987054c89159d4308..306e8f01ab44cd8ab0877a1482eb9db9b513387f 100644 (file)
@@ -102,7 +102,7 @@ if (isFormSent()) {
                                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(), 'N','N')",
                                        array(
                                                getUserData('userid'),
-                                               makeDatabaseUserId(determineReferalId()),
+                                               makeZeroToNull(determineReferalId()),
                                                bigintval(postRequestParameter('points') * 2),
                                                detectRemoteAddr()
                                        ), __FILE__, __LINE__);
@@ -120,7 +120,7 @@ if (isFormSent()) {
                                        // Okay add a refid line and apply refid percents
                                        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,0,%s,'%s',UNIX_TIMESTAMP(),'N','Y')",
                                                array(
-                                                       makeDatabaseUserId(determineReferalId()),
+                                                       makeZeroToNull(determineReferalId()),
                                                        (postRequestParameter('points') * 2 * getConfig('doubler_ref') / 100),
                                                        detectRemoteAddr()
                                                ), __FILE__, __LINE__);
index 5fdfa40d1b9dca1c814d88f9c48968702bb7e923..20529d418d0c5c236f439761f9a0654d50a07043 100644 (file)
@@ -41,10 +41,10 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.3.9');
+setThisExtensionVersion('0.4.0');
 
 // Version history array (add more with , '0.0.1' and so on)
-setExtensionVersionHistory(array('0.0.0', '0.1.0', '0.1.1', '0.1.2', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9'));
+setExtensionVersionHistory(array('0.0.0', '0.1.0', '0.1.1', '0.1.2', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0'));
 
 // Keep this extension always active!
 setExtensionAlwaysActive('Y');
@@ -434,6 +434,14 @@ PRIMARY KEY (`id`)
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Filter registriert, die das eigene {?POINTS?}-Guthaben des Mitgliedes zur&uuml;ckliefern.");
                                break;
+
+                       case '0.4.0': // SQL queries for v0.4.0
+                               // Add special fix include to fix filters
+                               addIncludeToPool('extension', 'inc/fix_user_points.php');
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Das Mitgliederguthaben musste repariert werden, da f&uuml;r Referal-Ebene 0, noch NULL geschrieben wurde.");
+                               break;
                } // END - switch
                break;
 
index 68e73929e5a53d8fc4e6b9fbce7e3ea8f874c2d9..869e89f444be2cada73f481cebf4eb2bb5c7f87a 100644 (file)
@@ -93,8 +93,8 @@ LIMIT 1",
                        getModule(),
                        $action,
                        getWhat(),
-                       makeDatabaseUserId($userid),
-                       makeDatabaseUserId(determineReferalId()),
+                       makeZeroToNull($userid),
+                       makeZeroToNull(determineReferalId()),
                        $isMember,
                        $isAdmin,
                        detectRemoteAddr(),
@@ -107,8 +107,8 @@ LIMIT 1",
                                getModule(),
                                $action,
                                getWhat(),
-                               makeDatabaseUserId($userid),
-                               makeDatabaseUserId(determineReferalId()),
+                               makeZeroToNull($userid),
+                               makeZeroToNull(determineReferalId()),
                                $isMember,
                                $isAdmin,
                                session_id(),
diff --git a/inc/fix_user_points.php b/inc/fix_user_points.php
new file mode 100644 (file)
index 0000000..bcb648c
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 07/04/2011 *
+ * ===================                          Last change: 07/04/2011 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : fix_user_points.php                              *
+ * -------------------------------------------------------------------- *
+ * Short description : Fixes dublicate entries in user_points table     *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Repariert doppelte Eintraege in user_points      *
+ * -------------------------------------------------------------------- *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * For more information visit: http://www.mxchange.org                  *
+ *                                                                      *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+       die();
+} // END - if
+
+// Get all user points
+$result = SQL_QUERY('SELECT
+       `userid`, `points`
+FROM
+       `{?_MYSQL_PREFIX?}_user_points`
+WHERE
+       `ref_depth`=0
+ORDER BY
+       `userid` ASC', __FILE__, __LINE__);
+
+// Do we have entries? (we should have!)
+if (!SQL_HASZERONUMS($result)) {
+       // Load row by row
+       while ($row = SQL_FETCHARRAY($result)) {
+               // We have to fix this amount, so first pay it directly
+               addPointsDirectly('user_null_fix', $row['userid'], $row['points']);
+       } // END - while
+} // END - if
+
+// Free result
+SQL_FREERESULT($result);
+
+// Remove all entries
+SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `ref_depth`=0', __FILE__, __LINE__);
+
+// [EOF]
+?>
index f539b61a2d36b5f7ec9f9dc6a30c37ff87ad375b..333de57fec72d155269ce177afa46889ae7a78b7 100644 (file)
@@ -2151,18 +2151,18 @@ function handleFieldWithBraces ($field) {
 }
 
 // Converts a userid so it can be used in SQL queries
-function makeDatabaseUserId ($userid) {
+function makeZeroToNull ($number) {
        // Is it a valid username?
-       if (isValidUserId($userid)) {
+       if ((!is_null($number)) && ($number > 0)) {
                // Always secure it
-               $userid = bigintval($userid);
+               $number = bigintval($number);
        } else {
                // Is not valid or zero
-               $userid = 'NULL';
+               $number = 'NULL';
        }
 
        // Return it
-       return $userid;
+       return $number;
 }
 
 // Capitalizes a string with underscores, e.g.: some_foo_string will become SomeFooString
index 20d35c2ce7ea735a8b882016511ea22486a368a8..e98010cd6650e29d41e6d3f6477fa3ab2709b0cc 100644 (file)
@@ -339,7 +339,7 @@ function doRegistration () {
                generateHash(postRequestParameter('pass1')),
                bigintval(postRequestParameter('max_mails')),
                bigintval(postRequestParameter('max_mails')),
-               makeDatabaseUserId(postRequestParameter('refid')),
+               makeZeroToNull(postRequestParameter('refid')),
                $hash,
                detectRemoteAddr(),
        ), __FUNCTION__, __LINE__);
index 8936a5a27ab69acb59aaaa1a4801cb423dba2324..4b9ee0e0138ad015586eaf8baec4091bb696f930 100644 (file)
@@ -1034,7 +1034,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
        if (!isset($GLOBALS['ref_level'])) {
                // Initialialize referal system
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal system initialized!');
-               $GLOBALS['ref_level'] = '0';
+               $GLOBALS['ref_level'] = NULL;
        } else {
                // Increase referal level
                $GLOBALS['ref_level']++;
@@ -1077,7 +1077,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
                                        $pointsColumn,
                                        $ref_points,
                                        bigintval($userid),
-                                       bigintval($GLOBALS['ref_level'])
+                                       makeZeroToNull($GLOBALS['ref_level'])
                                ), __FUNCTION__, __LINE__);
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - UPDATE! ('.SQL_AFFECTEDROWS().')');
 
@@ -1088,7 +1088,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
                                        array(
                                                $pointsColumn,
                                                bigintval($userid),
-                                               bigintval($GLOBALS['ref_level']),
+                                               makeZeroToNull($GLOBALS['ref_level']),
                                                $ref_points
                                        ), __FUNCTION__, __LINE__);
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
diff --git a/ref.php b/ref.php
index 06f3030707f18b4accdb8aa1f7a24b85fa72061b..52a353a255f9448faeea0f001a67edfe382c93d4 100644 (file)
--- a/ref.php
+++ b/ref.php
@@ -55,7 +55,7 @@ $url = 'modules.php?module=index';
 if ((isExtensionActive('user')) && (isReferalIdValid()) && (isValidUserId(determineReferalId()))) {
        // Update ref counter
        SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_clicks`=`ref_clicks`+1 WHERE `userid`=%s LIMIT 1",
-               array(makeDatabaseUserId(determineReferalId())), __FILE__, __LINE__);
+               array(makeZeroToNull(determineReferalId())), __FILE__, __LINE__);
 
        // Base URL for redirection
        switch (getConfig('refid_target')) {