Skip to content

Commit

Permalink
Make logs less repetitive & more informative
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Apr 22, 2024
1 parent 4d005de commit 1795267
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/midcom/db/attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 1795267

Please sign in to comment.