commit 4064acaa9c167853829cda6de17d174ee98d857a
Author: Peter Bulmer <peter.bulmer@catalyst.net.nz>
Date:   Tue Oct 28 15:08:46 2008 +1300

    MDL-17038 - truncate overlength varchar fields before attempting to insert

diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php
index 6a0944e..89cc494 100644
--- a/auth/mnet/auth.php
+++ b/auth/mnet/auth.php
@@ -886,6 +886,7 @@ class auth_plugin_mnet extends auth_plugin_base {
 
             unset($logEntryObj->username);
 
+            $logEntryObj = $this->trim_logline($logEntryObj);
             $insertok = insert_record('mnet_log', addslashes_object($logEntryObj), false);
 
             if ($insertok) {
@@ -1352,6 +1353,25 @@ class auth_plugin_mnet extends auth_plugin_base {
         }
     }
 
+    /**
+     * Trims a log line from mnet peer to limit each part to a length which can be stored in our DB
+     *
+     * @param object $logline The log information to be trimmed
+     * @return object The passed logline object trimmed to not exceed storable limits
+     */
+    function trim_logline ($logline) {
+        $limits = array('ip' => 15, 'coursename' => 40, 'module' => 20, 'action' => 40,
+                        'url' => 255);
+        foreach ($limits as $property => $limit) {
+            if (isset($logline->$property)) {
+                $logline->$property = substr($logline->$property, 0, $limit);
+            }
+        }
+
+        return $logline;
+    }
+
+
 }
 
 ?>

