Bug with multiple registration of filters fixed (see fix_filters.php for details)
authorRoland Häder <roland@mxchange.org>
Tue, 6 Oct 2009 19:09:04 +0000 (19:09 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 6 Oct 2009 19:09:04 +0000 (19:09 +0000)
.gitattributes
inc/db/lib-mysql3.php
inc/extensions.php
inc/extensions/ext-sql_patches.php
inc/fix_filters.php [new file with mode: 0644]
inc/functions.php
inc/mysql-manager.php

index 35f2646bcd38352d10663c15f19e144ef3579537..7eb12c044ddb8f7a7d0e1755d5606500f7346185 100644 (file)
@@ -168,6 +168,7 @@ inc/extensions/ext-wernis.php -text
 inc/extensions/ext-yoomedia.php -text
 inc/fatal_errors.php -text
 inc/filters.php -text
+inc/fix_filters.php -text
 inc/footer.php -text
 inc/functions.php -text
 inc/gen_mediadata.php -text
index e07cd405b535edf5239bf4120767c76b1fb07f2f..0d97094c82d13cc01ddc966b90450e57e7fd62cf 100644 (file)
@@ -70,11 +70,12 @@ function SQL_QUERY ($sql_string, $F, $L) {
        $querytimeBefore = array_sum(explode(' ', microtime()));
 
        // Run SQL command
-       //* DEBUG: */ echo $sql_string."<br />\n";
+       //* DEBUG: */ print $sql_string."<br />\n";
        $result = mysql_query($sql_string, SQL_GET_LINK())
                or addFatalMessage(__FUNCTION__, __LINE__, $F." (".$L."):".mysql_error()."<br />
 Query string:<br />
 ".$sql_string);
+       //* DEBUG: */ print __LINE__ . ': numRows=' . SQL_NUMROWS($result) . ',affected=' . SQL_AFFECTEDROWS() . "<br />\n";
 
        // Ending time
        $querytimeAfter = array_sum(explode(' ', microtime()));
index 5fb56a2765bebf70eacbcc594e2ac620be0b460a..22f218150d7cfc16d48aa0c5c416eb67d3827d7a 100644 (file)
@@ -549,7 +549,7 @@ function EXTENSION_UPDATE ($ext_name, $ext_ver, $dry_run = false) {
                // And load SQL queries in order of version history
                for ($idx = ($start + 1); $idx < count($history); $idx++) {
                        // Set current extension name
-                       //* DEBUG: */ print __FUNCTION__.'['.__LINE__.':] ext_name='.$ext_name.'<br />';
+                       //* DEBUG: */ print __FUNCTION__.'['.__LINE__.':] ext_name='.$ext_name."<br />\n";
                        EXT_SET_CURR_NAME($ext_name);
 
                        // Set extension version
index e4016d1815390ed1fe3fb5170ad283f3abea85a5..ecb7ec650d754ee35f7aa86b4dd7f9381ae0dbeb 100644 (file)
 if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
        require($INC);
-}
+} // END - if
 
 // Version number
-EXT_SET_VERSION('0.6.2');
+EXT_SET_VERSION('0.6.3');
 
 // Version history array (add more with , '0.1.0' and so on)
-EXT_SET_VER_HISTORY(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2', '0.4.3', '0.4.4', '0.4.5', '0.4.6', '0.4.7', '0.4.8', '0.4.9', '0.5.0', '0.5.1', '0.5.2', '0.5.3', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.5.9', '0.6.0', '0.6.1', '0.6.2'));
+EXT_SET_VER_HISTORY(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2', '0.4.3', '0.4.4', '0.4.5', '0.4.6', '0.4.7', '0.4.8', '0.4.9', '0.5.0', '0.5.1', '0.5.2', '0.5.3', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.5.9', '0.6.0', '0.6.1', '0.6.2', '0.6.3'));
 
 switch ($EXT_LOAD_MODE)
 {
@@ -681,6 +681,14 @@ PRIMARY KEY (`filter_id`)
                                // Update notes (these will be set as task text!)
                                EXT_SET_UPDATE_NOTES("Abh&auml;ngigkeit von <u>ext-user</u> gesetzt.");
                                break;
+
+                       case '0.6.3': // SQL queries for v0.6.3
+                               // Update notes (these will be set as task text!)
+                               EXT_SET_UPDATE_NOTES("Filter-Tabelle bereinigt um doppelte Eintr&auml;ge und Unique-Key auf <em>filter_name</em> und <em>filter_function</em> zusammen gesetzt.");
+
+                               // Include special filte
+                               loadIncludeOnce('inc/fix_filters.php');
+                               break;
                }
                break;
 
diff --git a/inc/fix_filters.php b/inc/fix_filters.php
new file mode 100644 (file)
index 0000000..6061153
--- /dev/null
@@ -0,0 +1,79 @@
+<?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]
+?>
index 5f9e1229ade302b33056d1ada5faeb8d7d17c4b0..db721a542e5b3e9aaa02ab60781e010421b0aeb1 100644 (file)
@@ -3430,7 +3430,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
                // Exclude '.', '..' and entries in $excludeArray automatically
                if (in_array($baseFile, $excludeArray, true))  {
                        // Exclude them
-                       //* DEBUG: */ print 'excluded=' . $baseFile . '<br />';
+                       //* DEBUG: */ print 'excluded=' . $baseFile . "<br />\n";
                        continue;
                } // END - if
 
@@ -3444,9 +3444,9 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
                // Check if the base filename matches an exclusion pattern and if the pattern is not empty
                if ((!empty($excludePattern)) && (preg_match($excludePattern, $baseFile, $match))) {
                        // These Lines are only for debugging!!
-                       //* DEBUG: */ print 'baseDir:' . $baseDir . '<br />';
-                       //* DEBUG: */ print 'baseFile:' . $baseFile . '<br />';
-                       //* DEBUG: */ print 'FQFN:' . $FQFN . '<br />';
+                       //* DEBUG: */ print 'baseDir:' . $baseDir . "<br />\n";
+                       //* DEBUG: */ print 'baseFile:' . $baseFile . "<br />\n";
+                       //* DEBUG: */ print 'FQFN:' . $FQFN . "<br />\n";
 
                        // Exclude this one
                        continue;
index 491bf296ffee12acb3e81cacc81c5a8297464957..23f4621a6df002b9b2f957d673a0403d093596d6 100644 (file)
@@ -1796,18 +1796,18 @@ function updateConfiguration ($entries, $values, $updateMode='') {
                        if (!empty($updateMode)) {
                                // Update entry
                                // @TODO Find a way for updating $_CONFIG here
-                               $all .= sprintf("%s=%s%s%s,", $entry, $entry, $updateMode, (float)$values[$idx]);
+                               $all .= sprintf("`%s`=%s%s%s,", $entry, $entry, $updateMode, (float)$values[$idx]);
                        } else {
                                // Check if string or number
                                if (($values[$idx] + 0) === $values[$idx]) {
                                        // Number detected
-                                       $all .= sprintf("%s=%s,", $entry, (float)$values[$idx]);
+                                       $all .= sprintf("`%s`=%s,", $entry, (float)$values[$idx]);
                                } elseif ($values[$idx] == 'UNIX_TIMESTAMP()') {
                                        // Function UNIX_TIMESTAMP() detected
-                                       $all .= sprintf("%s=%s,", $entry, $values[$idx]);
+                                       $all .= sprintf("`%s`=%s,", $entry, $values[$idx]);
                                } else {
                                        // String detected
-                                       $all .= sprintf("%s='%s',", $entry, SQL_ESCAPE($values[$idx]));
+                                       $all .= sprintf("`%s`='%s',", $entry, SQL_ESCAPE($values[$idx]));
                                }
                        }