use Friendica\Core\Renderer;
use Friendica\DI;
-use Friendica\Model\Storage\IStorage;
+use Friendica\Model\Storage\InvalidClassStorageException;
+use Friendica\Model\Storage\IWritableStorage;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
- $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
- /** @var IStorage $newstorage */
- $newstorage = DI::storageManager()->getByName($storagebackend);
+ $storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
+
+ try {
+ /** @var IWritableStorage $newstorage */
+ $newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
+ } catch (InvalidClassStorageException $storageException) {
+ notice(DI::l10n()->t('Storage backend, %s is invalid.', $storagebackend));
+ DI::baseUrl()->redirect('admin/storage');
+ }
// save storage backend form
$storage_opts = $newstorage->getOptions();
$storage_form_errors = $newstorage->saveOptions($storage_opts_data);
if (count($storage_form_errors)) {
foreach ($storage_form_errors as $name => $err) {
- notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
+ notice(DI::l10n()->t('Storage backend %s error: %s', $storage_opts[$name][1], $err));
}
DI::baseUrl()->redirect('admin/storage');
}
- if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) {
- notice(DI::l10n()->t('Invalid storage backend setting value.'));
+ if (!empty($_POST['submit_save_set'])) {
+ try {
+ /** @var IWritableStorage $newstorage */
+ $newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
+
+ if (!DI::storageManager()->setBackend($newstorage)) {
+ notice(DI::l10n()->t('Invalid storage backend setting value.'));
+ }
+ } catch (InvalidClassStorageException $storageException) {
+ notice(DI::l10n()->t('Invalid storage backend setting value.'));
+ }
}
DI::baseUrl()->redirect('admin/storage');
{
parent::content($parameters);
- $current_storage_backend = DI::storage();
- $available_storage_backends = [];
- $available_storage_forms = [];
-
- // show legacy option only if it is the current backend:
- // once changed can't be selected anymore
- if ($current_storage_backend == null) {
- $available_storage_backends[''] = DI::l10n()->t('Database (legacy)');
- }
+ $current_storage_backend = DI::storage();
+ $available_storage_forms = [];
- foreach (DI::storageManager()->listBackends() as $name => $class) {
- $available_storage_backends[$name] = $name;
+ foreach (DI::storageManager()->listBackends() as $name) {
// build storage config form,
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $name);
$storage_form = [];
- foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) {
+ foreach (DI::storageManager()->getWritableStorageByName($name)->getOptions() as $option => $info) {
$type = $info[0];
// Backward compatibilty with yesno field description
if ($type == 'yesno') {
$storage_form[$option] = $info;
}
- if (count($storage_form) > 0) {
- $available_storage_forms[] = [
- 'name' => $name,
- 'prefix' => $storage_form_prefix,
- 'form' => $storage_form,
- ];
- }
+ $available_storage_forms[] = [
+ 'name' => $name,
+ 'prefix' => $storage_form_prefix,
+ 'form' => $storage_form,
+ 'active' => $current_storage_backend instanceof IWritableStorage && $name === $current_storage_backend::getName(),
+ ];
}
$t = Renderer::getMarkupTemplate('admin/storage.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
+ '$label_current' => DI::l10n()->t('Current Storage Backend'),
+ '$label_config' => DI::l10n()->t('Storage Configuration'),
'$page' => DI::l10n()->t('Storage'),
- '$submit' => DI::l10n()->t('Save Settings'),
- '$clear' => DI::l10n()->t('Clear'),
+ '$save' => DI::l10n()->t('Save'),
+ '$save_use' => DI::l10n()->t('Save & Use storage backend'),
+ '$use' => DI::l10n()->t('Use storage backend'),
+ '$save_reload' => DI::l10n()->t('Save & Reload'),
+ '$noconfig' => DI::l10n()->t('This backend doesn\'t have custom settings'),
'$baseurl' => DI::baseUrl()->get(true),
'$form_security_token' => self::getFormSecurityToken("admin_storage"),
- '$storagebackend' => ['storagebackend', DI::l10n()->t('File storage backend'), $current_storage_backend, DI::l10n()->t('The backend used to store uploaded data. If you change the storage backend, you can manually move the existing files. If you do not do so, the files uploaded before the change will still be available at the old backend. Please see <a href="/help/Settings#1_2_3_1">the settings documentation</a> for more information about the choices and the moving procedure.'), $available_storage_backends],
+ '$storagebackend' => $current_storage_backend instanceof IWritableStorage ? $current_storage_backend::getName() : DI::l10n()->t('Database (legacy)'),
'$availablestorageforms' => $available_storage_forms,
]);
}