Permalink
Browse files

MDL-17038 - truncate overlength varchar fields before attempting to i…

…nsert

Signed-off-by: Peter Bulmer <peter.bulmer@catalyst.net.nz>


Author: Peter Bulmer <peter.bulmer@catalyst.net.nz>
  • Loading branch information...
1 parent d5942d6 commit 00959494a6abe4e474e634aa99cae4f8baef4ebd peterbulmer committed Oct 30, 2008
Showing with 20 additions and 0 deletions.
  1. +20 −0 auth/mnet/auth.php
View
@@ -886,6 +886,7 @@ function refresh_log($array) {
unset($logEntryObj->username);
+ $logEntryObj = $this->trim_logline($logEntryObj);
$insertok = insert_record('mnet_log', addslashes_object($logEntryObj), false);
if ($insertok) {
@@ -1352,6 +1353,25 @@ function logoutpage_hook() {
}
}
+ /**
+ * 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;
+ }
+
+
}
?>

0 comments on commit 0095949

Please sign in to comment.