From 17952675d7a3b9c25c4927bfdc35936e624cda24 Mon Sep 17 00:00:00 2001 From: flack Date: Mon, 22 Apr 2024 19:12:19 +0200 Subject: [PATCH] Make logs less repetitive & more informative --- lib/midcom/db/attachment.php | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/midcom/db/attachment.php b/lib/midcom/db/attachment.php index 6520c98b9..504afb47d 100644 --- a/lib/midcom/db/attachment.php +++ b/lib/midcom/db/attachment.php @@ -70,7 +70,8 @@ public function open(string $mode = 'w') $handle = $blob->get_handler($mode); if (!$handle) { - debug_add("Failed to open attachment with mode {$mode}, last Midgard error was: " . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); + debug_add("Failed to open attachment with mode {$mode}, last PHP error was: ", MIDCOM_LOG_WARN); + midcom::get()->debug->log_php_error(MIDCOM_LOG_WARN); return false; } @@ -335,16 +336,12 @@ public function _on_deleted() */ public function copy_from_memory($source) : bool { - $dest = $this->open(); - if (!$dest) { - debug_add('Could not open attachment for writing, last Midgard error was: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); - return false; + if ($dest = $this->open()) { + fwrite($dest, $source); + $this->close(); + return true; } - - fwrite($dest, $source); - - $this->close(); - return true; + return false; } /** @@ -355,16 +352,12 @@ public function copy_from_memory($source) : bool */ public function copy_from_handle($source) : bool { - $dest = $this->open(); - if (!$dest) { - debug_add('Could not open attachment for writing, last Midgard error was: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); - return false; + if ($dest = $this->open()) { + stream_copy_to_stream($source, $dest); + $this->close(); + return true; } - - stream_copy_to_stream($source, $dest); - - $this->close(); - return true; + return false; } /**