From 00959494a6abe4e474e634aa99cae4f8baef4ebd Mon Sep 17 00:00:00 2001 From: peterbulmer Date: Thu, 30 Oct 2008 01:39:45 +0000 Subject: [PATCH] MDL-17038 - truncate overlength varchar fields before attempting to insert Signed-off-by: Peter Bulmer Author: Peter Bulmer --- auth/mnet/auth.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php index 6a0944eb503..89cc4945ed1 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; + } + + } ?>