]> git.mjollnir.org Git - moodle.git/commitdiff
Bug #5254 - live logs
authorvyshane <vyshane>
Mon, 24 Apr 2006 02:24:18 +0000 (02:24 +0000)
committervyshane <vyshane>
Mon, 24 Apr 2006 02:24:18 +0000 (02:24 +0000)
Cleanup for duplicate module/action combinations. Added id field for
log_display table and added an index moduleaction.

lib/db/migrate2utf8.xml
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql

index 7e4733f05ac9b8614a6eddef57b16ff17d4a9fe2..3ba7dfc61bda3f73f2d2e10647acf565b13303f9 100755 (executable)
     </TABLE>
     <TABLE name="log_display">
       <FIELDS>
-        <FIELD name="module" method="NO_CONV" type="varchar" length="20" />
-        <FIELD name="action" method="NO_CONV" type="varchar" length="20" />
-        <FIELD name="mtable" method="NO_CONV" type="varchar" length="20" />
-        <FIELD name="field" method="NO_CONV" type="varchar" length="40" />
+        <FIELD name="mtable" method="NO_CONV" type="varchar" length="30" dropindex="moduleaction"/>
+        <FIELD name="field" method="NO_CONV" type="varchar" length="50" />
+        <FIELD name="module" method="NO_CONV" type="varchar" length="30" />
+        <FIELD name="action" method="NO_CONV" type="varchar" length="40" addindex="moduleaction(module(30), action(40))"/>
       </FIELDS>
     </TABLE>
     <TABLE name="message_contacts" />
index 847ae403c8393177eb342bf0d6a8249e4a52d5c0..21c457d175c8cf5e301c9c05821298ad05a77fc1 100644 (file)
@@ -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
index 92cb9a9d0eb2a3ea29878754ebf88845d96af77d..d93157a0b318e45477515272d2dc5df9110026f9 100644 (file)
@@ -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`);
 # --------------------------------------------------------
 
 #
index 713e0ece6590ae023a332f065fb75653489c6621..3802b023e0828fd8e13ac1c50ca2d9fd63bbd086 100644 (file)
@@ -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;
 }
 
index ca5ea44a2ef222b9f0876021ce72b8143537b656..71ba19c7c0fa0ba9b3c81f033bddaf5d6d2d1ddf 100644 (file)
@@ -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,