+<?php
+/************************************************************************
+ * MXChange v0.2.1 Start: 10/06/2009 *
+ * =============== Last change: 10/06/2009 *
+ * *
+ * -------------------------------------------------------------------- *
+ * File : fix_filters.php *
+ * -------------------------------------------------------------------- *
+ * Short description : Fixes dublicate entries in filters table *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung : Repariert doppelte Eintraege in filters-Tabelle *
+ * -------------------------------------------------------------------- *
+ * $Revision:: 1004 $ *
+ * $Date:: 2009-04-03 09:32:14 +0000 (Fri, 03 Apr 2009) $ *
+ * $Tag:: 0.2.1-FINAL $ *
+ * $Author:: quix0r $ *
+ * Needs to be in all Files and every File needs "svn propset *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2008 by Roland Haeder *
+ * For more information visit: http://www.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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
+ * MA 02110-1301 USA *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+ $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
+ require($INC);
+} // END - if
+
+// Get all filters
+$result = SQL_QUERY('SELECT
+ `filter_name`, `filter_function`
+FROM
+ `{!_MYSQL_PREFIX!}_filters`
+ORDER BY
+ `filter_name` ASC, `filter_function` ASC', __FILE__, __LINE__);
+
+// Do we have entries? (we should have!)
+if (SQL_NUMROWS($result) > 0) {
+ // Load row by row
+ while ($filter = SQL_FETCHARRAY($result)) {
+ // Now search again for this filter and get it's total count
+ $count = GET_TOTAL_DATA($filter['filter_name'], 'filters', 'filter_id', 'filter_name', true, sprintf(" AND `filter_function`='%s'", $filter['filter_function']));
+
+ // Do we have more than one entry?
+ if ($count > 1) {
+ // Then clean them up, except one
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_filters` WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT %s",
+ array($filter['filter_name'], $filter['filter_function'], ($count - 1)), __FILE__, __LINE__);
+ } // END - while
+ } // END - while
+} else {
+ // @TODO Why does this happen? In installation phase of sql_patches?
+ debug_report_bug(basename(__FILE__) . ' did run with no filters in database.');
+}
+
+// Free result
+SQL_FREERESULT($result);
+
+// Now insert our unqiue key
+SQL_QUERY("ALTER TABLE `{!_MYSQL_PREFIX!}_filters` ADD UNIQUE `name_function` (`filter_name` , `filter_function`)", __FILE__, __LINE__);
+
+// [EOF]
+?>