Refactor storage admin setting

This commit is contained in:
Philipp 2021-07-18 22:36:06 +02:00
parent 97bafb3a59
commit 3647f6f031
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
3 changed files with 77 additions and 23 deletions

View file

@ -25,7 +25,6 @@ use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\BaseAdmin; use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Psr\Log\LogLevel;
class Storage extends BaseAdmin class Storage extends BaseAdmin
{ {
@ -77,6 +76,7 @@ class Storage extends BaseAdmin
$current_storage_backend = DI::storage(); $current_storage_backend = DI::storage();
$available_storage_backends = []; $available_storage_backends = [];
$available_storage_forms = [];
// show legacy option only if it is the current backend: // show legacy option only if it is the current backend:
// once changed can't be selected anymore // once changed can't be selected anymore
@ -86,14 +86,12 @@ class Storage extends BaseAdmin
foreach (DI::storageManager()->listBackends() as $name => $class) { foreach (DI::storageManager()->listBackends() as $name => $class) {
$available_storage_backends[$name] = $name; $available_storage_backends[$name] = $name;
}
// build storage config form, // build storage config form,
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $current_storage_backend); $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $current_storage_backend);
$storage_form = []; $storage_form = [];
if (!is_null($current_storage_backend) && $current_storage_backend != '') { foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) {
foreach ($current_storage_backend->getOptions() as $name => $info) {
$type = $info[0]; $type = $info[0];
// Backward compatibilty with yesno field description // Backward compatibilty with yesno field description
if ($type == 'yesno') { if ($type == 'yesno') {
@ -102,10 +100,17 @@ class Storage extends BaseAdmin
unset($info[4]); unset($info[4]);
} }
$info[0] = $storage_form_prefix . '_' . $name; $info[0] = $storage_form_prefix . '_' . $option;
$info['type'] = $type; $info['type'] = $type;
$info['field'] = 'field_' . $type . '.tpl'; $info['field'] = 'field_' . $type . '.tpl';
$storage_form[$name] = $info; $storage_form[$option] = $info;
}
if (count($storage_form) > 0) {
$available_storage_forms[] = [
'name' => $name,
'form' => $storage_form,
];
} }
} }
@ -119,7 +124,7 @@ class Storage extends BaseAdmin
'$baseurl' => DI::baseUrl()->get(true), '$baseurl' => DI::baseUrl()->get(true),
'$form_security_token' => self::getFormSecurityToken("admin_storage"), '$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' => ['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],
'$storageform' => $storage_form, '$availablestorageforms' => $available_storage_forms,
]); ]);
} }
} }

View file

@ -4,10 +4,19 @@
<form action="{{$baseurl}}/admin/storage" method="post"> <form action="{{$baseurl}}/admin/storage" method="post">
<input type='hidden' name='form_security_token' value="{{$form_security_token}}"> <input type='hidden' name='form_security_token' value="{{$form_security_token}}">
<h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}} {{include file="field_select.tpl" field=$storagebackend}}
{{foreach from=$storageform item=$field}} <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
<h2>Storage Configuration</h2>
{{foreach from=$availablestorageforms item=$storage}}
<h3>{{$storage.name}}</h3>
{{foreach from=$storage.form item=$field}}
{{include file=$field.field field=$field}} {{include file=$field.field field=$field}}
{{/foreach}} {{/foreach}}
{{/foreach}}
<div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div> <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>

View file

@ -0,0 +1,40 @@
<link rel="stylesheet" href="view/theme/frio/css/mod_admin.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/>
<div id="adminpage" class="adminpage generic-page-wrapper">
<h1>{{$title}} - {{$page}}</h1>
<form action="{{$baseurl}}/admin/storage" method="post">
<input type='hidden' name='form_security_token' value="{{$form_security_token}}">
<h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}}
<input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>
<h2>Storage Configuration</h2>
{{foreach from=$availablestorageforms item=$storage}}
<div class="panel">
<div class="section-subtitle-wrapper panel-heading" role="tab" id="admin-settings-upload">
<h3>
<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#admin-settings" href="#admin-settings-upload-collapse" aria-expanded="false" aria-controls="admin-settings-upload-collapse">
{{$storage.name}}
</a>
</h3>
</div>
<div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
<div class="panel-body">
{{foreach from=$storage.form item=$field}}
{{include file=$field.field field=$field}}
{{/foreach}}
</div>
<div class="panel-footer">
<input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>
</div>
</div>
</div>
{{/foreach}}
</form>
</div>