From cc7178a6e0731d03ada3d0425b4b59b3976f17a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 9 Jun 2018 16:37:57 +0200 Subject: [PATCH] [ticket/15342] Small improvements to storage PHPBB3-15342 --- phpBB/includes/acp/acp_database.php | 2 ++ phpBB/phpbb/attachment/upload.php | 1 + phpBB/phpbb/storage/storage.php | 52 +++++++---------------------- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index c26ecdb849..b6dbc4bec2 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -189,6 +189,8 @@ class acp_database fclose($fp); + $storage->track_file($file); + // Remove file from tmp @unlink($temp_dir . '/' . $file); diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index 54515fd0a6..3a983addc3 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -248,6 +248,7 @@ class upload $fp = fopen($destination, 'rb'); $this->storage->write_stream($destination_name, $fp); fclose($fp); + $this->storage->track_file($destination_name); } else { diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 6e00520b3c..a9f48827ae 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -96,15 +96,8 @@ class storage */ public function put_contents($path, $content) { - try - { - $this->get_adapter()->put_contents($path, $content); - $this->track_file($path); - } - catch (\Exception $e) - { - throw $e; - } + $this->get_adapter()->put_contents($path, $content); + $this->track_file($path); } /** @@ -144,15 +137,8 @@ class storage */ public function delete($path) { - try - { - $this->get_adapter()->delete($path); - $this->untrack_file($path); - } - catch (\Exception $e) - { - throw $e; - } + $this->get_adapter()->delete($path); + $this->untrack_file($path); } /** @@ -166,16 +152,9 @@ class storage */ public function rename($path_orig, $path_dest) { - try - { - $this->get_adapter()->rename($path_orig, $path_dest); - $this->untrack_file($path_orig); - $this->track_file($path_dest); - } - catch (\Exception $e) - { - throw $e; - } + $this->get_adapter()->rename($path_orig, $path_dest); + $this->untrack_file($path_orig); + $this->track_file($path_dest); } /** @@ -189,15 +168,8 @@ class storage */ public function copy($path_orig, $path_dest) { - try - { - $this->get_adapter()->copy($path_orig, $path_dest); - $this->track_file($path_dest); - } - catch (\Exception $e) - { - throw $e; - } + $this->get_adapter()->copy($path_orig, $path_dest); + $this->track_file($path_dest); } /** @@ -231,6 +203,7 @@ class storage /** * Writes a new file using a stream. + * You have to track file after use this method * * @param string $path The target file * @param resource $resource The resource @@ -244,7 +217,6 @@ class storage if ($adapter instanceof stream_interface) { $adapter->write_stream($path, $resource); - $this->track_file($path); // Not sure if here, or after close the file } else { @@ -337,9 +309,9 @@ class storage FROM ' . $this->storage_table . " WHERE storage = '" . $this->get_name() . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $total = (int) $this->db->sql_fetchfield('total'); $this->db->sql_freeresult($result); - return $row['total']; + return $row; } }