Removed deprecated 'hidden' column from mod_reg table.
[mailer.git] / inc / fix_user_points.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 07/04/2011 *
4  * ===================                          Last change: 07/04/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : fix_user_points.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : Fixes dublicate entries in user_points table     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Repariert doppelte Eintraege in user_points      *
12  * -------------------------------------------------------------------- *
13  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         die();
36 } // END - if
37
38 // Get all user points
39 $result = sqlQuery('SELECT
40         `userid`,
41         `points`,
42         `locked_points`,
43         `order_points`,
44         `locked_order_points`
45 FROM
46         `{?_MYSQL_PREFIX?}_user_points`
47 WHERE
48         `ref_depth`=0
49 ORDER BY
50         `userid` ASC', __FILE__, __LINE__);
51
52 // Are there entries? (there should be!)
53 if (!ifSqlHasZeroNums($result)) {
54         // Load row by row
55         while ($row = sqlFetchArray($result)) {
56                 // Update the database again
57                 foreach (array_keys($row) as $column) {
58                         // Not userid itself
59                         if ($column != 'userid') {
60                                 // Update amount
61                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth` IS NULL",
62                                         array(
63                                                 $column,
64                                                 $column,
65                                                 $row[$column],
66                                                 $row['userid']
67                                         ), __FILE__, __LINE__);
68
69                                 // Nothing has been updated?
70                                 if (ifSqlHasZeroAffectedRows()) {
71                                         // Then insert it
72                                         sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `%s`) VALUES (%s,NULL,%s)",
73                                                 array(
74                                                         $column,
75                                                         $row['userid'],
76                                                         $row[$column]
77                                                 ), __FILE__, __LINE__);
78                                 } // END - if
79                         } // END - if
80                 } // END - foreach
81         } // END - while
82 } // END - if
83
84 // Free result
85 sqlFreeResult($result);
86
87 // Remove all entries
88 sqlQuery('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `ref_depth`=0', __FILE__, __LINE__);
89
90 // [EOF]
91 ?>