From fb716743d23500f427c1713c6f59f8ceec3285fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 9 Aug 2017 18:56:35 +0200 Subject: [PATCH 01/13] [ticket/15311] Use storage in backups PHPBB3-15311 --- .../config/default/container/services_db.yml | 5 - .../default/container/services_storage.yml | 8 + phpBB/config/default/container/tables.yml | 1 + phpBB/includes/acp/acp_database.php | 205 +++++++++++++----- phpBB/includes/constants.php | 1 + phpBB/install/schemas/schema_data.sql | 2 + phpBB/language/en/acp/database.php | 1 + phpBB/phpbb/db/extractor/base_extractor.php | 12 +- .../db/migration/data/v330/storage_backup.php | 40 ++++ 9 files changed, 207 insertions(+), 68 deletions(-) create mode 100644 phpBB/phpbb/db/migration/data/v330/storage_backup.php diff --git a/phpBB/config/default/container/services_db.yml b/phpBB/config/default/container/services_db.yml index d538177603..c368a6f464 100644 --- a/phpBB/config/default/container/services_db.yml +++ b/phpBB/config/default/container/services_db.yml @@ -34,7 +34,6 @@ services: class: phpbb\db\extractor\mssql_extractor shared: false arguments: - - '%core.root_path%' - '@request' - '@dbal.conn.driver' @@ -42,7 +41,6 @@ services: class: phpbb\db\extractor\mysql_extractor shared: false arguments: - - '%core.root_path%' - '@request' - '@dbal.conn.driver' @@ -50,7 +48,6 @@ services: class: phpbb\db\extractor\oracle_extractor shared: false arguments: - - '%core.root_path%' - '@request' - '@dbal.conn.driver' @@ -58,7 +55,6 @@ services: class: phpbb\db\extractor\postgres_extractor shared: false arguments: - - '%core.root_path%' - '@request' - '@dbal.conn.driver' @@ -66,6 +62,5 @@ services: class: phpbb\db\extractor\sqlite3_extractor shared: false arguments: - - '%core.root_path%' - '@request' - '@dbal.conn.driver' diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index f114dc1dfe..7216b4b5c4 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -17,6 +17,14 @@ services: tags: - { name: storage } + storage.backup: + class: phpbb\storage\storage + arguments: + - '@storage.adapter.factory' + - 'backup' + tags: + - { name: storage } + # Factory storage.adapter.factory: class: phpbb\storage\adapter_factory diff --git a/phpBB/config/default/container/tables.yml b/phpBB/config/default/container/tables.yml index 4aed35710b..6adacca0d0 100644 --- a/phpBB/config/default/container/tables.yml +++ b/phpBB/config/default/container/tables.yml @@ -8,6 +8,7 @@ parameters: tables.auth_provider_oauth_token_storage: '%core.table_prefix%oauth_tokens' tables.auth_provider_oauth_states: '%core.table_prefix%oauth_states' tables.auth_provider_oauth_account_assoc: '%core.table_prefix%oauth_accounts' + tables.backups: '%core.table_prefix%backups' tables.banlist: '%core.table_prefix%banlist' tables.bbcodes: '%core.table_prefix%bbcodes' tables.bookmarks: '%core.table_prefix%bookmarks' diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index b98756a34b..ea1656d297 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -27,9 +27,10 @@ class acp_database function main($id, $mode) { global $cache, $db, $user, $template, $table_prefix, $request; - global $phpbb_root_path, $phpbb_container, $phpbb_log; + global $phpbb_root_path, $phpbb_container, $phpbb_log, $table_prefix; $this->db_tools = $phpbb_container->get('dbal.tools'); + $storage = $phpbb_container->get('storage.backup'); $user->add_lang('acp/database'); @@ -98,50 +99,103 @@ class acp_database $filename = 'backup_' . $time . '_' . unique_id(); - $extractor = $phpbb_container->get('dbal.extractor'); - $extractor->init_extractor($format, $filename, $time, $download, $store); - - $extractor->write_start($table_prefix); - - foreach ($table as $table_name) + try { - // Get the table structure - if ($structure) + $extractor = $phpbb_container->get('dbal.extractor'); + $extractor->init_extractor($format, $filename, $time, $download, $store); + + $extractor->write_start($table_prefix); + + foreach ($table as $table_name) { - $extractor->write_table($table_name); - } - else - { - // We might wanna empty out all that junk :D - switch ($db->get_sql_layer()) + // Get the table structure + if ($structure) { - case 'sqlite3': - $extractor->flush('DELETE FROM ' . $table_name . ";\n"); - break; + $extractor->write_table($table_name); + } + else + { + // We might wanna empty out all that junk :D + switch ($db->get_sql_layer()) + { + case 'sqlite3': + $extractor->flush('DELETE FROM ' . $table_name . ";\n"); + break; - case 'mssql_odbc': - case 'mssqlnative': - $extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n"); - break; + case 'mssql_odbc': + case 'mssqlnative': + $extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n"); + break; - case 'oracle': - $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n"); - break; + case 'oracle': + $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n"); + break; - default: - $extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n"); - break; + default: + $extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n"); + break; + } + } + + // Data + if ($schema_data) + { + $extractor->write_data($table_name); } } - // Data - if ($schema_data) - { - $extractor->write_data($table_name); - } + $extractor->write_end(); + } + catch (\phpbb\exception\runtime_exception $e) + { + trigger_error($e->getMessage(), E_USER_ERROR); } - $extractor->write_end(); + try + { + if ($store) + { + // Get file name + switch ($format) + { + case 'text': + $ext = '.sql'; + break; + case 'bzip2': + $ext = '.sql.gz2'; + break; + case 'gzip': + $ext = '.sql.gz'; + break; + } + + $file = $filename . $ext; + + // Copy to storage using streams + $fp = fopen(sys_get_temp_dir() . '/' . $file, 'rb'); + + if ($fp === false) + { + throw new \phpbb\exception\runtime_exception('CANNOT_OPEN_FILE'); + } + + $storage->write_stream($file, $fp); + + fclose($fp); + + // Remove file from tmp + @unlink(sys_get_temp_dir() . '/' . $file); + + // Save to database + $sql = "INSERT INTO " . $table_prefix . "backups (filename) + VALUES ('$file');"; + $db->sql_query($sql); + } + } + catch (\phpbb\exception\runtime_exception $e) + { + trigger_error($e->getMessage(), E_USER_ERROR); + } $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_BACKUP'); @@ -208,9 +262,9 @@ class acp_database trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } - $file_name = $phpbb_root_path . 'store/' . $matches[0]; + $file_name = $matches[0]; - if (!file_exists($file_name) || !is_readable($file_name)) + if (!$storage->exists($file_name)) { trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } @@ -219,8 +273,24 @@ class acp_database { if (confirm_box(true)) { - unlink($file_name); - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE'); + try + { + // Delete from storage + $storage->delete($file_name); + + // Add log entry + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE'); + + // Remove from database + $sql = "DELETE FROM " . $table_prefix . "backups + WHERE filename = '" . $file_name . "';"; + $db->sql_query($sql); + } + catch (\Exception $e) + { + trigger_error($user->lang['BACKUP_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); + } + trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action)); } else @@ -253,25 +323,51 @@ class acp_database @set_time_limit(0); - $fp = @fopen($file_name, 'rb'); - - if ($fp !== false) + try { + $fp = $storage->read_stream($file_name); + while (!feof($fp)) { echo fread($fp, 8192); } fclose($fp); } + catch (\phpbb\storage\exception\exception $e) + { + + } flush(); exit; } + // Copy file to temp folder to decompress it + $temp_file_name = sys_get_temp_dir() . '/' . $file_name; + + try + { + $stream = $storage->read_stream($file_name); + $fp = fopen($temp_file_name, 'w+b'); + + while (!feof($stream)) + { + fwrite($fp, fread($stream, 8192)); + } + + fclose($fp); + fclose($stream); + } + catch (\phpbb\storage\exception\exception $e) + { + // Error while copying file from storage to temp + exit; + } + switch ($matches[1]) { case 'sql': - $fp = fopen($file_name, 'rb'); + $fp = fopen($temp_file_name, 'rb'); $read = 'fread'; $seek = 'fseek'; $eof = 'feof'; @@ -280,7 +376,7 @@ class acp_database break; case 'sql.bz2': - $fp = bzopen($file_name, 'r'); + $fp = bzopen($temp_file_name, 'r'); $read = 'bzread'; $seek = ''; $eof = 'feof'; @@ -289,7 +385,7 @@ class acp_database break; case 'sql.gz': - $fp = gzopen($file_name, 'rb'); + $fp = gzopen($temp_file_name, 'rb'); $read = 'gzread'; $seek = 'gzseek'; $eof = 'gzeof'; @@ -368,6 +464,8 @@ class acp_database $close($fp); + @unlink($temp_file_name); + // Purge the cache due to updated data $cache->purge(); @@ -393,26 +491,25 @@ class acp_database $methods[] = $type; } - $dir = $phpbb_root_path . 'store/'; - $dh = @opendir($dir); + $sql = 'SELECT filename + FROM ' . BACKUPS_TABLE; + $result = $db->sql_query($sql); $backup_files = array(); - if ($dh) + while ($row = $db->sql_fetchrow($result)) { - while (($file = readdir($dh)) !== false) + if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $row['filename'], $matches)) { - if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches)) + if (in_array($matches[2], $methods)) { - if (in_array($matches[2], $methods)) - { - $backup_files[(int) $matches[1]] = $file; - } + $backup_files[(int) $matches[1]] = $row['filename']; } } - closedir($dh); } + $db->sql_freeresult($result); + if (!empty($backup_files)) { krsort($backup_files); diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 2fa11e4d86..ee8b642b9b 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -239,6 +239,7 @@ define('ACL_ROLES_DATA_TABLE', $table_prefix . 'acl_roles_data'); define('ACL_ROLES_TABLE', $table_prefix . 'acl_roles'); define('ACL_USERS_TABLE', $table_prefix . 'acl_users'); define('ATTACHMENTS_TABLE', $table_prefix . 'attachments'); +define('BACKUPS_TABLE', $table_prefix . 'backups'); define('BANLIST_TABLE', $table_prefix . 'banlist'); define('BBCODES_TABLE', $table_prefix . 'bbcodes'); define('BOOKMARKS_TABLE', $table_prefix . 'bookmarks'); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index c6a60af67b..14c63fab72 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -291,6 +291,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\attachment INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\attachment\config\path', 'files'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\provider', 'phpbb\storage\provider\local'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\config\path', 'images/avatars/upload'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\provider', 'phpbb\storage\provider\local'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\config\path', 'store'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1); diff --git a/phpBB/language/en/acp/database.php b/phpBB/language/en/acp/database.php index ab85701eaa..ac5b19d5d9 100644 --- a/phpBB/language/en/acp/database.php +++ b/phpBB/language/en/acp/database.php @@ -43,6 +43,7 @@ $lang = array_merge($lang, array( 'BACKUP_DELETE' => 'The backup file has been deleted successfully.', 'BACKUP_INVALID' => 'The selected file to backup is invalid.', + 'BACKUP_ERROR' => 'Error when saving file.', 'BACKUP_OPTIONS' => 'Backup options', 'BACKUP_SUCCESS' => 'The backup file has been created successfully.', 'BACKUP_TYPE' => 'Backup type', diff --git a/phpBB/phpbb/db/extractor/base_extractor.php b/phpBB/phpbb/db/extractor/base_extractor.php index 547c85f066..2803b89357 100644 --- a/phpBB/phpbb/db/extractor/base_extractor.php +++ b/phpBB/phpbb/db/extractor/base_extractor.php @@ -21,10 +21,6 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception; */ abstract class base_extractor implements extractor_interface { - /** - * @var string phpBB root path - */ - protected $phpbb_root_path; /** * @var \phpbb\request\request_interface @@ -84,13 +80,11 @@ abstract class base_extractor implements extractor_interface /** * Constructor * - * @param string $phpbb_root_path * @param \phpbb\request\request_interface $request * @param \phpbb\db\driver\driver_interface $db */ - public function __construct($phpbb_root_path, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) + public function __construct(\phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) { - $this->phpbb_root_path = $phpbb_root_path; $this->request = $request; $this->db = $db; $this->fp = null; @@ -164,13 +158,13 @@ abstract class base_extractor implements extractor_interface if ($store === true) { - $file = $this->phpbb_root_path . 'store/' . $filename . $ext; + $file = sys_get_temp_dir() . '/' . $filename . $ext; $this->fp = $open($file, 'w'); if (!$this->fp) { - trigger_error('FILE_WRITE_FAIL', E_USER_ERROR); + throw new \phpbb\exception\runtime_exception('FILE_WRITE_FAIL'); } } diff --git a/phpBB/phpbb/db/migration/data/v330/storage_backup.php b/phpBB/phpbb/db/migration/data/v330/storage_backup.php new file mode 100644 index 0000000000..accdfb0575 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/storage_backup.php @@ -0,0 +1,40 @@ + +* @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; + +class storage_backup extends \phpbb\db\migration\migration +{ + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'backups' => array( + 'COLUMNS' => array( + 'backup_id' => array('UINT', NULL, 'auto_increment'), + 'filename' => array('VCHAR', ''), + ), + 'PRIMARY_KEY' => 'backup_id', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('storage\\backup\\provider', \phpbb\storage\provider\local::class)), + array('config.add', array('storage\\backup\\config\\path', 'store')), + ); + } +} From 12b55beb42bb0ccd51c0052019402d29d04bf01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 28 Aug 2017 18:24:51 +0200 Subject: [PATCH 02/13] [ticket/15311] Fix code style PHPBB3-15311 --- phpBB/phpbb/db/migration/data/v330/storage_backup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migration/data/v330/storage_backup.php b/phpBB/phpbb/db/migration/data/v330/storage_backup.php index accdfb0575..316ba4c104 100644 --- a/phpBB/phpbb/db/migration/data/v330/storage_backup.php +++ b/phpBB/phpbb/db/migration/data/v330/storage_backup.php @@ -21,7 +21,7 @@ class storage_backup extends \phpbb\db\migration\migration 'add_tables' => array( $this->table_prefix . 'backups' => array( 'COLUMNS' => array( - 'backup_id' => array('UINT', NULL, 'auto_increment'), + 'backup_id' => array('UINT', null, 'auto_increment'), 'filename' => array('VCHAR', ''), ), 'PRIMARY_KEY' => 'backup_id', From 5a65208341c8b4dd0ad53ab1114b3f267a0945ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sun, 10 Sep 2017 14:40:37 +0200 Subject: [PATCH 03/13] [ticket/15311] Fix language string PHPBB3-15311 --- phpBB/language/en/acp/database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/acp/database.php b/phpBB/language/en/acp/database.php index ac5b19d5d9..6d0fc2f1e2 100644 --- a/phpBB/language/en/acp/database.php +++ b/phpBB/language/en/acp/database.php @@ -43,7 +43,7 @@ $lang = array_merge($lang, array( 'BACKUP_DELETE' => 'The backup file has been deleted successfully.', 'BACKUP_INVALID' => 'The selected file to backup is invalid.', - 'BACKUP_ERROR' => 'Error when saving file.', + 'BACKUP_ERROR' => 'Error while saving file.', 'BACKUP_OPTIONS' => 'Backup options', 'BACKUP_SUCCESS' => 'The backup file has been created successfully.', 'BACKUP_TYPE' => 'Backup type', From 6d2c815c7565123cedadbfdca25ebecc76ff168c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sun, 10 Sep 2017 14:46:37 +0200 Subject: [PATCH 04/13] [ticket/15311] Detail errors a little more PHPBB3-15311 --- phpBB/includes/acp/acp_database.php | 5 ++--- phpBB/language/en/acp/database.php | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index ea1656d297..a256f5260e 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -335,7 +335,7 @@ class acp_database } catch (\phpbb\storage\exception\exception $e) { - + // If open fails, just finish } flush(); @@ -360,8 +360,7 @@ class acp_database } catch (\phpbb\storage\exception\exception $e) { - // Error while copying file from storage to temp - exit; + trigger_error($user->lang['RESTORE_DOWNLOAD_FAIL'] . adm_back_link($this->u_action)); } switch ($matches[1]) diff --git a/phpBB/language/en/acp/database.php b/phpBB/language/en/acp/database.php index 6d0fc2f1e2..7170cefe8e 100644 --- a/phpBB/language/en/acp/database.php +++ b/phpBB/language/en/acp/database.php @@ -59,6 +59,7 @@ $lang = array_merge($lang, array( 'FILE_WRITE_FAIL' => 'Unable to write file to storage folder.', 'FULL_BACKUP' => 'Full', + 'RESTORE_DOWNLOAD_FAIL' => 'Error while copying file from storage to local temporary folder.', 'RESTORE_FAILURE' => 'The backup file may be corrupt.', 'RESTORE_OPTIONS' => 'Restore options', 'RESTORE_SELECTED_BACKUP' => 'Are you sure you want to restore the selected backup?', From e8a70dcb24f657c83e73b4e138d009822ce7584e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sun, 10 Sep 2017 14:49:28 +0200 Subject: [PATCH 05/13] [ticket/15311] Use stream_copy_to_stream PHPBB3-15311 --- phpBB/includes/acp/acp_database.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index a256f5260e..62b6b2ed07 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -350,10 +350,7 @@ class acp_database $stream = $storage->read_stream($file_name); $fp = fopen($temp_file_name, 'w+b'); - while (!feof($stream)) - { - fwrite($fp, fread($stream, 8192)); - } + stream_copy_to_stream($stream, $fp); fclose($fp); fclose($stream); From 01a8487244d924f3715e11742909318ae2a959c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 23 Oct 2017 17:02:05 +0200 Subject: [PATCH 06/13] [ticket/15311] Use cache directory if can't use system temp PHPBB3-15311 --- .../config/default/container/services_db.yml | 5 +++ .../default/container/services_files.yml | 2 + .../default/container/services_filesystem.yml | 5 +++ phpBB/includes/acp/acp_database.php | 14 ++++--- phpBB/includes/functions_compress.php | 4 +- phpBB/phpbb/cache/driver/file.php | 2 +- phpBB/phpbb/composer/installer.php | 2 +- phpBB/phpbb/db/extractor/base_extractor.php | 9 +++- phpBB/phpbb/files/types/remote.php | 16 ++++++- phpBB/phpbb/files/types/remote_storage.php | 16 ++++++- phpBB/phpbb/filesystem/filesystem.php | 42 ++++++++++++++++++- tests/attachment/upload_test.php | 2 +- tests/avatar/manager_test.php | 2 +- tests/console/thumbnail_test.php | 2 +- tests/controller/common_helper_route.php | 2 +- tests/dbal/connect_test.php | 2 +- tests/email/email_parsing_test.php | 2 +- tests/error_collector_test.php | 2 +- tests/extension/metadata_manager_test.php | 2 +- tests/feed/attachments_base_test.php | 2 +- tests/files/types_base_test.php | 2 +- tests/files/types_form_test.php | 2 +- tests/files/types_local_test.php | 2 +- tests/files/types_remote_test.php | 11 +++-- tests/files/upload_test.php | 2 +- tests/filesystem/clean_path_test.php | 2 +- tests/filesystem/is_absolute_test.php | 2 +- tests/filesystem/realpath_test.php | 4 +- tests/functional/fileupload_remote_test.php | 4 +- tests/installer/database_helper_test.php | 2 +- tests/installer/module_base_test.php | 2 +- tests/mock/extension_manager.php | 2 +- tests/security/base.php | 2 +- tests/session/check_ban_test.php | 2 +- tests/session/extract_page_test.php | 2 +- tests/storage/adapter/local_test.php | 2 +- tests/template/asset_test.php | 2 +- tests/template/template_allfolder_test.php | 2 +- tests/template/template_events_test.php | 2 +- tests/template/template_includecss_test.php | 2 +- tests/template/template_test_case.php | 4 +- .../template/template_test_case_with_tree.php | 2 +- ...phpbb_database_test_connection_manager.php | 2 +- tests/upload/filespec_test.php | 2 +- tests/upload/fileupload_test.php | 2 +- tests/viewonline/helper_test.php | 2 +- 46 files changed, 145 insertions(+), 57 deletions(-) diff --git a/phpBB/config/default/container/services_db.yml b/phpBB/config/default/container/services_db.yml index c368a6f464..b52b29e20f 100644 --- a/phpBB/config/default/container/services_db.yml +++ b/phpBB/config/default/container/services_db.yml @@ -34,6 +34,7 @@ services: class: phpbb\db\extractor\mssql_extractor shared: false arguments: + - '@filesystem' - '@request' - '@dbal.conn.driver' @@ -41,6 +42,7 @@ services: class: phpbb\db\extractor\mysql_extractor shared: false arguments: + - '@filesystem' - '@request' - '@dbal.conn.driver' @@ -48,6 +50,7 @@ services: class: phpbb\db\extractor\oracle_extractor shared: false arguments: + - '@filesystem' - '@request' - '@dbal.conn.driver' @@ -55,6 +58,7 @@ services: class: phpbb\db\extractor\postgres_extractor shared: false arguments: + - '@filesystem' - '@request' - '@dbal.conn.driver' @@ -62,5 +66,6 @@ services: class: phpbb\db\extractor\sqlite3_extractor shared: false arguments: + - '@filesystem' - '@request' - '@dbal.conn.driver' diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 96682d6713..b5310c8c6e 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -71,6 +71,7 @@ services: arguments: - '@config' - '@files.factory' + - '@filesystem' - '@language' - '@php_ini' - '@request' @@ -82,6 +83,7 @@ services: arguments: - '@config' - '@files.factory' + - '@filesystem' - '@language' - '@php_ini' - '@request' diff --git a/phpBB/config/default/container/services_filesystem.yml b/phpBB/config/default/container/services_filesystem.yml index 828f9076dd..36025755fd 100644 --- a/phpBB/config/default/container/services_filesystem.yml +++ b/phpBB/config/default/container/services_filesystem.yml @@ -1,3 +1,8 @@ +parameters: + core.filesystem.cache_temp_dir: '%core.cache_dir%tmp/' + services: filesystem: class: phpbb\filesystem\filesystem + arguments: + - '%core.filesystem.cache_temp_dir%' diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 62b6b2ed07..d345d4075e 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -21,8 +21,9 @@ if (!defined('IN_PHPBB')) class acp_database { - var $db_tools; - var $u_action; + protected $db_tools; + protected $filesystem; + public $u_action; function main($id, $mode) { @@ -30,6 +31,7 @@ class acp_database global $phpbb_root_path, $phpbb_container, $phpbb_log, $table_prefix; $this->db_tools = $phpbb_container->get('dbal.tools'); + $this->filesystem = $phpbb_container->get('filesystem'); $storage = $phpbb_container->get('storage.backup'); $user->add_lang('acp/database'); @@ -172,7 +174,9 @@ class acp_database $file = $filename . $ext; // Copy to storage using streams - $fp = fopen(sys_get_temp_dir() . '/' . $file, 'rb'); + $temp_dir = $this->filesystem->get_temp_dir(); + + $fp = fopen($temp_dir . '/' . $file, 'rb'); if ($fp === false) { @@ -184,7 +188,7 @@ class acp_database fclose($fp); // Remove file from tmp - @unlink(sys_get_temp_dir() . '/' . $file); + @unlink($temp_dir . '/' . $file); // Save to database $sql = "INSERT INTO " . $table_prefix . "backups (filename) @@ -343,7 +347,7 @@ class acp_database } // Copy file to temp folder to decompress it - $temp_file_name = sys_get_temp_dir() . '/' . $file_name; + $temp_file_name = $this->filesystem->get_temp_dir() . '/' . $file_name; try { diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 77e03ee449..2b0f4181b3 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -215,7 +215,7 @@ class compress_zip extends compress global $phpbb_filesystem; $this->fp = @fopen($file, $mode . 'b'); - $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(); + $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(''); if (!$this->fp) { @@ -582,7 +582,7 @@ class compress_tar extends compress $this->type = &$type; $this->open(); - $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(); + $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(''); } /** diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index de6f444251..2e9018ca19 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -35,7 +35,7 @@ class file extends \phpbb\cache\driver\base global $phpbb_container; $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir'); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); if (!is_dir($this->cache_dir)) { diff --git a/phpBB/phpbb/composer/installer.php b/phpBB/phpbb/composer/installer.php index 3a03e29ef5..5038cc7cb8 100644 --- a/phpBB/phpbb/composer/installer.php +++ b/phpBB/phpbb/composer/installer.php @@ -402,7 +402,7 @@ class installer */ public function check_requirements() { - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); return $filesystem->is_writable([ $this->root_path . $this->composer_filename, diff --git a/phpBB/phpbb/db/extractor/base_extractor.php b/phpBB/phpbb/db/extractor/base_extractor.php index 2803b89357..1c49b5b70a 100644 --- a/phpBB/phpbb/db/extractor/base_extractor.php +++ b/phpBB/phpbb/db/extractor/base_extractor.php @@ -21,6 +21,10 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception; */ abstract class base_extractor implements extractor_interface { + /** + * @var \phpbb\filesystem\filesystem + */ + protected $filesystem; /** * @var \phpbb\request\request_interface @@ -83,8 +87,9 @@ abstract class base_extractor implements extractor_interface * @param \phpbb\request\request_interface $request * @param \phpbb\db\driver\driver_interface $db */ - public function __construct(\phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) + public function __construct(\phpbb\filesystem\filesystem $filesystem, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) { + $this->filesystem = $filesystem; $this->request = $request; $this->db = $db; $this->fp = null; @@ -158,7 +163,7 @@ abstract class base_extractor implements extractor_interface if ($store === true) { - $file = sys_get_temp_dir() . '/' . $filename . $ext; + $file = $this->filesystem->get_temp_dir() . '/' . $filename . $ext; $this->fp = $open($file, 'w'); diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index e64e360b6a..b32b06adce 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -17,6 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use phpbb\config\config; use phpbb\files\factory; use phpbb\files\filespec; +use phpbb\filesystem\filesystem; use phpbb\language\language; use phpbb\request\request_interface; @@ -28,6 +29,15 @@ class remote extends base /** @var factory Files factory */ protected $factory; + /** @var filesystem Filesystem */ + protected $filesystem; + + /** @var language */ + protected $language; + + /** @var IniGetWrapper */ + protected $php_ini; + /** @var request_interface */ protected $request; @@ -39,15 +49,17 @@ class remote extends base * * @param config $config phpBB config * @param factory $factory Files factory + * @param filesystem $filesystem Filesystem * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object * @param string $phpbb_root_path phpBB root path */ - public function __construct(config $config, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) { $this->config = $config; $this->factory = $factory; + $this->filesystem = $filesystem; $this->language = $language; $this->php_ini = $php_ini; $this->request = $request; @@ -139,7 +151,7 @@ class remote extends base $data = $response->getBody(); - $filename = tempnam(sys_get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index 3e6953703e..54960b477e 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -17,6 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use phpbb\config\config; use phpbb\files\factory; use phpbb\files\filespec; +use phpbb\filesystem\filesystem; use phpbb\language\language; use phpbb\request\request_interface; @@ -28,6 +29,15 @@ class remote_storage extends base /** @var factory Files factory */ protected $factory; + /** @var filesystem Filesystem */ + protected $filesystem; + + /** @var language */ + protected $language; + + /** @var IniGetWrapper */ + protected $php_ini; + /** @var request_interface */ protected $request; @@ -39,15 +49,17 @@ class remote_storage extends base * * @param config $config phpBB config * @param factory $factory Files factory + * @param filesystem $filesystem Filesystem * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object * @param string $phpbb_root_path phpBB root path */ - public function __construct(config $config, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) { $this->config = $config; $this->factory = $factory; + $this->filesystem = $filesystem; $this->language = $language; $this->php_ini = $php_ini; $this->request = $request; @@ -138,7 +150,7 @@ class remote_storage extends base $data = $response->getBody(); - $filename = tempnam(sys_get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 7754a4107b..942ebb702f 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -42,14 +42,25 @@ class filesystem implements filesystem_interface */ protected $symfony_filesystem; + /** + * @var string + */ + protected $cache_temp_dir; + + /** + * @var string + */ + protected $temp_dir; + /** * Constructor */ - public function __construct() + public function __construct($cache_temp_dir) { $this->chmod_info = array(); $this->symfony_filesystem = new \Symfony\Component\Filesystem\Filesystem(); $this->working_directory = null; + $this->cache_temp_dir = $cache_temp_dir; } /** @@ -742,4 +753,33 @@ class filesystem implements filesystem_interface { return helper::resolve_path($path, $prefix, $absolute, $return_array); } + + /** + * Get a temporary directory to write files + * + * @return string returns the directory + */ + public function get_temp_dir() + { + if (!isset($this->temp_dir)) + { + $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; + + // Prevent trying to write to system temp dir in case of open_basedir + // restrictions being in effect + if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir)) + { + $tmp_dir = $this->cache_temp_dir; + + if (!is_dir($tmp_dir)) + { + $this->filesystem->mkdir($tmp_dir, 0777); + } + } + + $this->temp_dir = helper::realpath($tmp_dir); + } + + return $this->temp_dir; + } } diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php index 2d577db107..61208ccaa7 100644 --- a/tests/attachment/upload_test.php +++ b/tests/attachment/upload_test.php @@ -85,7 +85,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), $this->config, $this->db, $phpbb_root_path, $phpEx); $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $guessers = array( diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 2866a1673d..a78c7a30cd 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -35,7 +35,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case ->method('get') ->will($this->returnArgument(0)); - $filesystem = new \phpbb\filesystem\filesystem(); + $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']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); diff --git a/tests/console/thumbnail_test.php b/tests/console/thumbnail_test.php index ecce6f157c..5b32823230 100644 --- a/tests/console/thumbnail_test.php +++ b/tests/console/thumbnail_test.php @@ -68,7 +68,7 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case $this->application->add(new delete($this->user, $this->db, $this->phpbb_root_path)); $this->application->add(new recreate($this->user)); - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_1'); copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_2'); diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 3c732ff49b..7dc869cbdc 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -88,7 +88,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $this->symfony_request = new \phpbb\symfony_request( $this->request ); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->phpbb_path_helper = new \phpbb\path_helper( $this->symfony_request, $this->request, diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 3933dab798..7cc887b4ed 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -22,7 +22,7 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case { global $phpbb_root_path, $phpEx, $phpbb_filesystem; - $phpbb_filesystem = new phpbb\filesystem\filesystem(); + $phpbb_filesystem = new phpbb\filesystem\filesystem(''); $config = $this->get_database_config(); diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index 245c2c3a58..1c6195633c 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -36,7 +36,7 @@ class phpbb_email_parsing_test extends phpbb_test_case $symfony_request = new \phpbb\symfony_request( $request ); - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $phpbb_path_helper = new \phpbb\path_helper( $symfony_request, $request, diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php index 8ed89bbe52..5e31be0b4f 100644 --- a/tests/error_collector_test.php +++ b/tests/error_collector_test.php @@ -19,7 +19,7 @@ class phpbb_error_collector_test extends phpbb_test_case global $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); } public function test_collection() diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 5887fd974d..7422f68b67 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -53,7 +53,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $cache_path = $this->phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); $loader = new \phpbb\template\twig\loader(''); - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() diff --git a/tests/feed/attachments_base_test.php b/tests/feed/attachments_base_test.php index 3d66c906ad..9eb67eb022 100644 --- a/tests/feed/attachments_base_test.php +++ b/tests/feed/attachments_base_test.php @@ -29,7 +29,7 @@ class phpbb_feed_attachments_base_test extends phpbb_database_test_case { global $phpbb_root_path, $phpEx; - $this->filesystem = new \phpbb\filesystem(); + $this->filesystem = new \phpbb\filesystem(''); $config = new \phpbb\config\config(array()); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/files/types_base_test.php b/tests/files/types_base_test.php index 3b1cf68d50..48fe071830 100644 --- a/tests/files/types_base_test.php +++ b/tests/files/types_base_test.php @@ -41,7 +41,7 @@ class phpbb_files_types_base_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/files/types_form_test.php b/tests/files/types_form_test.php index 25d79f6117..71ce07babb 100644 --- a/tests/files/types_form_test.php +++ b/tests/files/types_form_test.php @@ -47,7 +47,7 @@ class phpbb_files_types_form_test extends phpbb_test_case ->method('file') ->willReturn(array()); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/files/types_local_test.php b/tests/files/types_local_test.php index 67e4c571f5..a7a2cd78cf 100644 --- a/tests/files/types_local_test.php +++ b/tests/files/types_local_test.php @@ -47,7 +47,7 @@ class phpbb_files_types_local_test extends phpbb_test_case ->method('file') ->willReturn(array()); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php index 85ec2a528b..29e831e87f 100644 --- a/tests/files/types_remote_test.php +++ b/tests/files/types_remote_test.php @@ -15,8 +15,10 @@ require_once dirname(__FILE__) . '/type_foo.php'; class phpbb_files_types_remote_test extends phpbb_test_case { + /** @var string */ private $path; + /** @var \phpbb\filesystem\filesystem */ private $filesystem; /** @var \phpbb\config\config */ @@ -49,7 +51,8 @@ class phpbb_files_types_remote_test extends phpbb_test_case $this->config->set('remote_upload_verify', 0); $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $cache_path = $phpbb_root_path . 'cache/files'; + $this->filesystem = new \phpbb\filesystem\filesystem($cache_path); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; @@ -71,7 +74,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case public function test_upload_fsock_fail() { - $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->filesystem, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); @@ -106,7 +109,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case $php_ini->expects($this->any()) ->method('getString') ->willReturn($max_file_size); - $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->language, $php_ini, $this->request, $this->phpbb_root_path); + $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->filesystem, $this->language, $php_ini, $this->request, $this->phpbb_root_path); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); @@ -118,7 +121,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case public function test_upload_wrong_path() { - $type_remote = new \phpbb\files\types\foo($this->config, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $type_remote = new \phpbb\files\types\foo($this->config, $this->factory, $this->filesystem, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index a9c2dca9d9..60c2dc7d36 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -50,7 +50,7 @@ class phpbb_files_upload_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index d2dec424b4..3c99e785d0 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -18,7 +18,7 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); } public function clean_path_data() diff --git a/tests/filesystem/is_absolute_test.php b/tests/filesystem/is_absolute_test.php index 7a50989b74..181445e147 100644 --- a/tests/filesystem/is_absolute_test.php +++ b/tests/filesystem/is_absolute_test.php @@ -20,7 +20,7 @@ class phpbb_filesystem_is_absolute_test extends phpbb_test_case { parent::setUp(); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); } static public function is_absolute_data() diff --git a/tests/filesystem/realpath_test.php b/tests/filesystem/realpath_test.php index d994935f94..9b94592cb3 100644 --- a/tests/filesystem/realpath_test.php +++ b/tests/filesystem/realpath_test.php @@ -31,7 +31,7 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case { parent::setUp(); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); } public function realpath_resolve_absolute_without_symlinks_data() @@ -55,7 +55,7 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case return array(); } - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $relative_path = $filesystem->make_path_relative(__DIR__, getcwd()); return array( diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 4fced5700a..235d81d48d 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -52,7 +52,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $config['rand_seed_last_update'] = time() + 600; $config['remote_upload_verify'] = 0; - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->request = $this->createMock('\phpbb\request\request'); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; @@ -61,7 +61,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); - $container->set('files.types.remote', new \phpbb\files\types\remote($config, $this->factory, $this->language, $this->php_ini, $this->request, $phpbb_root_path)); + $container->set('files.types.remote', new \phpbb\files\types\remote($config, $this->factory, $this->filesystem, $this->language, $this->php_ini, $this->request, $phpbb_root_path)); $this->phpbb_root_path = $phpbb_root_path; } diff --git a/tests/installer/database_helper_test.php b/tests/installer/database_helper_test.php index ed355884f6..9d728b205c 100644 --- a/tests/installer/database_helper_test.php +++ b/tests/installer/database_helper_test.php @@ -20,7 +20,7 @@ class phpbb_installer_database_helper_test extends phpbb_test_case public function setUp() { - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $phpbb_root_path = ''; $this->database_helper = new \phpbb\install\helper\database($filesystem, $phpbb_root_path); } diff --git a/tests/installer/module_base_test.php b/tests/installer/module_base_test.php index 71ec2b8db2..7527268914 100644 --- a/tests/installer/module_base_test.php +++ b/tests/installer/module_base_test.php @@ -43,7 +43,7 @@ class module_base_test extends phpbb_test_case $this->module = new test_installer_module($module_collection, true, false); $iohandler = $this->createMock('\phpbb\install\helper\iohandler\iohandler_interface'); - $config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(), new \bantu\IniGetWrapper\IniGetWrapper(), '', 'php'); + $config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(''), new \bantu\IniGetWrapper\IniGetWrapper(), '', 'php'); $this->module->setup($config, $iohandler); } diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 0d6d110647..7c96eeeb4f 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -21,7 +21,7 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->container = $container; $this->config = new \phpbb\config\config(array()); $this->user = new \phpbb\user($lang,'\phpbb\datetime'); diff --git a/tests/security/base.php b/tests/security/base.php index d2abdbc362..2c7a0bd251 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -46,7 +46,7 @@ abstract class phpbb_security_test_base extends phpbb_test_case $request = new phpbb_mock_request(array(), array(), array(), $this->server); $symfony_request = new \phpbb\symfony_request($request); - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); // Set no user and trick a bit to circumvent errors $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php index 04da5f08b9..26e95b2856 100644 --- a/tests/session/check_ban_test.php +++ b/tests/session/check_ban_test.php @@ -44,7 +44,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case $this->session = $this->session_factory->get_session($this->db); global $cache, $config, $phpbb_root_path, $phpEx, $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); $this->backup_cache = $cache; // Change the global cache object for this test because diff --git a/tests/session/extract_page_test.php b/tests/session/extract_page_test.php index f8aa3d27a5..42adf719ce 100644 --- a/tests/session/extract_page_test.php +++ b/tests/session/extract_page_test.php @@ -160,7 +160,7 @@ class phpbb_session_extract_page_test extends phpbb_session_test_case { global $symfony_request, $request, $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); $server['HTTP_HOST'] = 'localhost'; $server['SERVER_NAME'] = 'localhost'; diff --git a/tests/storage/adapter/local_test.php b/tests/storage/adapter/local_test.php index b478ce4009..8099a49522 100644 --- a/tests/storage/adapter/local_test.php +++ b/tests/storage/adapter/local_test.php @@ -21,7 +21,7 @@ { parent::setUp(); - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR; $this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); diff --git a/tests/template/asset_test.php b/tests/template/asset_test.php index 3d2fdd8959..49ecc56012 100644 --- a/tests/template/asset_test.php +++ b/tests/template/asset_test.php @@ -41,7 +41,7 @@ class phpbb_template_asset_test extends phpbb_test_case $path_helper->method('get_phpbb_root_path') ->willReturn($phpbb_root_path); - $asset = new asset('', $path_helper, new phpbb\filesystem\filesystem()); + $asset = new asset('', $path_helper, new phpbb\filesystem\filesystem('')); $asset->set_path($path, true); $this->assertEquals($expected, $asset->get_path()); diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index 17a57fba35..75b6bf834d 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -33,7 +33,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = $user; - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 024bdc57ce..fd603b113d 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -139,7 +139,7 @@ Zeta test event in all', dirname(__FILE__) . "/datasets/$dataset/" ); - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index f195742dc6..52f212b5aa 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -28,7 +28,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index bcb6f4cde7..5340132aad 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -80,7 +80,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = $user; - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -126,7 +126,7 @@ class phpbb_template_template_test_case extends phpbb_test_case global $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); } protected function tearDown() diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index aa71bf6ed6..c5069b703b 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $filesystem = new \phpbb\filesystem\filesystem(); + $filesystem = new \phpbb\filesystem\filesystem(''); $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index f7ba3ba21b..9f282d7d1d 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -354,7 +354,7 @@ class phpbb_database_test_connection_manager $queries = file_get_contents($filename); - $db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path); + $db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(''), $phpbb_root_path); $sql = $db_helper->remove_comments($queries); $sql = $db_helper->split_sql_file($sql, $this->dbms['DELIM']); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 18b6deed1f..9f2d906355 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -75,7 +75,7 @@ class phpbb_filespec_test extends phpbb_test_case $this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->phpbb_root_path = $phpbb_root_path; } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 84fc00bf98..df658b459e 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -53,7 +53,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; - $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $guessers = array( new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), diff --git a/tests/viewonline/helper_test.php b/tests/viewonline/helper_test.php index 6540d33287..53704b2ec7 100644 --- a/tests/viewonline/helper_test.php +++ b/tests/viewonline/helper_test.php @@ -17,7 +17,7 @@ class phpbb_viewonline_helper_test extends phpbb_test_case { parent::setUp(); - $this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem\filesystem()); + $this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem\filesystem('')); } public function session_pages_data() From 6b6c02aa7f68947b0193797dbfcbd502deefdf22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 31 Oct 2017 11:23:31 +0100 Subject: [PATCH 07/13] [ticket/15311] Fix variable PHPBB3-15311 --- phpBB/phpbb/filesystem/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 942ebb702f..52eb271b8a 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -773,7 +773,7 @@ class filesystem implements filesystem_interface if (!is_dir($tmp_dir)) { - $this->filesystem->mkdir($tmp_dir, 0777); + $this->mkdir($tmp_dir, 0777); } } From 4ebded01b9f0c457f3b28fe8e82080a7f7ec5137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 May 2018 14:11:21 +0200 Subject: [PATCH 08/13] [ticket/15311] Improve code comments PHPBB3-15311 --- phpBB/includes/acp/acp_database.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index d345d4075e..5c2e2908eb 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -113,11 +113,13 @@ class acp_database // Get the table structure if ($structure) { + // Add table structure to the backup + // This method also add a "drop the table if exists" after trying to write the table structure $extractor->write_table($table_name); } else { - // We might wanna empty out all that junk :D + // Add command to empty table before write data on it switch ($db->get_sql_layer()) { case 'sqlite3': @@ -139,7 +141,7 @@ class acp_database } } - // Data + // Write schema data if it exists if ($schema_data) { $extractor->write_data($table_name); From 01f88fd2697eafd4a954aa9d01182d77acef00e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 May 2018 14:13:10 +0200 Subject: [PATCH 09/13] [ticket/15311] Escape file_name in sql query PHPBB3-15311 --- phpBB/includes/acp/acp_database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 5c2e2908eb..63e9506ad9 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -289,7 +289,7 @@ class acp_database // Remove from database $sql = "DELETE FROM " . $table_prefix . "backups - WHERE filename = '" . $file_name . "';"; + WHERE filename = '" . $db->sql_escape($file_name) . "';"; $db->sql_query($sql); } catch (\Exception $e) From b029c7889e24489da6ae3e08a338823314cb1dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 17 May 2018 00:02:03 +0200 Subject: [PATCH 10/13] [ticket/15311] Fix test PHPBB3-15311 --- tests/content_visibility/delete_post_test.php | 2 +- tests/functions_user/delete_user_test.php | 2 +- tests/notification/submit_post_base.php | 2 +- tests/privmsgs/delete_user_pms_test.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index d4feeaad22..ac2efdcfc3 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -298,7 +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 = 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()) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index b51dabbba0..9d1b897226 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -35,7 +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 = 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()) diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index d882c106ac..bbd9bc938c 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -92,7 +92,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 = 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()) diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index b35510113a..5315c99fb4 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -92,7 +92,7 @@ class phpbb_privmsgs_delete_user_pms_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 = 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()) From d156bf3757a34c2bcc91bf90940b709d2fafd508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 23 May 2018 22:46:22 +0200 Subject: [PATCH 11/13] [ticket/15311] Fix code style PHPBB3-15311 --- phpBB/phpbb/filesystem/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 52eb271b8a..ed63282d99 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -773,7 +773,7 @@ class filesystem implements filesystem_interface if (!is_dir($tmp_dir)) { - $this->mkdir($tmp_dir, 0777); + $this->mkdir($tmp_dir, 0777); } } From b43268e8fcadc336df74c4b803484f295e6f3f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 30 May 2018 23:15:31 +0200 Subject: [PATCH 12/13] [ticket/15311] Move get_temp_dir to another service PHPBB3-15311 --- .../default/container/services_attachment.yml | 1 + .../config/default/container/services_db.yml | 10 ++-- .../default/container/services_files.yml | 6 +-- .../default/container/services_filesystem.yml | 4 ++ phpBB/includes/functions_compress.php | 4 +- phpBB/phpbb/attachment/upload.php | 10 +++- phpBB/phpbb/cache/driver/file.php | 2 +- phpBB/phpbb/composer/installer.php | 2 +- phpBB/phpbb/db/extractor/base_extractor.php | 11 ++-- phpBB/phpbb/files/types/remote.php | 19 +++---- phpBB/phpbb/files/types/remote_storage.php | 19 +++---- phpBB/phpbb/filesystem/filesystem.php | 42 +-------------- phpBB/phpbb/filesystem/temp.php | 54 +++++++++++++++++++ tests/attachment/upload_test.php | 10 +++- tests/avatar/manager_test.php | 2 +- tests/console/thumbnail_test.php | 2 +- tests/content_visibility/delete_post_test.php | 2 +- tests/controller/common_helper_route.php | 2 +- tests/dbal/connect_test.php | 2 +- tests/email/email_parsing_test.php | 2 +- tests/error_collector_test.php | 2 +- tests/extension/metadata_manager_test.php | 2 +- tests/feed/attachments_base_test.php | 2 +- tests/files/types_base_test.php | 2 +- tests/files/types_form_test.php | 2 +- tests/files/types_local_test.php | 2 +- tests/files/types_remote_test.php | 12 +++-- tests/files/upload_test.php | 2 +- tests/filesystem/clean_path_test.php | 2 +- tests/filesystem/is_absolute_test.php | 2 +- tests/filesystem/realpath_test.php | 4 +- tests/functional/fileupload_remote_test.php | 8 ++- tests/functions_user/delete_user_test.php | 2 +- tests/installer/database_helper_test.php | 2 +- tests/installer/module_base_test.php | 2 +- tests/mock/extension_manager.php | 2 +- tests/notification/submit_post_base.php | 2 +- tests/privmsgs/delete_user_pms_test.php | 2 +- tests/security/base.php | 2 +- tests/session/check_ban_test.php | 2 +- tests/session/extract_page_test.php | 2 +- tests/storage/adapter/local_test.php | 2 +- tests/template/asset_test.php | 2 +- tests/template/template_allfolder_test.php | 2 +- tests/template/template_events_test.php | 2 +- tests/template/template_includecss_test.php | 2 +- tests/template/template_test_case.php | 4 +- .../template/template_test_case_with_tree.php | 2 +- ...phpbb_database_test_connection_manager.php | 2 +- tests/upload/filespec_test.php | 2 +- tests/upload/fileupload_test.php | 2 +- tests/viewonline/helper_test.php | 2 +- 52 files changed, 160 insertions(+), 130 deletions(-) create mode 100644 phpBB/phpbb/filesystem/temp.php diff --git a/phpBB/config/default/container/services_attachment.yml b/phpBB/config/default/container/services_attachment.yml index 5b614d2f60..0ec8357599 100644 --- a/phpBB/config/default/container/services_attachment.yml +++ b/phpBB/config/default/container/services_attachment.yml @@ -36,4 +36,5 @@ services: - '@dispatcher' - '@plupload' - '@storage.attachment' + - '@temp' - '@user' diff --git a/phpBB/config/default/container/services_db.yml b/phpBB/config/default/container/services_db.yml index b52b29e20f..4a005d5e50 100644 --- a/phpBB/config/default/container/services_db.yml +++ b/phpBB/config/default/container/services_db.yml @@ -34,7 +34,7 @@ services: class: phpbb\db\extractor\mssql_extractor shared: false arguments: - - '@filesystem' + - '@temp' - '@request' - '@dbal.conn.driver' @@ -42,7 +42,7 @@ services: class: phpbb\db\extractor\mysql_extractor shared: false arguments: - - '@filesystem' + - '@temp' - '@request' - '@dbal.conn.driver' @@ -50,7 +50,7 @@ services: class: phpbb\db\extractor\oracle_extractor shared: false arguments: - - '@filesystem' + - '@temp' - '@request' - '@dbal.conn.driver' @@ -58,7 +58,7 @@ services: class: phpbb\db\extractor\postgres_extractor shared: false arguments: - - '@filesystem' + - '@temp' - '@request' - '@dbal.conn.driver' @@ -66,6 +66,6 @@ services: class: phpbb\db\extractor\sqlite3_extractor shared: false arguments: - - '@filesystem' + - '@temp' - '@request' - '@dbal.conn.driver' diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index b5310c8c6e..43be127ea2 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -71,11 +71,10 @@ services: arguments: - '@config' - '@files.factory' - - '@filesystem' + - '@temp' - '@language' - '@php_ini' - '@request' - - '%core.root_path%' files.types.remote_storage: class: phpbb\files\types\remote_storage @@ -83,8 +82,7 @@ services: arguments: - '@config' - '@files.factory' - - '@filesystem' + - '@temp' - '@language' - '@php_ini' - '@request' - - '%core.root_path%' diff --git a/phpBB/config/default/container/services_filesystem.yml b/phpBB/config/default/container/services_filesystem.yml index 36025755fd..e7832bf37d 100644 --- a/phpBB/config/default/container/services_filesystem.yml +++ b/phpBB/config/default/container/services_filesystem.yml @@ -4,5 +4,9 @@ parameters: services: filesystem: class: phpbb\filesystem\filesystem + + temp: + class: phpbb\filesystem\temp arguments: + - '@filesystem' - '%core.filesystem.cache_temp_dir%' diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 2b0f4181b3..77e03ee449 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -215,7 +215,7 @@ class compress_zip extends compress global $phpbb_filesystem; $this->fp = @fopen($file, $mode . 'b'); - $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(''); + $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(); if (!$this->fp) { @@ -582,7 +582,7 @@ class compress_tar extends compress $this->type = &$type; $this->open(); - $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(''); + $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem(); } /** diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index 82a7578380..b3cd4972a1 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -21,6 +21,7 @@ use \phpbb\language\language; use \phpbb\mimetype\guesser; use \phpbb\plupload\plupload; use \phpbb\storage\storage; +use \phpbb\filesystem\temp; use \phpbb\user; /** @@ -55,6 +56,9 @@ class upload /** @var storage */ protected $storage; + /** @var temp */ + protected $temp; + /** @var user */ protected $user; @@ -80,9 +84,10 @@ class upload * @param guesser $mimetype_guesser * @param dispatcher $phpbb_dispatcher * @param plupload $plupload + * @param temp $temp * @param user $user */ - public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, user $user) + public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, temp $temp, user $user) { $this->auth = $auth; $this->cache = $cache; @@ -93,6 +98,7 @@ class upload $this->phpbb_dispatcher = $phpbb_dispatcher; $this->plupload = $plupload; $this->storage = $storage; + $this->temp = $temp; $this->user = $user; } @@ -234,7 +240,7 @@ class upload { $source = $this->file->get('filename'); $destination_name = 'thumb_' . $this->file->get('realname'); - $destination = sys_get_temp_dir() . '/' . $destination_name; + $destination = $this->temp->get_temp_dir() . '/' . $destination_name; if (create_thumbnail($source, $destination, $this->file->get('mimetype'))) { diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 2e9018ca19..de6f444251 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -35,7 +35,7 @@ class file extends \phpbb\cache\driver\base global $phpbb_container; $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir'); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); if (!is_dir($this->cache_dir)) { diff --git a/phpBB/phpbb/composer/installer.php b/phpBB/phpbb/composer/installer.php index 5038cc7cb8..3a03e29ef5 100644 --- a/phpBB/phpbb/composer/installer.php +++ b/phpBB/phpbb/composer/installer.php @@ -402,7 +402,7 @@ class installer */ public function check_requirements() { - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); return $filesystem->is_writable([ $this->root_path . $this->composer_filename, diff --git a/phpBB/phpbb/db/extractor/base_extractor.php b/phpBB/phpbb/db/extractor/base_extractor.php index 1c49b5b70a..b750f064bb 100644 --- a/phpBB/phpbb/db/extractor/base_extractor.php +++ b/phpBB/phpbb/db/extractor/base_extractor.php @@ -22,9 +22,9 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception; abstract class base_extractor implements extractor_interface { /** - * @var \phpbb\filesystem\filesystem + * @var \phpbb\filesystem\temp */ - protected $filesystem; + protected $temp; /** * @var \phpbb\request\request_interface @@ -84,12 +84,13 @@ abstract class base_extractor implements extractor_interface /** * Constructor * + * @param \phpbb\filesystem\temp $temp * @param \phpbb\request\request_interface $request * @param \phpbb\db\driver\driver_interface $db */ - public function __construct(\phpbb\filesystem\filesystem $filesystem, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) + public function __construct(\phpbb\filesystem\temp $temp, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) { - $this->filesystem = $filesystem; + $this->temp = $temp; $this->request = $request; $this->db = $db; $this->fp = null; @@ -163,7 +164,7 @@ abstract class base_extractor implements extractor_interface if ($store === true) { - $file = $this->filesystem->get_temp_dir() . '/' . $filename . $ext; + $file = $this->temp->get_temp_dir() . '/' . $filename . $ext; $this->fp = $open($file, 'w'); diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index b32b06adce..3bfd7dc7cd 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -17,7 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use phpbb\config\config; use phpbb\files\factory; use phpbb\files\filespec; -use phpbb\filesystem\filesystem; +use phpbb\filesystem\temp; use phpbb\language\language; use phpbb\request\request_interface; @@ -29,8 +29,8 @@ class remote extends base /** @var factory Files factory */ protected $factory; - /** @var filesystem Filesystem */ - protected $filesystem; + /** @var filesystem Filesystem temp */ + protected $temp; /** @var language */ protected $language; @@ -41,29 +41,24 @@ class remote extends base /** @var request_interface */ protected $request; - /** @var string phpBB root path */ - protected $phpbb_root_path; - /** * Construct a form upload type * * @param config $config phpBB config * @param factory $factory Files factory - * @param filesystem $filesystem Filesystem + * @param temp $temp Filesystem temp * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object - * @param string $phpbb_root_path phpBB root path */ - public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + public function __construct(config $config, factory $factory, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request) { $this->config = $config; $this->factory = $factory; - $this->filesystem = $filesystem; + $this->temp = $temp; $this->language = $language; $this->php_ini = $php_ini; $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; } /** @@ -151,7 +146,7 @@ class remote extends base $data = $response->getBody(); - $filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index 54960b477e..8c2ceb6900 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -17,7 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use phpbb\config\config; use phpbb\files\factory; use phpbb\files\filespec; -use phpbb\filesystem\filesystem; +use phpbb\filesystem\temp; use phpbb\language\language; use phpbb\request\request_interface; @@ -29,8 +29,8 @@ class remote_storage extends base /** @var factory Files factory */ protected $factory; - /** @var filesystem Filesystem */ - protected $filesystem; + /** @var temp Filesystem temp */ + protected $temp; /** @var language */ protected $language; @@ -41,29 +41,24 @@ class remote_storage extends base /** @var request_interface */ protected $request; - /** @var string phpBB root path */ - protected $phpbb_root_path; - /** * Construct a form upload type * * @param config $config phpBB config * @param factory $factory Files factory - * @param filesystem $filesystem Filesystem + * @param temp $temp Filesystem temp * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object - * @param string $phpbb_root_path phpBB root path */ - public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + public function __construct(config $config, factory $factory, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request) { $this->config = $config; $this->factory = $factory; - $this->filesystem = $filesystem; + $this->temp = $temp; $this->language = $language; $this->php_ini = $php_ini; $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; } /** @@ -150,7 +145,7 @@ class remote_storage extends base $data = $response->getBody(); - $filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index ed63282d99..7754a4107b 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -42,25 +42,14 @@ class filesystem implements filesystem_interface */ protected $symfony_filesystem; - /** - * @var string - */ - protected $cache_temp_dir; - - /** - * @var string - */ - protected $temp_dir; - /** * Constructor */ - public function __construct($cache_temp_dir) + public function __construct() { $this->chmod_info = array(); $this->symfony_filesystem = new \Symfony\Component\Filesystem\Filesystem(); $this->working_directory = null; - $this->cache_temp_dir = $cache_temp_dir; } /** @@ -753,33 +742,4 @@ class filesystem implements filesystem_interface { return helper::resolve_path($path, $prefix, $absolute, $return_array); } - - /** - * Get a temporary directory to write files - * - * @return string returns the directory - */ - public function get_temp_dir() - { - if (!isset($this->temp_dir)) - { - $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; - - // Prevent trying to write to system temp dir in case of open_basedir - // restrictions being in effect - if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir)) - { - $tmp_dir = $this->cache_temp_dir; - - if (!is_dir($tmp_dir)) - { - $this->mkdir($tmp_dir, 0777); - } - } - - $this->temp_dir = helper::realpath($tmp_dir); - } - - return $this->temp_dir; - } } diff --git a/phpBB/phpbb/filesystem/temp.php b/phpBB/phpbb/filesystem/temp.php new file mode 100644 index 0000000000..ffd9cc6973 --- /dev/null +++ b/phpBB/phpbb/filesystem/temp.php @@ -0,0 +1,54 @@ + + * @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\filesystem; + +class temp +{ + /** + * @var string + */ + protected $temp_dir; + + /** + * Constructor + */ + public function __construct($filesystem, $cache_temp_dir) + { + $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; + + // Prevent trying to write to system temp dir in case of open_basedir + // restrictions being in effect + if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir)) + { + $tmp_dir = $cache_temp_dir; + + if (!is_dir($tmp_dir)) + { + $filesystem->mkdir($tmp_dir, 0777); + } + } + + $this->temp_dir = helper::realpath($tmp_dir); + } + + /** + * Get a temporary directory to write files + * + * @return string returns the directory + */ + public function get_temp_dir() + { + return $this->temp_dir; + } +} diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php index 61208ccaa7..a9567510c8 100644 --- a/tests/attachment/upload_test.php +++ b/tests/attachment/upload_test.php @@ -54,8 +54,12 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case /** @var \phpbb\attachment\upload */ protected $upload; + /** @var \phpbb\filesystem\filesystem */ private $filesystem; + /** @var \phpbb\filesystem\temp */ + protected $temp; + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ protected $container; @@ -85,7 +89,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), $this->config, $this->db, $phpbb_root_path, $phpEx); $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $guessers = array( @@ -143,6 +147,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->factory = new \phpbb\files\factory($this->container); $this->files_upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $this->phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $this->temp = new \phpbb\filesystem\temp($this->filesystem, ''); $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); $this->upload = new \phpbb\attachment\upload( @@ -155,6 +160,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->phpbb_dispatcher, $this->plupload, $this->storage, + $this->temp, $this->user ); } @@ -247,6 +253,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->phpbb_dispatcher, $this->plupload, $this->storage, + $this->temp, $this->user ); @@ -411,6 +418,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->phpbb_dispatcher, $plupload, $this->storage, + $this->temp, $this->user ); diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index a78c7a30cd..2866a1673d 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -35,7 +35,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case ->method('get') ->will($this->returnArgument(0)); - $filesystem = new \phpbb\filesystem\filesystem(''); + $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']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); diff --git a/tests/console/thumbnail_test.php b/tests/console/thumbnail_test.php index 5b32823230..ecce6f157c 100644 --- a/tests/console/thumbnail_test.php +++ b/tests/console/thumbnail_test.php @@ -68,7 +68,7 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case $this->application->add(new delete($this->user, $this->db, $this->phpbb_root_path)); $this->application->add(new recreate($this->user)); - $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_1'); copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_2'); diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index ac2efdcfc3..d4feeaad22 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -298,7 +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 = 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()) diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 7dc869cbdc..3c732ff49b 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -88,7 +88,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $this->symfony_request = new \phpbb\symfony_request( $this->request ); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->phpbb_path_helper = new \phpbb\path_helper( $this->symfony_request, $this->request, diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 7cc887b4ed..3933dab798 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -22,7 +22,7 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case { global $phpbb_root_path, $phpEx, $phpbb_filesystem; - $phpbb_filesystem = new phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new phpbb\filesystem\filesystem(); $config = $this->get_database_config(); diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index 1c6195633c..245c2c3a58 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -36,7 +36,7 @@ class phpbb_email_parsing_test extends phpbb_test_case $symfony_request = new \phpbb\symfony_request( $request ); - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $phpbb_path_helper = new \phpbb\path_helper( $symfony_request, $request, diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php index 5e31be0b4f..8ed89bbe52 100644 --- a/tests/error_collector_test.php +++ b/tests/error_collector_test.php @@ -19,7 +19,7 @@ class phpbb_error_collector_test extends phpbb_test_case global $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); } public function test_collection() diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 7422f68b67..5887fd974d 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -53,7 +53,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $cache_path = $this->phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); $loader = new \phpbb\template\twig\loader(''); - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() diff --git a/tests/feed/attachments_base_test.php b/tests/feed/attachments_base_test.php index 9eb67eb022..3d66c906ad 100644 --- a/tests/feed/attachments_base_test.php +++ b/tests/feed/attachments_base_test.php @@ -29,7 +29,7 @@ class phpbb_feed_attachments_base_test extends phpbb_database_test_case { global $phpbb_root_path, $phpEx; - $this->filesystem = new \phpbb\filesystem(''); + $this->filesystem = new \phpbb\filesystem(); $config = new \phpbb\config\config(array()); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/files/types_base_test.php b/tests/files/types_base_test.php index 48fe071830..3b1cf68d50 100644 --- a/tests/files/types_base_test.php +++ b/tests/files/types_base_test.php @@ -41,7 +41,7 @@ class phpbb_files_types_base_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/files/types_form_test.php b/tests/files/types_form_test.php index 71ce07babb..25d79f6117 100644 --- a/tests/files/types_form_test.php +++ b/tests/files/types_form_test.php @@ -47,7 +47,7 @@ class phpbb_files_types_form_test extends phpbb_test_case ->method('file') ->willReturn(array()); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/files/types_local_test.php b/tests/files/types_local_test.php index a7a2cd78cf..67e4c571f5 100644 --- a/tests/files/types_local_test.php +++ b/tests/files/types_local_test.php @@ -47,7 +47,7 @@ class phpbb_files_types_local_test extends phpbb_test_case ->method('file') ->willReturn(array()); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php index 29e831e87f..ea869bb85c 100644 --- a/tests/files/types_remote_test.php +++ b/tests/files/types_remote_test.php @@ -21,6 +21,9 @@ class phpbb_files_types_remote_test extends phpbb_test_case /** @var \phpbb\filesystem\filesystem */ private $filesystem; + /** @var \phpbb\filesystem\temp */ + private $temp; + /** @var \phpbb\config\config */ protected $config; @@ -52,7 +55,8 @@ class phpbb_files_types_remote_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); $cache_path = $phpbb_root_path . 'cache/files'; - $this->filesystem = new \phpbb\filesystem\filesystem($cache_path); + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->temp = new \phpbb\filesystem\temp($this->filesystem, $cache_path); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; @@ -74,7 +78,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case public function test_upload_fsock_fail() { - $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->filesystem, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->temp, $this->language, $this->php_ini, $this->request); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); @@ -109,7 +113,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case $php_ini->expects($this->any()) ->method('getString') ->willReturn($max_file_size); - $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->filesystem, $this->language, $php_ini, $this->request, $this->phpbb_root_path); + $type_remote = new \phpbb\files\types\remote($this->config, $this->factory, $this->temp, $this->language, $php_ini, $this->request); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); @@ -121,7 +125,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case public function test_upload_wrong_path() { - $type_remote = new \phpbb\files\types\foo($this->config, $this->factory, $this->filesystem, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $type_remote = new \phpbb\files\types\foo($this->config, $this->factory, $this->temp, $this->language, $this->php_ini, $this->request); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index 60c2dc7d36..a9c2dca9d9 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -50,7 +50,7 @@ class phpbb_files_upload_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index 3c99e785d0..d2dec424b4 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -18,7 +18,7 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); } public function clean_path_data() diff --git a/tests/filesystem/is_absolute_test.php b/tests/filesystem/is_absolute_test.php index 181445e147..7a50989b74 100644 --- a/tests/filesystem/is_absolute_test.php +++ b/tests/filesystem/is_absolute_test.php @@ -20,7 +20,7 @@ class phpbb_filesystem_is_absolute_test extends phpbb_test_case { parent::setUp(); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); } static public function is_absolute_data() diff --git a/tests/filesystem/realpath_test.php b/tests/filesystem/realpath_test.php index 9b94592cb3..d994935f94 100644 --- a/tests/filesystem/realpath_test.php +++ b/tests/filesystem/realpath_test.php @@ -31,7 +31,7 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case { parent::setUp(); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); } public function realpath_resolve_absolute_without_symlinks_data() @@ -55,7 +55,7 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case return array(); } - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $relative_path = $filesystem->make_path_relative(__DIR__, getcwd()); return array( diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 235d81d48d..0d09d5fcc8 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -19,6 +19,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case /** @var \phpbb\filesystem\filesystem_interface */ protected $filesystem; + /** @var \phpbb\filesystem\temp */ + protected $temp; + /** @var \phpbb\files\factory */ protected $factory; @@ -52,7 +55,8 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $config['rand_seed_last_update'] = time() + 600; $config['remote_upload_verify'] = 0; - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->temp = new \phpbb\filesystem\temp($this->filesystem, ''); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->request = $this->createMock('\phpbb\request\request'); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; @@ -61,7 +65,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); - $container->set('files.types.remote', new \phpbb\files\types\remote($config, $this->factory, $this->filesystem, $this->language, $this->php_ini, $this->request, $phpbb_root_path)); + $container->set('files.types.remote', new \phpbb\files\types\remote($config, $this->factory, $this->temp, $this->language, $this->php_ini, $this->request)); $this->phpbb_root_path = $phpbb_root_path; } diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 9d1b897226..b51dabbba0 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -35,7 +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 = 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()) diff --git a/tests/installer/database_helper_test.php b/tests/installer/database_helper_test.php index 9d728b205c..ed355884f6 100644 --- a/tests/installer/database_helper_test.php +++ b/tests/installer/database_helper_test.php @@ -20,7 +20,7 @@ class phpbb_installer_database_helper_test extends phpbb_test_case public function setUp() { - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $phpbb_root_path = ''; $this->database_helper = new \phpbb\install\helper\database($filesystem, $phpbb_root_path); } diff --git a/tests/installer/module_base_test.php b/tests/installer/module_base_test.php index 7527268914..71ec2b8db2 100644 --- a/tests/installer/module_base_test.php +++ b/tests/installer/module_base_test.php @@ -43,7 +43,7 @@ class module_base_test extends phpbb_test_case $this->module = new test_installer_module($module_collection, true, false); $iohandler = $this->createMock('\phpbb\install\helper\iohandler\iohandler_interface'); - $config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(''), new \bantu\IniGetWrapper\IniGetWrapper(), '', 'php'); + $config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(), new \bantu\IniGetWrapper\IniGetWrapper(), '', 'php'); $this->module->setup($config, $iohandler); } diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 7c96eeeb4f..0d6d110647 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -21,7 +21,7 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->container = $container; $this->config = new \phpbb\config\config(array()); $this->user = new \phpbb\user($lang,'\phpbb\datetime'); diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index bbd9bc938c..d882c106ac 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -92,7 +92,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 = 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()) diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index 5315c99fb4..b35510113a 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -92,7 +92,7 @@ class phpbb_privmsgs_delete_user_pms_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 = 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()) diff --git a/tests/security/base.php b/tests/security/base.php index 2c7a0bd251..d2abdbc362 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -46,7 +46,7 @@ abstract class phpbb_security_test_base extends phpbb_test_case $request = new phpbb_mock_request(array(), array(), array(), $this->server); $symfony_request = new \phpbb\symfony_request($request); - $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); // Set no user and trick a bit to circumvent errors $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php index 26e95b2856..04da5f08b9 100644 --- a/tests/session/check_ban_test.php +++ b/tests/session/check_ban_test.php @@ -44,7 +44,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case $this->session = $this->session_factory->get_session($this->db); global $cache, $config, $phpbb_root_path, $phpEx, $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); $this->backup_cache = $cache; // Change the global cache object for this test because diff --git a/tests/session/extract_page_test.php b/tests/session/extract_page_test.php index 42adf719ce..f8aa3d27a5 100644 --- a/tests/session/extract_page_test.php +++ b/tests/session/extract_page_test.php @@ -160,7 +160,7 @@ class phpbb_session_extract_page_test extends phpbb_session_test_case { global $symfony_request, $request, $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); $server['HTTP_HOST'] = 'localhost'; $server['SERVER_NAME'] = 'localhost'; diff --git a/tests/storage/adapter/local_test.php b/tests/storage/adapter/local_test.php index 8099a49522..b478ce4009 100644 --- a/tests/storage/adapter/local_test.php +++ b/tests/storage/adapter/local_test.php @@ -21,7 +21,7 @@ { parent::setUp(); - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR; $this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); diff --git a/tests/template/asset_test.php b/tests/template/asset_test.php index 49ecc56012..3d2fdd8959 100644 --- a/tests/template/asset_test.php +++ b/tests/template/asset_test.php @@ -41,7 +41,7 @@ class phpbb_template_asset_test extends phpbb_test_case $path_helper->method('get_phpbb_root_path') ->willReturn($phpbb_root_path); - $asset = new asset('', $path_helper, new phpbb\filesystem\filesystem('')); + $asset = new asset('', $path_helper, new phpbb\filesystem\filesystem()); $asset->set_path($path, true); $this->assertEquals($expected, $asset->get_path()); diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index 75b6bf834d..17a57fba35 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -33,7 +33,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = $user; - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index fd603b113d..024bdc57ce 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -139,7 +139,7 @@ Zeta test event in all', dirname(__FILE__) . "/datasets/$dataset/" ); - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 52f212b5aa..f195742dc6 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -28,7 +28,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 5340132aad..bcb6f4cde7 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -80,7 +80,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = $user; - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -126,7 +126,7 @@ class phpbb_template_template_test_case extends phpbb_test_case global $phpbb_filesystem; - $phpbb_filesystem = new \phpbb\filesystem\filesystem(''); + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); } protected function tearDown() diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index c5069b703b..aa71bf6ed6 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 9f282d7d1d..f7ba3ba21b 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -354,7 +354,7 @@ class phpbb_database_test_connection_manager $queries = file_get_contents($filename); - $db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(''), $phpbb_root_path); + $db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path); $sql = $db_helper->remove_comments($queries); $sql = $db_helper->split_sql_file($sql, $this->dbms['DELIM']); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 9f2d906355..18b6deed1f 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -75,7 +75,7 @@ class phpbb_filespec_test extends phpbb_test_case $this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->phpbb_root_path = $phpbb_root_path; } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index df658b459e..84fc00bf98 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -53,7 +53,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->request = $this->createMock('\phpbb\request\request'); $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $guessers = array( new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), diff --git a/tests/viewonline/helper_test.php b/tests/viewonline/helper_test.php index 53704b2ec7..6540d33287 100644 --- a/tests/viewonline/helper_test.php +++ b/tests/viewonline/helper_test.php @@ -17,7 +17,7 @@ class phpbb_viewonline_helper_test extends phpbb_test_case { parent::setUp(); - $this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem\filesystem('')); + $this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem\filesystem()); } public function session_pages_data() From 3320ffb3996b23f1957a422227de3ec33737fca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 31 May 2018 22:52:06 +0200 Subject: [PATCH 13/13] [ticket/15311] Change service and method name PHPBB3-15311 --- phpBB/config/default/container/services_attachment.yml | 2 +- phpBB/config/default/container/services_db.yml | 10 +++++----- phpBB/config/default/container/services_files.yml | 4 ++-- phpBB/config/default/container/services_filesystem.yml | 2 +- phpBB/includes/acp/acp_database.php | 8 ++++---- phpBB/phpbb/attachment/upload.php | 2 +- phpBB/phpbb/db/extractor/base_extractor.php | 2 +- phpBB/phpbb/files/types/remote.php | 2 +- phpBB/phpbb/files/types/remote_storage.php | 2 +- phpBB/phpbb/filesystem/temp.php | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/phpBB/config/default/container/services_attachment.yml b/phpBB/config/default/container/services_attachment.yml index 0ec8357599..afabbd6f95 100644 --- a/phpBB/config/default/container/services_attachment.yml +++ b/phpBB/config/default/container/services_attachment.yml @@ -36,5 +36,5 @@ services: - '@dispatcher' - '@plupload' - '@storage.attachment' - - '@temp' + - '@filesystem.temp' - '@user' diff --git a/phpBB/config/default/container/services_db.yml b/phpBB/config/default/container/services_db.yml index 4a005d5e50..fe7d42937d 100644 --- a/phpBB/config/default/container/services_db.yml +++ b/phpBB/config/default/container/services_db.yml @@ -34,7 +34,7 @@ services: class: phpbb\db\extractor\mssql_extractor shared: false arguments: - - '@temp' + - '@filesystem.temp' - '@request' - '@dbal.conn.driver' @@ -42,7 +42,7 @@ services: class: phpbb\db\extractor\mysql_extractor shared: false arguments: - - '@temp' + - '@filesystem.temp' - '@request' - '@dbal.conn.driver' @@ -50,7 +50,7 @@ services: class: phpbb\db\extractor\oracle_extractor shared: false arguments: - - '@temp' + - '@filesystem.temp' - '@request' - '@dbal.conn.driver' @@ -58,7 +58,7 @@ services: class: phpbb\db\extractor\postgres_extractor shared: false arguments: - - '@temp' + - '@filesystem.temp' - '@request' - '@dbal.conn.driver' @@ -66,6 +66,6 @@ services: class: phpbb\db\extractor\sqlite3_extractor shared: false arguments: - - '@temp' + - '@filesystem.temp' - '@request' - '@dbal.conn.driver' diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 43be127ea2..d1114c9c68 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -71,7 +71,7 @@ services: arguments: - '@config' - '@files.factory' - - '@temp' + - '@filesystem.temp' - '@language' - '@php_ini' - '@request' @@ -82,7 +82,7 @@ services: arguments: - '@config' - '@files.factory' - - '@temp' + - '@filesystem.temp' - '@language' - '@php_ini' - '@request' diff --git a/phpBB/config/default/container/services_filesystem.yml b/phpBB/config/default/container/services_filesystem.yml index e7832bf37d..15206314b9 100644 --- a/phpBB/config/default/container/services_filesystem.yml +++ b/phpBB/config/default/container/services_filesystem.yml @@ -5,7 +5,7 @@ services: filesystem: class: phpbb\filesystem\filesystem - temp: + filesystem.temp: class: phpbb\filesystem\temp arguments: - '@filesystem' diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 63e9506ad9..c26ecdb849 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) class acp_database { protected $db_tools; - protected $filesystem; + protected $temp; public $u_action; function main($id, $mode) @@ -31,7 +31,7 @@ class acp_database global $phpbb_root_path, $phpbb_container, $phpbb_log, $table_prefix; $this->db_tools = $phpbb_container->get('dbal.tools'); - $this->filesystem = $phpbb_container->get('filesystem'); + $this->temp = $phpbb_container->get('filesystem.temp'); $storage = $phpbb_container->get('storage.backup'); $user->add_lang('acp/database'); @@ -176,7 +176,7 @@ class acp_database $file = $filename . $ext; // Copy to storage using streams - $temp_dir = $this->filesystem->get_temp_dir(); + $temp_dir = $this->temp->get_dir(); $fp = fopen($temp_dir . '/' . $file, 'rb'); @@ -349,7 +349,7 @@ class acp_database } // Copy file to temp folder to decompress it - $temp_file_name = $this->filesystem->get_temp_dir() . '/' . $file_name; + $temp_file_name = $this->temp->get_dir() . '/' . $file_name; try { diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index b3cd4972a1..54515fd0a6 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -240,7 +240,7 @@ class upload { $source = $this->file->get('filename'); $destination_name = 'thumb_' . $this->file->get('realname'); - $destination = $this->temp->get_temp_dir() . '/' . $destination_name; + $destination = $this->temp->get_dir() . '/' . $destination_name; if (create_thumbnail($source, $destination, $this->file->get('mimetype'))) { diff --git a/phpBB/phpbb/db/extractor/base_extractor.php b/phpBB/phpbb/db/extractor/base_extractor.php index b750f064bb..106e047eaa 100644 --- a/phpBB/phpbb/db/extractor/base_extractor.php +++ b/phpBB/phpbb/db/extractor/base_extractor.php @@ -164,7 +164,7 @@ abstract class base_extractor implements extractor_interface if ($store === true) { - $file = $this->temp->get_temp_dir() . '/' . $filename . $ext; + $file = $this->temp->get_dir() . '/' . $filename . $ext; $this->fp = $open($file, 'w'); diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index 3bfd7dc7cd..17c3d7a614 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -146,7 +146,7 @@ class remote extends base $data = $response->getBody(); - $filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->temp->get_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index 8c2ceb6900..d542c5e2f4 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -145,7 +145,7 @@ class remote_storage extends base $data = $response->getBody(); - $filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->temp->get_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/filesystem/temp.php b/phpBB/phpbb/filesystem/temp.php index ffd9cc6973..649221d802 100644 --- a/phpBB/phpbb/filesystem/temp.php +++ b/phpBB/phpbb/filesystem/temp.php @@ -16,7 +16,7 @@ namespace phpbb\filesystem; class temp { /** - * @var string + * @var string Temporary directory path */ protected $temp_dir; @@ -47,7 +47,7 @@ class temp * * @return string returns the directory */ - public function get_temp_dir() + public function get_dir() { return $this->temp_dir; }