]> git.mxchange.org Git - mailer.git/blobdiff - inc/fix_user_points.php
Some fixes:
[mailer.git] / inc / fix_user_points.php
index bcb648ced491125b4c8b075f856c7b46bdde45fd..b4a61ae4f9618e7840689adaa45a692ca6f0ea62 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://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 *
@@ -41,8 +41,12 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Get all user points
-$result = SQL_QUERY('SELECT
-       `userid`, `points`
+$result = sqlQuery('SELECT
+       `userid`,
+       `points`,
+       `locked_points`,
+       `order_points`,
+       `locked_order_points`
 FROM
        `{?_MYSQL_PREFIX?}_user_points`
 WHERE
@@ -50,20 +54,43 @@ WHERE
 ORDER BY
        `userid` ASC', __FILE__, __LINE__);
 
-// Do we have entries? (we should have!)
-if (!SQL_HASZERONUMS($result)) {
+// Are there entries? (there should be!)
+if (!ifSqlHasZeroNums($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']);
+       while ($row = sqlFetchArray($result)) {
+               // Update the database again
+               foreach (array_keys($row) as $column) {
+                       // Not userid itself
+                       if ($column != 'userid') {
+                               // Update amount
+                               sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth` IS NULL",
+                                       array(
+                                               $column,
+                                               $column,
+                                               $row[$column],
+                                               $row['userid']
+                                       ), __FILE__, __LINE__);
+
+                               // Nothing has been updated?
+                               if (ifSqlHasZeroAffectedRows()) {
+                                       // Then insert it
+                                       sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `%s`) VALUES (%s,NULL,%s)",
+                                               array(
+                                                       $column,
+                                                       $row['userid'],
+                                                       $row[$column]
+                                               ), __FILE__, __LINE__);
+                               } // END - if
+                       } // END - if
+               } // END - foreach
        } // END - while
 } // END - if
 
 // Free result
-SQL_FREERESULT($result);
+sqlFreeResult($result);
 
 // Remove all entries
-SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `ref_depth`=0', __FILE__, __LINE__);
+sqlQuery('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `ref_depth`=0', __FILE__, __LINE__);
 
 // [EOF]
 ?>