diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index 7216b4b5c4..92f31779e6 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -4,24 +4,33 @@ services: storage.attachment: class: phpbb\storage\storage arguments: + - '@dbal.conn' + - '@cache.driver' - '@storage.adapter.factory' - 'attachment' + - '%tables.storage%' tags: - { name: storage } storage.avatar: class: phpbb\storage\storage arguments: + - '@dbal.conn' + - '@cache.driver' - '@storage.adapter.factory' - 'avatar' + - '%tables.storage%' tags: - { name: storage } storage.backup: class: phpbb\storage\storage arguments: + - '@dbal.conn' + - '@cache.driver' - '@storage.adapter.factory' - 'backup' + - '%tables.storage%' tags: - { name: storage } diff --git a/phpBB/config/default/container/tables.yml b/phpBB/config/default/container/tables.yml index 6adacca0d0..f3c2282de9 100644 --- a/phpBB/config/default/container/tables.yml +++ b/phpBB/config/default/container/tables.yml @@ -60,6 +60,7 @@ parameters: tables.sitelist: '%core.table_prefix%sitelist' tables.smilies: '%core.table_prefix%smilies' tables.sphinx: '%core.table_prefix%sphinx' + tables.storage: '%core.table_prefix%storage' tables.styles: '%core.table_prefix%styles' tables.styles_template: '%core.table_prefix%styles_template' tables.styles_template_data: '%core.table_prefix%styles_template_data' diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index c26ecdb849..cb40ac547e 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -187,7 +187,12 @@ class acp_database $storage->write_stream($file, $fp); - fclose($fp); + if (is_resource($fp)) + { + fclose($fp); + } + + $storage->track_file($file); // Remove file from tmp @unlink($temp_dir . '/' . $file); diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 99675e2b29..4ab2c409ab 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -502,8 +502,8 @@ class acp_main $upload_dir_size = get_formatted_filesize($config['upload_dir_size']); - // Couldn't open Avatar dir. - $avatar_dir_size = $user->lang['NOT_AVAILABLE']; + $storage_avatar = $phpbb_container->get('storage.avatar'); + $avatar_dir_size = get_formatted_filesize($storage_avatar->get_size()); if ($posts_per_day > $total_posts) { diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index ee8b642b9b..dcab741366 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -288,6 +288,7 @@ define('SESSIONS_KEYS_TABLE', $table_prefix . 'sessions_keys'); define('SITELIST_TABLE', $table_prefix . 'sitelist'); define('SMILIES_TABLE', $table_prefix . 'smilies'); define('SPHINX_TABLE', $table_prefix . 'sphinx'); +define('STORAGE_TABLE', $table_prefix . 'storage'); define('STYLES_TABLE', $table_prefix . 'styles'); define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template'); define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data'); diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index 54515fd0a6..6202798e05 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -199,6 +199,7 @@ class upload // Check for attachment quota and free space if (!$this->check_attach_quota() || !$this->check_disk_space()) { + $this->file->remove($this->storage); return $this->file_data; } @@ -246,8 +247,15 @@ class upload { // Move the thumbnail from temp folder to the storage $fp = fopen($destination, 'rb'); + $this->storage->write_stream($destination_name, $fp); - fclose($fp); + + if (is_resource($fp)) + { + fclose($fp); + } + + $this->storage->track_file($destination_name); } else { @@ -314,8 +322,6 @@ class upload $this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED'); $this->file_data['post_attach'] = false; - $this->file->remove($this->storage); - return false; } } @@ -326,10 +332,35 @@ class upload /** * Check if there is enough free space available on disk * - * @return bool True if disk space is available, false if not + * @return bool True if disk space is available or not limited, false if not */ protected function check_disk_space() { + try + { + $free_space = $this->storage->free_space(); + + if ($free_space <= $this->file->get('filesize')) + { + if ($this->auth->acl_get('a_')) + { + $this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FULL'); + } + else + { + $this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED'); + } + + $this->file_data['post_attach'] = false; + + return false; + } + } + catch (\phpbb\storage\exception\exception $e) + { + // Do nothing + } + return true; } diff --git a/phpBB/phpbb/db/migration/data/v330/storage_track.php b/phpBB/phpbb/db/migration/data/v330/storage_track.php new file mode 100644 index 0000000000..7463e4641b --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/storage_track.php @@ -0,0 +1,132 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v330; + +use phpbb\storage\storage; + +class storage_track extends \phpbb\db\migration\container_aware_migration +{ + static public function depends_on() + { + return array( + '\phpbb\db\migration\data\v330\storage_attachment', + '\phpbb\db\migration\data\v330\storage_avatar', + '\phpbb\db\migration\data\v330\storage_backup', + ); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'storage' => array( + 'COLUMNS' => array( + 'file_id' => array('UINT', null, 'auto_increment'), + 'file_path' => array('VCHAR', ''), + 'storage' => array('VCHAR', ''), + 'filesize' => array('UINT:20', 0), + ), + 'PRIMARY_KEY' => 'file_id', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'storage', + ), + ); + } + + public function update_data() + { + return [ + ['custom', [[$this, 'track_avatars']]], + ['custom', [[$this, 'track_attachments']]], + ['custom', [[$this, 'track_backups']]], + ]; + } + + public function track_avatars() + { + /** @var storage $storage */ + $storage = $this->container->get('storage.avatar'); + + $sql = 'SELECT user_avatar + FROM ' . USERS_TABLE . " + WHERE user_avatar_type = 'avatar.driver.upload'"; + + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $avatar_group = false; + $filename = $row['user_avatar']; + + if (isset($filename[0]) && $filename[0] === 'g') + { + $avatar_group = true; + $filename = substr($filename, 1); + } + + $ext = substr(strrchr($filename, '.'), 1); + $filename = (int) $filename; + + $storage->track_file($this->config['avatar_salt'] . '_' . ($avatar_group ? 'g' : '') . $filename . '.' . $ext); + } + $this->db->sql_freeresult($result); + } + + public function track_attachments() + { + /** @var storage $storage */ + $storage = $this->container->get('storage.attachment'); + + $sql = 'SELECT physical_filename, thumbnail + FROM ' . ATTACHMENTS_TABLE; + + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $storage->track_file($row['physical_filename']); + + if ($row['thumbnail'] == 1) + { + $storage->track_file('thumb_' . $row['physical_filename']); + } + } + $this->db->sql_freeresult($result); + } + + public function track_backups() + { + /** @var storage $storage */ + $storage = $this->container->get('storage.backup'); + + $sql = 'SELECT filename + FROM ' . BACKUPS_TABLE; + + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $storage->track_file($row['filename']); + } + $this->db->sql_freeresult($result); + } +} diff --git a/phpBB/phpbb/files/filespec_storage.php b/phpBB/phpbb/files/filespec_storage.php index 8b6194fe99..5f3b895a05 100644 --- a/phpBB/phpbb/files/filespec_storage.php +++ b/phpBB/phpbb/files/filespec_storage.php @@ -288,6 +288,10 @@ class filespec_storage { $storage->delete($this->destination_file); } + else + { + @unlink($this->filename); + } } /** @@ -445,8 +449,15 @@ class filespec_storage try { $fp = fopen($this->filename, 'rb'); + $storage->write_stream($this->destination_file, $fp); - fclose($fp); + + if (is_resource($fp)) + { + fclose($fp); + } + + $storage->track_file($this->destination_file); } catch (\phpbb\storage\exception\exception $e) { diff --git a/phpBB/phpbb/storage/adapter/adapter_interface.php b/phpBB/phpbb/storage/adapter/adapter_interface.php index d57c2ba587..6d8b561c25 100644 --- a/phpBB/phpbb/storage/adapter/adapter_interface.php +++ b/phpBB/phpbb/storage/adapter/adapter_interface.php @@ -23,7 +23,7 @@ interface adapter_interface public function configure($options); /** - * Dumps content into a file. + * Dumps content into a file * * @param string path The file to be written to. * @param string content The data to write into the file. @@ -47,7 +47,7 @@ interface adapter_interface public function get_contents($path); /** - * Checks the existence of files or directories. + * Checks the existence of files or directories * * @param string $path file/directory to check * @@ -56,7 +56,7 @@ interface adapter_interface public function exists($path); /** - * Removes files or directories. + * Removes files or directories * * @param string $path file/directory to remove * @@ -65,7 +65,7 @@ interface adapter_interface public function delete($path); /** - * Rename a file or a directory. + * Rename a file or a directory * * @param string $path_orig The original file/direcotry * @param string $path_dest The target file/directory @@ -76,7 +76,7 @@ interface adapter_interface public function rename($path_orig, $path_dest); /** - * Copies a file. + * Copies a file * * @param string $path_orig The original filename * @param string $path_dest The target filename @@ -87,7 +87,7 @@ interface adapter_interface public function copy($path_orig, $path_dest); /** - * Get direct link. + * Get direct link * * @param string $path The file * @@ -95,4 +95,13 @@ interface adapter_interface * */ public function get_link($path); + + /* + * Get space available in bytes + * + * @throws \phpbb\storage\exception\exception When unable to retrieve available storage space + * + * @return float Returns available space + */ + public function free_space(); } diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index bfcdebc565..c4a95da25b 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -340,7 +340,7 @@ class local implements adapter_interface, stream_interface } /** - * Get file size. + * Get file size * * @param string $path The file * @@ -361,7 +361,7 @@ class local implements adapter_interface, stream_interface } /** - * Get file mimetype. + * Get file mimetype * * @param string $path The file * @@ -373,7 +373,7 @@ class local implements adapter_interface, stream_interface } /** - * Get image dimensions. + * Get image dimensions * * @param string $path The file * @@ -394,7 +394,7 @@ class local implements adapter_interface, stream_interface } /** - * Get image width. + * Get image width * * @param string $path The file * @@ -406,7 +406,7 @@ class local implements adapter_interface, stream_interface } /** - * Get image height. + * Get image height * * @param string $path The file * @@ -424,4 +424,19 @@ class local implements adapter_interface, stream_interface { return generate_board_url() . $this->path . $path; } + + /** + * {@inheritdoc} + */ + public function free_space() + { + $free_space = @disk_free_space($this->root_path); + + if ($free_space === false) + { + throw new exception('STORAGE_CANNOT_GET_FREE_SPACE'); + } + + return $free_space; + } } diff --git a/phpBB/phpbb/storage/exception/exception.php b/phpBB/phpbb/storage/exception/exception.php index 4eca403cc1..3a587bea3f 100644 --- a/phpBB/phpbb/storage/exception/exception.php +++ b/phpBB/phpbb/storage/exception/exception.php @@ -20,11 +20,11 @@ class exception extends runtime_exception /** * Constructor * - * @param string $message The Exception message to throw (must be a language variable). - * @param string $filename The file that caused the error. - * @param array $parameters The parameters to use with the language var. - * @param \Exception $previous The previous runtime_exception used for the runtime_exception chaining. - * @param integer $code The Exception code. + * @param string $message The Exception message to throw (must be a language variable) + * @param string $filename The file that caused the error + * @param array $parameters The parameters to use with the language var + * @param \Exception $previous The previous runtime_exception used for the runtime_exception chaining + * @param integer $code The Exception code */ public function __construct($message = '', $filename = '', $parameters = [], \Exception $previous = null, $code = 0) { diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index ae2bd5169d..6b10e6892a 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -34,7 +34,7 @@ class file_info * Stores the properties of $path file, so dont have to be consulted multiple times. * For example, when you need the width of an image, using getimagesize() you get * both dimensions, so you store both here, and when you get the height, you dont have - * to call getimagesize() again. + * to call getimagesize() again * * @var array */ @@ -54,7 +54,7 @@ class file_info } /** - * Load propertys lazily. + * Load propertys lazily * * @param string name The property name. * diff --git a/phpBB/phpbb/storage/provider/provider_interface.php b/phpBB/phpbb/storage/provider/provider_interface.php index a61845bccc..428b6eb187 100644 --- a/phpBB/phpbb/storage/provider/provider_interface.php +++ b/phpBB/phpbb/storage/provider/provider_interface.php @@ -16,28 +16,28 @@ namespace phpbb\storage\provider; interface provider_interface { /** - * Gets adapter name. + * Gets adapter name * * @return string */ public function get_name(); /** - * Gets adapter class. + * Gets adapter class * * @return \phpbb\storage\adapter\adapter_interface */ public function get_adapter_class(); /** - * Gets adapter options. + * Gets adapter options * * @return array Configuration keys */ public function get_options(); /** - * Return true if the adapter is available. + * Return true if the adapter is available * * @return bool */ diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 862b039c6a..97d71048ee 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -13,15 +13,29 @@ namespace phpbb\storage; +use phpbb\cache\driver\driver_interface as cache; +use phpbb\db\driver\driver_interface as db; + /** * @internal Experimental */ class storage { /** - * @var string + * @var \phpbb\storage\adapter\adapter_interface */ - protected $storage_name; + protected $adapter; + + /** + * @var \phpbb\db\driver\driver_interface + */ + protected $db; + + /** + * Cache driver + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; /** * @var \phpbb\storage\adapter_factory @@ -29,20 +43,31 @@ class storage protected $factory; /** - * @var \phpbb\storage\adapter\adapter_interface + * @var string */ - protected $adapter; + protected $storage_name; + + /** + * @var string + */ + protected $storage_table; /** * Constructor * + * @param \phpbb\db\driver\driver_interface $db + * @param \phpbb\cache\driver\driver_interface $cache * @param \phpbb\storage\adapter_factory $factory * @param string $storage_name + * @param string $storage_table */ - public function __construct(adapter_factory $factory, $storage_name) + public function __construct(db $db, cache $cache, adapter_factory $factory, $storage_name, $storage_table) { + $this->db = $db; + $this->cache = $cache; $this->factory = $factory; $this->storage_name = $storage_name; + $this->storage_table = $storage_table; } /** @@ -71,7 +96,7 @@ class storage } /** - * Dumps content into a file. + * Dumps content into a file * * @param string path The file to be written to. * @param string content The data to write into the file. @@ -82,6 +107,7 @@ class storage public function put_contents($path, $content) { $this->get_adapter()->put_contents($path, $content); + $this->track_file($path); } /** @@ -101,7 +127,7 @@ class storage } /** - * Checks the existence of files or directories. + * Checks the existence of files or directories * * @param string $path file/directory to check * @@ -113,7 +139,7 @@ class storage } /** - * Removes files or directories. + * Removes files or directories * * @param string $path file/directory to remove * @@ -122,10 +148,11 @@ class storage public function delete($path) { $this->get_adapter()->delete($path); + $this->untrack_file($path); } /** - * Rename a file or a directory. + * Rename a file or a directory * * @param string $path_orig The original file/direcotry * @param string $path_dest The target file/directory @@ -136,10 +163,11 @@ class storage public function rename($path_orig, $path_dest) { $this->get_adapter()->rename($path_orig, $path_dest); + $this->track_rename($path_orig, $path_dest); } /** - * Copies a file. + * Copies a file * * @param string $path_orig The original filename * @param string $path_dest The target filename @@ -150,15 +178,16 @@ class storage public function copy($path_orig, $path_dest) { $this->get_adapter()->copy($path_orig, $path_dest); + $this->track_file($path_dest); } /** - * Reads a file as a stream. + * Reads a file as a stream * * @param string $path File to read * * @throws \phpbb\storage\exception\exception When unable to open file - + * * @return resource Returns a file pointer */ public function read_stream($path) @@ -182,11 +211,13 @@ class storage } /** - * Writes a new file using a stream. + * Writes a new file using a stream + * The file needs to be tracked after using this method * * @param string $path The target file * @param resource $resource The resource - * When target file cannot be created + * + * @throws \phpbb\storage\exception\exception When target file cannot be created */ public function write_stream($path, $resource) { @@ -204,7 +235,83 @@ class storage } /** - * Get file info. + * Track file in database + * + * @param string $path The target file + * @param bool $update Update file size when already tracked + */ + public function track_file($path, $update = false) + { + $sql_ary = array( + 'file_path' => $path, + 'storage' => $this->get_name(), + ); + + // Get file, if exist update filesize, if not add new record + $sql = 'SELECT * FROM ' . $this->storage_table . ' + WHERE ' . $this->db->sql_build_array('SELECT', $sql_ary); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $file = $this->file_info($path); + $sql_ary['filesize'] = $file->size; + + $sql = 'INSERT INTO ' . $this->storage_table . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + } + else if ($update) + { + $file = $this->file_info($path); + $sql = 'UPDATE ' . $this->storage_table . ' + SET filesize = ' . $file->size . ' + WHERE ' . $this->db->sql_build_array('SELECT', $sql_ary); + $this->db->sql_query($sql); + } + + $this->cache->destroy('_storage_' . $this->get_name() . '_totalsize'); + $this->cache->destroy('_storage_' . $this->get_name() . '_numfiles'); + } + + /** + * Untrack file + * + * @param string $path The target file + */ + public function untrack_file($path) + { + $sql_ary = array( + 'file_path' => $path, + 'storage' => $this->get_name(), + ); + + $sql = 'DELETE FROM ' . $this->storage_table . ' + WHERE ' . $this->db->sql_build_array('DELETE', $sql_ary); + $this->db->sql_query($sql); + + $this->cache->destroy('_storage_' . $this->get_name() . '_totalsize'); + $this->cache->destroy('_storage_' . $this->get_name() . '_numfiles'); + } + + /** + * Rename tracked file + * + * @param string $path_orig The original file/direcotry + * @param string $path_dest The target file/directory + */ + protected function track_rename($path_orig, $path_dest) + { + $sql = 'UPDATE ' . $this->storage_table . " + SET file_path = '" . $this->db->sql_escape($path_dest) . "' + WHERE file_path = '" . $this->db->sql_escape($path_orig) . "' + AND storage = '" . $this->db->sql_escape($this->get_name()) . "'"; + $this->db->sql_query($sql); + } + + /** + * Get file info * * @param string $path The file * @@ -214,7 +321,7 @@ class storage */ public function file_info($path) { - return new file_info($this->adapter, $path); + return new file_info($this->get_adapter(), $path); } /** @@ -229,4 +336,66 @@ class storage { return $this->get_adapter()->get_link($path); } + + /** + * Get total storage size + * + * @return int Size in bytes + */ + public function get_size() + { + $total_size = $this->cache->get('_storage_' . $this->get_name() . '_totalsize'); + + if ($total_size === false) + { + $sql = 'SELECT SUM(filesize) AS totalsize + FROM ' . $this->storage_table . " + WHERE storage = '" . $this->db->sql_escape($this->get_name()) . "'"; + $result = $this->db->sql_query($sql); + + $total_size = (int) $this->db->sql_fetchfield('totalsize'); + $this->cache->put('_storage_' . $this->get_name() . '_totalsize', $total_size); + + $this->db->sql_freeresult($result); + } + + return (int) $total_size; + } + + /** + * Get number of storage files + * + * @return int Number of files + */ + public function get_num_files() + { + $number_files = $this->cache->get('_storage_' . $this->get_name() . '_numfiles'); + + if ($number_files === false) + { + $sql = 'SELECT COUNT(file_id) AS numfiles + FROM ' . $this->storage_table . " + WHERE storage = '" . $this->db->sql_escape($this->get_name()) . "'"; + $result = $this->db->sql_query($sql); + + $number_files = (int) $this->db->sql_fetchfield('numfiles'); + $this->cache->put('_storage_' . $this->get_name() . '_numfiles', $number_files); + + $this->db->sql_freeresult($result); + } + + return (int) $number_files; + } + + /** + * Get space available in bytes + * + * @throws \phpbb\storage\exception\exception When unable to retrieve available storage space + * + * @return float Returns available space + */ + public function free_space() + { + return $this->get_adapter()->free_space(); + } } diff --git a/phpBB/phpbb/storage/stream_interface.php b/phpBB/phpbb/storage/stream_interface.php index 0ba866777a..6d0af71550 100644 --- a/phpBB/phpbb/storage/stream_interface.php +++ b/phpBB/phpbb/storage/stream_interface.php @@ -16,7 +16,7 @@ namespace phpbb\storage; interface stream_interface { /** - * Reads a file as a stream. + * Reads a file as a stream * * @param string $path File to read * @@ -27,7 +27,7 @@ interface stream_interface public function read_stream($path); /** - * Writes a new file using a stream. + * Writes a new file using a stream * * @param string $path The target file * @param resource $resource The resource diff --git a/tests/attachment/delete_test.php b/tests/attachment/delete_test.php index cefe076bbf..35dbf5d47d 100644 --- a/tests/attachment/delete_test.php +++ b/tests/attachment/delete_test.php @@ -44,9 +44,10 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case parent::setUp(); + $cache = $this->createMock('\phpbb\cache\driver\driver_interface'); $this->config = new \phpbb\config\config(array()); $this->db = $this->new_dbal(); - $db = $this->db; + $db_mock = $this->createMock('\phpbb\db\driver\driver_interface'); $this->resync = new \phpbb\attachment\resync($this->db); $this->filesystem = $this->createMock('\phpbb\filesystem\filesystem', array('remove', 'exists')); $this->filesystem->expects($this->any()) @@ -61,7 +62,7 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case $adapter_factory_mock->expects($this->any()) ->method('get') ->willReturn($adapter); - $this->storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $this->storage = new \phpbb\storage\storage($db_mock, $cache, $adapter_factory_mock, '', ''); $this->dispatcher = new \phpbb_mock_event_dispatcher(); $this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage); } diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php index a9567510c8..f1df81bc8a 100644 --- a/tests/attachment/upload_test.php +++ b/tests/attachment/upload_test.php @@ -86,7 +86,9 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case )); $config = $this->config; $this->db = $this->new_dbal(); + $db_mock = $this->createMock('\phpbb\db\driver\driver_interface'); $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), $this->config, $this->db, $phpbb_root_path, $phpEx); + $cache_mock = $this->createMock('\phpbb\cache\driver\driver_interface'); $this->request = $this->createMock('\phpbb\request\request'); $this->filesystem = new \phpbb\filesystem\filesystem(); @@ -109,7 +111,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $adapter_factory_mock->expects($this->any()) ->method('get') ->willReturn($adapter); - $this->storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $this->storage = new \phpbb\storage\storage($db_mock, $cache_mock, $adapter_factory_mock, '', ''); $factory_mock = $this->getMockBuilder('\phpbb\files\factory') ->disableOriginalConstructor() diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 2866a1673d..c390eac883 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -30,6 +30,8 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case global $phpbb_root_path, $phpEx; // Mock phpbb_container + + $cache = $this->createMock('\phpbb\cache\driver\driver_interface'); $phpbb_container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); $phpbb_container->expects($this->any()) ->method('get') @@ -38,15 +40,15 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case $filesystem = new \phpbb\filesystem\filesystem(); $adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); $adapter->configure(['path' => 'images/avatars/upload']); + $db = $this->createMock('\phpbb\db\driver\driver_interface'); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); $adapter_factory_mock->expects($this->any()) ->method('get') ->willReturn($adapter); - $storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $storage = new \phpbb\storage\storage($db, $cache, $adapter_factory_mock, '', ''); // Prepare dependencies for avatar manager and driver $this->config = new \phpbb\config\config(array()); - $cache = $this->createMock('\phpbb\cache\driver\driver_interface'); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index d4feeaad22..2007aad194 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -298,13 +298,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case $db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); - $adapter->configure(['path' => 'files']); - $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); - $adapter_factory_mock->expects($this->any()) - ->method('get') - ->willReturn($adapter); - $storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $storage = $this->createMock('\phpbb\storage\storage'); // Create auth mock $auth = $this->createMock('\phpbb\auth\auth'); diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index b51dabbba0..e6610cbabb 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -35,13 +35,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); - $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); - $adapter->configure(['path' => 'files']); - $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); - $adapter_factory_mock->expects($this->any()) - ->method('get') - ->willReturn($adapter); - $storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $storage = $this->createMock('\phpbb\storage\storage'); // Works as a workaround for tests $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage)); diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index d882c106ac..255d52bde0 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -56,6 +56,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c // Database $this->db = $this->new_dbal(); $db = $this->db; + $db_mock = $this->createMock('\phpbb\db\driver\driver_interface'); // Auth $auth = $this->createMock('\phpbb\auth\auth'); @@ -92,13 +93,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); // Storage - $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); - $adapter->configure(['path' => 'files']); - $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); - $adapter_factory_mock->expects($this->any()) - ->method('get') - ->willReturn($adapter); - $storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $storage = $this->createMock('\phpbb\storage\storage'); // User $user = $this->createMock('\phpbb\user', array(), array( diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index b35510113a..50761d72ca 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -87,7 +87,10 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case { global $db, $phpbb_container, $phpbb_root_path; + $cache = $this->createMock('\phpbb\cache\driver\driver_interface'); + $db = $this->new_dbal(); + $db_mock = $this->createMock('\phpbb\db\driver\driver_interface'); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); @@ -98,7 +101,7 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case $adapter_factory_mock->expects($this->any()) ->method('get') ->willReturn($adapter); - $storage = new \phpbb\storage\storage($adapter_factory_mock, ''); + $storage = new \phpbb\storage\storage($db_mock, $cache, $adapter_factory_mock, '', ''); // Works as a workaround for tests $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage));