mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/16604] Optimize code and avoid code duplication
PHPBB3-16604
This commit is contained in:
parent
43805f4eaa
commit
473bb417a2
1 changed files with 32 additions and 29 deletions
|
@ -48,6 +48,9 @@ class acp_storage
|
|||
/** @var string */
|
||||
public $page_title;
|
||||
|
||||
/** @var string */
|
||||
public $phpbb_root_path;
|
||||
|
||||
/** @var string */
|
||||
public $tpl_name;
|
||||
|
||||
|
@ -60,7 +63,7 @@ class acp_storage
|
|||
*/
|
||||
public function main($id, $mode)
|
||||
{
|
||||
global $phpbb_container, $phpbb_dispatcher;
|
||||
global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path;
|
||||
|
||||
$this->config = $phpbb_container->get('config');
|
||||
$this->filesystem = $phpbb_container->get('filesystem');
|
||||
|
@ -70,6 +73,7 @@ class acp_storage
|
|||
$this->user = $phpbb_container->get('user');
|
||||
$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;
|
||||
|
||||
// Add necesary language files
|
||||
$this->lang->add_lang(['acp/storage']);
|
||||
|
@ -91,8 +95,6 @@ class acp_storage
|
|||
*/
|
||||
public function overview($id, $mode)
|
||||
{
|
||||
global $phpbb_root_path;
|
||||
|
||||
$form_key = 'acp_storage';
|
||||
add_form_key($form_key);
|
||||
|
||||
|
@ -118,19 +120,7 @@ class acp_storage
|
|||
|
||||
$options = $this->get_provider_options($this->get_current_provider($storage_name));
|
||||
|
||||
if ($this->provider_collection->get_by_class($this->get_current_provider($storage_name))->get_name() == 'local' && isset($options['path']))
|
||||
{
|
||||
$path = $this->get_new_definition($storage_name, 'path');
|
||||
|
||||
if (empty($path))
|
||||
{
|
||||
$messages[] = $this->lang->lang('STORAGE_PATH_NOT_SET', $this->lang->lang('STORAGE_' . strtoupper($storage->get_name()) . '_TITLE'));
|
||||
}
|
||||
else if (!$this->filesystem->is_writable($phpbb_root_path . $path) || !$this->filesystem->exists($phpbb_root_path . $path))
|
||||
{
|
||||
$messages[] = $this->lang->lang('STORAGE_PATH_NOT_EXISTS', $this->lang->lang('STORAGE_' . strtoupper($storage->get_name()) . '_TITLE'));
|
||||
}
|
||||
}
|
||||
$this->validate_path($storage_name, $options, $messages);
|
||||
|
||||
$modified = false;
|
||||
|
||||
|
@ -188,19 +178,7 @@ class acp_storage
|
|||
$storage_name = $storage->get_name();
|
||||
$options = $this->get_provider_options($this->get_current_provider($storage_name));
|
||||
|
||||
if ($this->provider_collection->get_by_class($this->get_current_provider($storage_name))->get_name() == 'local' && isset($options['path']))
|
||||
{
|
||||
$path = $this->get_current_definition($storage_name, 'path');
|
||||
|
||||
if (empty($path))
|
||||
{
|
||||
$messages[] = $this->lang->lang('STORAGE_PATH_NOT_SET', $this->lang->lang('STORAGE_' . strtoupper($storage->get_name()) . '_TITLE'));
|
||||
}
|
||||
else if (!$this->filesystem->is_writable($phpbb_root_path . $path) || !$this->filesystem->exists($phpbb_root_path . $path))
|
||||
{
|
||||
$messages[] = $this->lang->lang('STORAGE_PATH_NOT_EXISTS', $this->lang->lang('STORAGE_' . strtoupper($storage->get_name()) . '_TITLE'));
|
||||
}
|
||||
}
|
||||
$this->validate_path($storage_name, $options, $messages);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -376,4 +354,29 @@ class acp_storage
|
|||
$this->config->set('storage\\' . $storage_name . '\\config\\' . $definition, $this->get_new_definition($storage_name, $definition));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates path
|
||||
*
|
||||
* @param string $storage_name Storage name
|
||||
* @param array $options Storage provider configuration keys
|
||||
* @param array $messages Error messages array
|
||||
* @return array $messages Reference to messages array
|
||||
*/
|
||||
protected function validate_path($storage_name, $options, &$messages)
|
||||
{
|
||||
if ($this->provider_collection->get_by_class($this->get_current_provider($storage_name))->get_name() == 'local' && isset($options['path']))
|
||||
{
|
||||
$path = $this->request->is_set_post('submit') ? $this->get_new_definition($storage_name, 'path') : $this->get_current_definition($storage_name, 'path');
|
||||
|
||||
if (empty($path))
|
||||
{
|
||||
$messages[] = $this->lang->lang('STORAGE_PATH_NOT_SET', $this->lang->lang('STORAGE_' . strtoupper($storage_name) . '_TITLE'));
|
||||
}
|
||||
else if (!$this->filesystem->is_writable($this->phpbb_root_path . $path) || !$this->filesystem->exists($this->phpbb_root_path . $path))
|
||||
{
|
||||
$messages[] = $this->lang->lang('STORAGE_PATH_NOT_EXISTS', $this->lang->lang('STORAGE_' . strtoupper($storage_name) . '_TITLE'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue