From 0534f2dd9b93faa4167aac527790ea7885a59844 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 22 Aug 2013 16:23:26 +0800 Subject: [PATCH] MDL-36126 backup: ensure the backup_logs message does not exceed the maximum allowed length in the DB --- backup/util/loggers/database_logger.class.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backup/util/loggers/database_logger.class.php b/backup/util/loggers/database_logger.class.php index dcfddec7e19..1897af5b6a7 100644 --- a/backup/util/loggers/database_logger.class.php +++ b/backup/util/loggers/database_logger.class.php @@ -59,7 +59,13 @@ class database_logger extends base_logger { if ($this->levelcol) { $columns[$this->levelcol] = $level; } - $columns[$this->messagecol] = $message; //TODO: should this be cleaned? + $message = clean_param($message, PARAM_NOTAGS); + // Check if the message exceeds the 255 character limit in the database, + // if it does, shorten it so that it can be inserted successfully. + if (textlib::strlen($message) > 255) { + $message = textlib::substr($message, 0, 252) . '...'; + } + $columns[$this->messagecol] = $message; return $this->insert_log_record($this->logtable, $columns); } @@ -69,6 +75,6 @@ class database_logger extends base_logger { // to preserve DB logs if the whole backup/restore transaction is // rollback global $DB; - return $DB->insert_record($this->logtable, $columns, false); // Don't return inserted id + return $DB->insert_record($table, $columns, false); // Don't return inserted id } }