]> git.mxchange.org Git - mailer.git/blob - inc/fix_menu.php
Added patch_core.sh to all 'cored' PHP projects to ease patching of the 'core' project
[mailer.git] / inc / fix_menu.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/22/2009 *
4  * ===================                          Last change: 10/22/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : fix_menu.php                                     *
8  * -------------------------------------------------------------------- *
9  * Short description : Fixes dublicate entries in filters table         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Repariert doppelte Eintraege in filters-Tabelle  *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Get all menus
44 foreach (array('guest','member','admin') as $menu) {
45         // Query it
46         $result = SQL_QUERY_ESC("SELECT `action`, `what` FROM `{?_MYSQL_PREFIX?}_%s_menu` ORDER BY `action` ASC, `what` ASC",
47                 array($menu), __FILE__, __LINE__);
48
49         // Init array
50         $menus = array();
51
52         // Load all entries
53         while ($entry = SQL_FETCHARRAY($result)) {
54                 // Is the menu entry set?
55                 if (!isset($menus['menu'][$entry['action']][$entry['what']])) {
56                         // Not found
57                         $menus['menu'][$entry['action']][$entry['what']] = 1;
58                 } else {
59                         // Double entry, so get count
60                         if (is_null($entry['what'])) {
61                                 // Main menu
62                                 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', true, " AND `what` IS NULL");
63                         } else {
64                                 // Sub menu
65                                 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', true, sprintf(" AND `what`='%s'", $entry['what']));
66                         }
67                         //* DEBUG: */ debugOutput('menu='.$menu.',action='.$entry['action'].',what='.$entry['what'].',entries='.$entries);
68
69                         // Only remove if we have at least 2 entries from same menu
70                         if ($entries > 1) {
71                                 // Remove all except one
72                                 if (is_null($entry['what'])) {
73                                         // Main menu is double
74                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` IS NULL LIMIT %s",
75                                                 array(
76                                                         $menu,
77                                                         $entry['action'],
78                                                         ($entries - 1)
79                                                 ), __FILE__, __LINE__);
80                                 } else {
81                                         // Sub menu is double
82                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s' LIMIT %s",
83                                                 array(
84                                                         $menu,
85                                                         $entry['action'],
86                                                         $entry['what'],
87                                                         ($entries - 1)
88                                                 ), __FILE__, __LINE__);
89                                 }
90                         } // END - if
91                 }
92         } // END - while
93
94         // Free result
95         SQL_FREERESULT($result);
96
97         // Init sqls
98         initSqls();
99
100         // Now insert our unqiue key for action-what combination
101         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `action_what`", $menu));
102         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE `action_what` (`action` , `what`)", $menu));
103
104         // Now insert our unqiue key for what
105         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `what`", $menu));
106         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE `what` (`what`)", $menu));
107
108         // And run all
109         runFilterChain('run_sqls');
110 } // END - foreach
111
112 // [EOF]
113 ?>