1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-05 00:07:44 +02:00

Merge pull request #6753 from rubencm/ticket/17361

[ticket/17361] Improve storage
This commit is contained in:
Marc Alexander
2025-02-22 15:06:48 +01:00
committed by GitHub
37 changed files with 890 additions and 920 deletions

View File

@@ -162,12 +162,7 @@ class acp_database
throw new \phpbb\exception\runtime_exception('CANNOT_OPEN_FILE');
}
$storage->write_stream($file, $fp);
if (is_resource($fp))
{
fclose($fp);
}
$storage->write($file, $fp);
// Remove file from tmp
@unlink($temp_dir . '/' . $file);
@@ -279,7 +274,7 @@ class acp_database
try
{
$stream = $storage->read_stream($backup_info['file_name']);
$stream = $storage->read($backup_info['file_name']);
$fp = fopen($temp_file_name, 'w+b');
stream_copy_to_stream($stream, $fp);

View File

@@ -496,7 +496,7 @@ class acp_main
$upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
$storage_avatar = $phpbb_container->get('storage.avatar');
$avatar_dir_size = get_formatted_filesize($storage_avatar->get_size());
$avatar_dir_size = get_formatted_filesize($storage_avatar->total_size());
if ($posts_per_day > $total_posts)
{

View File

@@ -378,7 +378,6 @@ class acp_storage
foreach ($this->storage_collection as $storage)
{
$storage_name = $storage->get_name();
$options = $this->storage_helper->get_provider_options($this->storage_helper->get_current_provider($storage_name));
$modified = false;
@@ -389,6 +388,8 @@ class acp_storage
}
else
{
$options = $this->storage_helper->get_provider_options($this->storage_helper->get_current_provider($storage_name));
// Check if options have been modified
foreach (array_keys($options) as $definition)
{
@@ -431,8 +432,8 @@ class acp_storage
$storage_stats[] = [
'name' => $this->lang->lang('STORAGE_' . strtoupper($storage->get_name()) . '_TITLE'),
'files' => $storage->get_num_files(),
'size' => get_formatted_filesize($storage->get_size()),
'files' => $storage->total_files(),
'size' => get_formatted_filesize($storage->total_size()),
'free_space' => $free_space,
];
}
@@ -535,30 +536,29 @@ class acp_storage
$this->validate_path($storage_name, $messages);
// Check options
$new_options = $this->storage_helper->get_provider_options($this->request->variable([$storage_name, 'provider'], ''));
$new_provider = $this->provider_collection->get_by_class($this->request->variable([$storage_name, 'provider'], ''));
foreach ($new_options as $definition_key => $definition_value)
foreach ($new_provider->get_options() as $definition_key => $definition_value)
{
$provider = $this->provider_collection->get_by_class($this->request->variable([$storage_name, 'provider'], ''));
$definition_title = $this->lang->lang('STORAGE_ADAPTER_' . strtoupper($provider->get_name()) . '_OPTION_' . strtoupper($definition_key));
$definition_title = $definition_value['title'];
$value = $this->request->variable([$storage_name, $definition_key], '');
switch ($definition_value['tag'])
switch ($definition_value['form_macro']['tag'])
{
case 'text':
if ($definition_value['type'] == 'email' && filter_var($value, FILTER_VALIDATE_EMAIL))
if ($definition_value['form_macro']['type'] === 'email' && filter_var($value, FILTER_VALIDATE_EMAIL))
{
$messages[] = $this->lang->lang('STORAGE_FORM_TYPE_EMAIL_INCORRECT_FORMAT', $definition_title, $storage_title);
}
$maxlength = $definition_value['max'] ?? 255;
$maxlength = $definition_value['form_macro']['max'] ?? 255;
if (strlen($value) > $maxlength)
{
$messages[] = $this->lang->lang('STORAGE_FORM_TYPE_TEXT_TOO_LONG', $definition_title, $storage_title);
}
if ($provider->get_name() == 'local' && $definition_key == 'path')
if ($new_provider->get_name() === 'local' && $definition_key === 'path')
{
$path = $value;
@@ -575,7 +575,7 @@ class acp_storage
case 'radio':
$found = false;
foreach ($definition_value['buttons'] as $button)
foreach ($definition_value['form_macro']['buttons'] as $button)
{
if ($button['value'] == $value)
{
@@ -592,7 +592,7 @@ class acp_storage
case 'select':
$found = false;
foreach ($definition_value['options'] as $option)
foreach ($definition_value['form_macro']['options'] as $option)
{
if ($option['value'] == $value)
{
@@ -619,10 +619,18 @@ class acp_storage
*/
protected function validate_path(string $storage_name, array &$messages) : void
{
$current_provider = $this->storage_helper->get_current_provider($storage_name);
$options = $this->storage_helper->get_provider_options($current_provider);
if ($this->request->is_set_post('submit'))
{
$provider = $this->request->variable([$storage_name, 'provider'], '');
}
else
{
$provider = $this->storage_helper->get_current_provider($storage_name);
}
if ($this->provider_collection->get_by_class($current_provider)->get_name() == 'local' && isset($options['path']))
$options = $this->storage_helper->get_provider_options($provider);
if ($this->provider_collection->get_by_class($provider)->get_name() === 'local' && isset($options['path']))
{
$path = $this->request->is_set_post('submit') ? $this->request->variable([$storage_name, 'path'], '') : $this->storage_helper->get_current_definition($storage_name, 'path');

View File

@@ -2126,7 +2126,8 @@ function group_correct_avatar($group_id, $old_entry)
try
{
$storage->rename($old_filename, $new_filename);
$storage->write($new_filename, $storage->read($old_filename));
$storage->delete($old_filename);
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_avatar = \'' . $db->sql_escape($new_entry) . "'