2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/22/2009 *
4 * =================== Last change: 10/22/2009 *
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 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
31 ************************************************************************/
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
39 foreach (array('guest','member','admin') as $menu) {
41 $result = sqlQueryEscaped("SELECT `action`, `what` FROM `{?_MYSQL_PREFIX?}_%s_menu` ORDER BY `action` ASC,`what` ASC",
42 array($menu), __FILE__, __LINE__);
48 while ($entry = sqlFetchArray($result)) {
49 // Is the menu entry set?
50 if (!isset($menus['menu'][$entry['action']][$entry['what']])) {
52 $menus['menu'][$entry['action']][$entry['what']] = 1;
54 // Double entry, so get count
55 if (is_null($entry['what'])) {
57 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', TRUE, ' AND `what` IS NULL');
60 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', TRUE, sprintf(" AND `what`='%s'", $entry['what']));
62 //* DEBUG: */ debugOutput('menu='.$menu.',action='.$entry['action'].',what='.$entry['what'].',entries='.$entries);
64 // Only remove if we have at least 2 entries from same menu
66 // Remove all except one
67 if (is_null($entry['what'])) {
68 // Main menu is double
69 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` IS NULL LIMIT %s",
74 ), __FILE__, __LINE__);
77 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s' LIMIT %s",
83 ), __FILE__, __LINE__);
90 sqlFreeResult($result);
95 // Now insert our unqiue key for action-what combination
96 addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP INDEX `action_what`', $menu));
97 addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE INDEX `action_what` (`action`, `what`)', $menu));
99 // Now insert our unqiue key for what
100 addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP INDEX `what`', $menu));
101 addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE INDEX `what` (`what`)', $menu));
104 runFilterChain('run_sqls');