diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 3886f006d1..49535c1a74 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -97,6 +97,15 @@ {% endfor %} {% endfor %} +
+
+

{{ lang('STORAGE_REMOVE_OLD_FILES_EXPLAIN') }}
+
+ +
+
+
+
{{ lang('SUBMIT') }}   diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 3ea1036167..f9e0e75ae0 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -24,6 +24,9 @@ class acp_storage /** @var \phpbb\config\config $config */ protected $config; + /** @var \db\driver\driver_interface $db */ + protected $db; + /** @var \phpbb\language\language $lang */ protected $lang; @@ -33,6 +36,9 @@ class acp_storage /** @var \phpbb\template\template */ protected $template; + /** @var \phpbb\di\service_collection */ + protected $adapter_collection; + /** @var \phpbb\di\service_collection */ protected $provider_collection; @@ -63,10 +69,13 @@ class acp_storage global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path; $this->config = $phpbb_container->get('config'); + $this->db = $phpbb_container->get('dbal.conn'); $this->filesystem = $phpbb_container->get('filesystem'); $this->lang = $phpbb_container->get('language'); $this->request = $phpbb_container->get('request'); $this->template = $phpbb_container->get('template'); + $this->user = $phpbb_container->get('user'); + $this->adapter_collection = $phpbb_container->get('storage.adapter_collection'); $this->provider_collection = $phpbb_container->get('storage.provider_collection'); $this->storage_collection = $phpbb_container->get('storage.storage_collection'); $this->phpbb_root_path = $phpbb_root_path; @@ -153,6 +162,31 @@ class acp_storage { foreach ($modified_storages as $storage_name) { + $current_adapter = $this->get_current_adapter($storage_name); + $new_adapter = $this->get_new_adapter($storage_name); + + $sql = 'SELECT file_path + FROM ' . STORAGE_TABLE . " + WHERE storage = '" . $storage_name . "'"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $stream = $current_adapter->read_stream($row['file_path']); + $new_adapter->write_stream($row['file_path'], $stream); + fclose($stream); + } + + $this->db->sql_rowseek(0, $result); + + if ($this->request->variable('remove_old', false)) + { + while ($row = $this->db->sql_fetchrow($result)) + { + $current_adapter->delete($row['file_path']); + } + } + $this->update_storage_config($storage_name); } @@ -375,4 +409,42 @@ class acp_storage } } } + + protected function get_current_adapter($storage_name) + { + $provider = $this->get_current_provider($storage_name); + $provider_class = $this->provider_collection->get_by_class($provider); + + $adapter = $this->adapter_collection->get_by_class($provider_class->get_adapter_class()); + $definitions = $this->get_provider_options($provider); + + $options = []; + foreach (array_keys($definitions) as $definition) + { + $options[$definition] = $this->get_current_definition($storage_name, $definition); + } + + $adapter->configure($options); + + return $adapter; + } + + protected function get_new_adapter($storage_name) + { + $provider = $this->get_new_provider($storage_name); + $provider_class = $this->provider_collection->get_by_class($provider); + + $adapter = $this->adapter_collection->get_by_class($provider_class->get_adapter_class()); + $definitions = $this->get_provider_options($provider); + + $options = []; + foreach (array_keys($definitions) as $definition) + { + $options[$definition] = $this->get_new_definition($storage_name, $definition); + } + + $adapter->configure($options); + + return $adapter; + } } diff --git a/phpBB/language/en/acp/storage.php b/phpBB/language/en/acp/storage.php index 98ad84df53..ae3c007c4a 100644 --- a/phpBB/language/en/acp/storage.php +++ b/phpBB/language/en/acp/storage.php @@ -39,15 +39,17 @@ if (empty($lang) || !is_array($lang)) $lang = array_merge($lang, array( // Template - 'STORAGE_TITLE' => 'Storage Settings', - 'STORAGE_TITLE_EXPLAIN' => 'Change storage providers for the file storage types of phpBB. Choose local or remote providers to store files added to or created by phpBB.', - 'STORAGE_SELECT' => 'Select storage', - 'STORAGE_SELECT_DESC' => 'Select a storage from the list.', - 'STORAGE_NAME' => 'Storage name', - 'STORAGE_NUM_FILES' => 'Number of files', - 'STORAGE_SIZE' => 'Size', - 'STORAGE_FREE' => 'Available space', - 'STORAGE_UNKNOWN' => 'Unknown', + 'STORAGE_TITLE' => 'Storage Settings', + 'STORAGE_TITLE_EXPLAIN' => 'Change storage providers for the file storage types of phpBB. Choose local or remote providers to store files added to or created by phpBB.', + 'STORAGE_SELECT' => 'Select storage', + 'STORAGE_SELECT_DESC' => 'Select a storage from the list.', + 'STORAGE_NAME' => 'Storage name', + 'STORAGE_NUM_FILES' => 'Number of files', + 'STORAGE_SIZE' => 'Size', + 'STORAGE_FREE' => 'Available space', + 'STORAGE_UNKNOWN' => 'Unknown', + 'STORAGE_REMOVE_OLD_FILES' => 'Remove old files', + 'STORAGE_REMOVE_OLD_FILES_EXPLAIN' => 'Remove old files after they are copied to the new storage system.', // Storage names 'STORAGE_ATTACHMENT_TITLE' => 'Attachments storage',