mirror of
https://github.com/friendica/friendica
synced 2025-04-29 12:24:24 +02:00
Split Storage usage and Storage configuration
This commit is contained in:
parent
ac9e5df614
commit
065b46c721
12 changed files with 379 additions and 208 deletions
|
@ -22,8 +22,6 @@
|
|||
namespace Friendica\Model\Storage;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
/**
|
||||
|
@ -40,30 +38,17 @@ class Filesystem implements IWritableStorage
|
|||
{
|
||||
const NAME = 'Filesystem';
|
||||
|
||||
// Default base folder
|
||||
const DEFAULT_BASE_FOLDER = 'storage';
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var string */
|
||||
private $basePath;
|
||||
|
||||
/** @var L10n */
|
||||
private $l10n;
|
||||
|
||||
/**
|
||||
* Filesystem constructor.
|
||||
*
|
||||
* @param IConfig $config
|
||||
* @param L10n $l10n
|
||||
* @param string $filesystemPath
|
||||
*/
|
||||
public function __construct(IConfig $config, L10n $l10n)
|
||||
public function __construct(string $filesystemPath = FilesystemConfig::DEFAULT_BASE_FOLDER)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->l10n = $l10n;
|
||||
|
||||
$path = $this->config->get('storage', 'filesystem_path', self::DEFAULT_BASE_FOLDER);
|
||||
$path = $filesystemPath;
|
||||
$this->basePath = rtrim($path, '/');
|
||||
}
|
||||
|
||||
|
@ -176,37 +161,6 @@ class Filesystem implements IWritableStorage
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'storagepath' => [
|
||||
'input',
|
||||
$this->l10n->t('Storage base path'),
|
||||
$this->basePath,
|
||||
$this->l10n->t('Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function saveOptions(array $data): array
|
||||
{
|
||||
$storagePath = $data['storagepath'] ?? '';
|
||||
if ($storagePath === '' || !is_dir($storagePath)) {
|
||||
return [
|
||||
'storagepath' => $this->l10n->t('Enter a valid existing folder')
|
||||
];
|
||||
};
|
||||
$this->config->set('storage', 'filesystem_path', $storagePath);
|
||||
$this->basePath = $storagePath;
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue