From 721cb8678d00d3c8c1e04e4022489f5b997c6424 Mon Sep 17 00:00:00 2001 From: vyshane Date: Mon, 24 Apr 2006 02:24:18 +0000 Subject: [PATCH] Bug #5254 - live logs Cleanup for duplicate module/action combinations. Added id field for log_display table and added an index moduleaction. --- lib/db/migrate2utf8.xml | 8 ++++---- lib/db/mysql.php | 36 +++++++++++++++++++++++++++++++++++- lib/db/mysql.sql | 2 ++ lib/db/postgres7.php | 32 ++++++++++++++++++++++++++++++++ lib/db/postgres7.sql | 10 ++++++---- 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/lib/db/migrate2utf8.xml b/lib/db/migrate2utf8.xml index 7e4733f05a..3ba7dfc61b 100755 --- a/lib/db/migrate2utf8.xml +++ b/lib/db/migrate2utf8.xml @@ -208,10 +208,10 @@ - - - - + + + +
diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 847ae403c8..21c457d175 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -1794,7 +1794,41 @@ function main_upgrade($oldversion=0) { table_column('user','lastname','lastname','varchar','100','','','not null'); } + if ($oldversion < 2006042000) { + // Look through table log_display and get rid of duplicates. + $rs = get_recordset_sql('SELECT DISTINCT * FROM '.$CFG->prefix.'log_display'); + + // Drop the log_display table and create it back with an id field. + execute_sql("DROP TABLE {$CFG->prefix}log_display", false); + + modify_database('', "CREATE TABLE prefix_log_display ( + `id` int(10) unsigned NOT NULL auto_increment, + `module` varchar(30), + `action` varchar(40), + `mtable` varchar(30), + `field` varchar(50), + PRIMARY KEY (`id`) + ) TYPE=MyISAM"); + + // Add index to ensure that module and action combination is unique. + modify_database('', "ALTER TABLE prefix_log_display ADD UNIQUE `moduleaction`(`module` , `action`)"); + + // Insert the records back in, sans duplicates. + if ($rs && $rs->RecordCount() > 0) { + while (!$rs->EOF) { + $sql = "INSERT INTO {$CFG->prefix}log_display ". + "VALUES('', '".$rs->fields['module']."', ". + "'".$rs->fields['action']."', ". + "'".$rs->fields['mtable']."', ". + "'".$rs->fields['field']."')"; + + execute_sql($sql, false); + $rs->MoveNext(); + } + } + } + return $result; } -?> +?> \ No newline at end of file diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 92cb9a9d0e..d93157a0b3 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -432,11 +432,13 @@ CREATE TABLE `prefix_log` ( # CREATE TABLE `prefix_log_display` ( + `id` int(10) unsigned NOT NULL auto_increment, `module` varchar(20) NOT NULL default '', `action` varchar(20) NOT NULL default '', `mtable` varchar(20) NOT NULL default '', `field` varchar(40) NOT NULL default '' ) TYPE=MyISAM COMMENT='For a particular module/action, specifies a moodle table/field.'; +ALTER TABLE prefix_log_display ADD UNIQUE `moduleaction`(`module` , `action`); # -------------------------------------------------------- # diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 713e0ece65..3802b023e0 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -1492,6 +1492,38 @@ function main_upgrade($oldversion=0) { table_column('course_modules','','visibleold','integer','1','unsigned','1','not null', 'visible'); } + if ($oldversion < 2006042000) { + // Look through table log_display and get rid of duplicates. + $rs = get_recordset_sql('SELECT DISTINCT * FROM '.$CFG->prefix.'log_display'); + + // Drop the log_display table and create it back with an id field. + execute_sql("DROP TABLE {$CFG->prefix}log_display", false); + + modify_database('', "CREATE TABLE prefix_log_display ( + id SERIAL PRIMARY KEY, + module varchar(30) NOT NULL default '', + action varchar(40) NOT NULL default '', + mtable varchar(30) NOT NULL default '', + field varchar(50) NOT NULL default '')"); + + // Add index to ensure that module and action combination is unique. + modify_database('', 'CREATE INDEX prefix_log_display_moduleaction ON prefix_log_display (module,action)'); + + // Insert the records back in, sans duplicates. + if ($rs && $rs->RecordCount() > 0) { + while (!$rs->EOF) { + $sql = "INSERT INTO {$CFG->prefix}log_display ". + "VALUES('', '".$rs->fields['module']."', ". + "'".$rs->fields['action']."', ". + "'".$rs->fields['mtable']."', ". + "'".$rs->fields['field']."')"; + + execute_sql($sql, false); + $rs->MoveNext(); + } + } + } + return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index ca5ea44a2e..71ba19c7c0 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -271,11 +271,13 @@ CREATE INDEX prefix_log_userid_idx ON prefix_log (userid); CREATE INDEX prefix_log_info_idx ON prefix_log (info); CREATE TABLE prefix_log_display ( - module varchar(20) NOT NULL default '', - action varchar(20) NOT NULL default '', - mtable varchar(20) NOT NULL default '', - field varchar(40) NOT NULL default '' + id SERIAL PRIMARY KEY, + module varchar(30) NOT NULL default '', + action varchar(40) NOT NULL default '', + mtable varchar(30) NOT NULL default '', + field varchar(50) NOT NULL default '' ); +CREATE INDEX prefix_log_display_moduleaction ON prefix_log_display (module,action); CREATE TABLE prefix_message ( id SERIAL PRIMARY KEY, -- 2.39.5