From 0851db137e420b90617f47b77de2302e770f5f02 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 4 Jul 2011 01:27:20 +0000 Subject: [PATCH] Required fix for NULL vs. 0 in user_points --- .gitattributes | 1 + doubler.php | 4 +- inc/extensions/ext-user.php | 12 +++++- inc/filter/online_filter.php | 8 ++-- inc/fix_user_points.php | 69 +++++++++++++++++++++++++++++++++ inc/functions.php | 10 ++--- inc/libs/register_functions.php | 2 +- inc/mysql-manager.php | 6 +-- ref.php | 2 +- 9 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 inc/fix_user_points.php diff --git a/.gitattributes b/.gitattributes index 5000e2d9d7..5b6d060869 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/doubler.php b/doubler.php index 16aceb6e3e..306e8f01ab 100644 --- a/doubler.php +++ b/doubler.php @@ -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__); diff --git a/inc/extensions/ext-user.php b/inc/extensions/ext-user.php index 5fdfa40d1b..20529d418d 100644 --- a/inc/extensions/ext-user.php +++ b/inc/extensions/ext-user.php @@ -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ü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ür Referal-Ebene 0, noch NULL geschrieben wurde."); + break; } // END - switch break; diff --git a/inc/filter/online_filter.php b/inc/filter/online_filter.php index 68e73929e5..869e89f444 100644 --- a/inc/filter/online_filter.php +++ b/inc/filter/online_filter.php @@ -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 index 0000000000..bcb648ced4 --- /dev/null +++ b/inc/fix_user_points.php @@ -0,0 +1,69 @@ + diff --git a/inc/functions.php b/inc/functions.php index f539b61a2d..333de57fec 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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 diff --git a/inc/libs/register_functions.php b/inc/libs/register_functions.php index 20d35c2ce7..e98010cd66 100644 --- a/inc/libs/register_functions.php +++ b/inc/libs/register_functions.php @@ -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__); diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 8936a5a27a..4b9ee0e013 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -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 06f3030707..52a353a255 100644 --- 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')) { -- 2.39.2