1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 08:47:45 +02:00

[ticket/15699] Fixes code review

PHPBB3-15699
This commit is contained in:
Ruben Calvo
2024-05-25 16:35:44 +02:00
parent de73a2e3d7
commit 195fb59b4e
6 changed files with 181 additions and 35 deletions

View File

@@ -15,7 +15,6 @@ namespace phpbb\storage;
use phpbb\config\config;
use phpbb\di\service_collection;
use phpbb\storage\adapter\adapter_interface;
use phpbb\storage\exception\storage_exception;
class adapter_factory
@@ -54,9 +53,9 @@ class adapter_factory
*
* @param string $storage_name
*
* @return adapter_interface
* @return mixed
*/
public function get(string $storage_name)
public function get(string $storage_name): mixed
{
$provider_class = $this->config['storage\\' . $storage_name . '\\provider'];
$provider = $this->providers->get_by_class($provider_class);
@@ -71,7 +70,15 @@ class adapter_factory
return $this->get_with_options($storage_name, $options);
}
public function get_with_options(string $storage_name, array $options)
/**
* Obtains a configured adapters for a given storage with custom options
*
* @param string $storage_name
* @param array $options
*
* @return mixed
*/
public function get_with_options(string $storage_name, array $options): mixed
{
$provider_class = $this->config['storage\\' . $storage_name . '\\provider'];
$provider = $this->providers->get_by_class($provider_class);

View File

@@ -21,31 +21,41 @@ class helper
/** @var config */
protected $config;
/** @var service_collection */
protected $provider_collection;
/** @var service_collection */
protected $adapter_collection;
/** @var adapter_factory */
protected $adapter_factory;
/** @var state_helper */
protected $state_helper;
public function __construct(config $config, service_collection $provider_collection, service_collection $adapter_collection, adapter_factory $adapter_factory, state_helper $state_helper)
/** @var service_collection */
protected $provider_collection;
/** @var service_collection */
protected $adapter_collection;
/**
* Constructor
*
* @param config $config
* @param adapter_factory $adapter_factory
* @param state_helper $state_helper
* @param service_collection $provider_collection
* @param service_collection $adapter_collection
*/
public function __construct(config $config, adapter_factory $adapter_factory, state_helper $state_helper, service_collection $provider_collection, service_collection $adapter_collection)
{
$this->config = $config;
$this->provider_collection = $provider_collection;
$this->adapter_collection = $adapter_collection;
$this->adapter_factory = $adapter_factory;
$this->state_helper = $state_helper;
$this->provider_collection = $provider_collection;
$this->adapter_collection = $adapter_collection;
}
/**
* Get adapter definitions from a provider
*
* @param string $provider_class Provider class
*
* @return array Adapter definitions
*/
public function get_provider_options(string $provider_class) : array
@@ -57,6 +67,7 @@ class helper
* Get the current provider from config
*
* @param string $storage_name Storage name
*
* @return string The current provider
*/
public function get_current_provider(string $storage_name) : string
@@ -69,6 +80,7 @@ class helper
*
* @param string $storage_name Storage name
* @param string $definition Definition
*
* @return string Definition value
*/
public function get_current_definition(string $storage_name, string $definition) : string
@@ -102,7 +114,7 @@ class helper
*
* @return mixed Storage adapter instance
*/
public function get_new_adapter(string $storage_name)
public function get_new_adapter(string $storage_name): mixed
{
static $adapters = [];
@@ -123,6 +135,13 @@ class helper
return $adapters[$storage_name];
}
/**
* Delete configuration options for a given storage
*
* @param string $storage_name
*
* @return void
*/
public function delete_storage_options(string $storage_name): void
{
$provider = $this->get_current_provider($storage_name);
@@ -134,16 +153,41 @@ class helper
}
}
/**
* Set a provider in configuration for a given storage
*
* @param string $storage_name
* @param string $provider
*
* @return void
*/
public function set_storage_provider(string $storage_name, string $provider): void
{
$this->config->set('storage\\' . $storage_name . '\\provider', $provider);
}
/**
* Set storage options in configuration for a given storage
*
* @param string $storage_name
* @param string $definition
* @param string $value
*
* @return void
*/
public function set_storage_definition(string $storage_name, string $definition, string $value): void
{
$this->config->set('storage\\' . $storage_name . '\\config\\' . $definition, $value);
}
/**
* Copy a file from the current adapter to the new adapter
*
* @param $storage_name
* @param $file
*
* @return void
*/
public function copy_file_to_new_adapter($storage_name, $file): void
{
$current_adapter = $this->get_current_adapter($storage_name);
@@ -166,7 +210,6 @@ class helper
*/
public function update_storage_config(string $storage_name) : void
{
// Remove old storage config
$this->delete_storage_options($storage_name);

View File

@@ -31,6 +31,11 @@ class state_helper
/** @var service_collection */
protected $provider_collection;
/**
* @param config $config
* @param db_text $config_text
* @param service_collection $provider_collection
*/
public function __construct(config $config, db_text $config_text, service_collection $provider_collection)
{
$this->config = $config;
@@ -48,6 +53,13 @@ class state_helper
return !empty(json_decode($this->config_text->get('storage_update_state'), true));
}
/**
* Get new provider for the specified storage
*
* @param string $storage_name
*
* @return string
*/
public function new_provider(string $storage_name): string
{
$state = $this->load_state();
@@ -55,6 +67,14 @@ class state_helper
return $state['storages'][$storage_name]['provider'];
}
/**
* Get new definition value for the specified storage
*
* @param string $storage_name
* @param string $definition
*
* @return string
*/
public function new_definition_value(string $storage_name, string $definition): string
{
$state = $this->load_state();
@@ -62,6 +82,11 @@ class state_helper
return $state['storages'][$storage_name]['config'][$definition];
}
/**
* Get the update type
*
* @return update_type
*/
public function update_type(): update_type
{
$state = $this->load_state();
@@ -69,6 +94,11 @@ class state_helper
return update_type::from($state['update_type']);
}
/**
* Get the current storage index
*
* @return int
*/
public function storage_index(): int
{
$state = $this->load_state();
@@ -76,6 +106,13 @@ class state_helper
return $state['storage_index'];
}
/**
* Update the storage index
*
* @param int $storage_index
*
* @return void
*/
public function set_storage_index(int $storage_index): void
{
$state = $this->load_state();
@@ -85,6 +122,11 @@ class state_helper
$this->save_state($state);
}
/**
* Get the current remove storage index
*
* @return int
*/
public function remove_storage_index(): int
{
$state = $this->load_state();
@@ -92,6 +134,13 @@ class state_helper
return $state['remove_storage_index'];
}
/**
* Update the remove storage index
*
* @param int $storage_index
*
* @return void
*/
public function set_remove_storage_index(int $storage_index): void
{
$state = $this->load_state();
@@ -101,6 +150,11 @@ class state_helper
$this->save_state($state);
}
/**
* Get the file index
*
* @return int
*/
public function file_index(): int
{
$state = $this->load_state();
@@ -108,6 +162,12 @@ class state_helper
return $state['file_index'];
}
/**
* Set the file index
*
* @param int $file_index
* @return void
*/
public function set_file_index(int $file_index): void
{
$state = $this->load_state();
@@ -117,6 +177,11 @@ class state_helper
$this->save_state($state);
}
/**
* Get the storage names to be updated
*
* @return array
*/
public function storages(): array
{
$state = $this->load_state();
@@ -178,7 +243,7 @@ class state_helper
*/
public function clear_state(): void
{
$this->save_state([]);
$this->save_state();
}
/**
@@ -210,5 +275,4 @@ class state_helper
{
$this->config_text->set('storage_update_state', json_encode($state, JSON_THROW_ON_ERROR));
}
}