1
1
Fork 0
This commit is contained in:
Philipp Holzer 2021-07-18 23:09:45 +02:00
parent 3647f6f031
commit cbe522ee82
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
3 changed files with 36 additions and 32 deletions

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Admin;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Storage\IStorage;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
@ -35,35 +36,37 @@ class Storage extends BaseAdmin
self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
$storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
/** @var IStorage $newstorage */
$newstorage = DI::storageManager()->getByName($storagebackend);
// save storage backend form
if (DI::storageManager()->setBackend($storagebackend)) {
$storage_opts = DI::storage()->getOptions();
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
$storage_opts_data = [];
foreach ($storage_opts as $name => $info) {
$fieldname = $storage_form_prefix . '_' . $name;
switch ($info[0]) { // type
case 'checkbox':
case 'yesno':
$value = !empty($_POST[$fieldname]);
break;
default:
$value = $_POST[$fieldname] ?? '';
}
$storage_opts_data[$name] = $value;
$storage_opts = $newstorage->getOptions();
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
$storage_opts_data = [];
foreach ($storage_opts as $name => $info) {
$fieldname = $storage_form_prefix . '_' . $name;
switch ($info[0]) { // type
case 'checkbox':
case 'yesno':
$value = !empty($_POST[$fieldname]);
break;
default:
$value = $_POST[$fieldname] ?? '';
}
unset($name);
unset($info);
$storage_opts_data[$name] = $value;
}
unset($name);
unset($info);
$storage_form_errors = DI::storage()->saveOptions($storage_opts_data);
if (count($storage_form_errors)) {
foreach ($storage_form_errors as $name => $err) {
notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
}
DI::baseUrl()->redirect('admin/storage');
$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);
}
} elseif (!empty($storagebackend)) {
DI::baseUrl()->redirect('admin/storage');
}
if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) {
notice(DI::l10n()->t('Invalid storage backend setting value.'));
}
@ -88,7 +91,7 @@ class Storage extends BaseAdmin
$available_storage_backends[$name] = $name;
// 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]|', '', $name);
$storage_form = [];
foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) {
@ -109,6 +112,7 @@ class Storage extends BaseAdmin
if (count($storage_form) > 0) {
$available_storage_forms[] = [
'name' => $name,
'prefix' => $storage_form_prefix,
'form' => $storage_form,
];
}

View file

@ -7,7 +7,7 @@
<h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}}
<div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
<div class="submit"><input type="submit" name="page_storage" value="{{$submit}}" /></div>
<h2>Storage Configuration</h2>
@ -18,7 +18,7 @@
{{/foreach}}
{{/foreach}}
<div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
<div class="submit"><input type="submit" name="page_storage" value="{{$submit}}" /></div>
</form>
</div>

View file

@ -9,27 +9,27 @@
<h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}}
<input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>
<input type="submit" name="page_storage" 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">
<div class="section-subtitle-wrapper panel-heading" role="tab" id="admin-settings-{{$storage.prefix}}">
<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">
<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#admin-settings" href="#admin-settings-{{$storage.prefix}}-collapse" aria-expanded="false" aria-controls="admin-settings-{{$storage.prefix}}-collapse">
{{$storage.name}}
</a>
</h3>
</div>
<div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
<div id="admin-settings-{{$storage.prefix}}-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-{{$storage.prefix}}">
<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}}"/>
<input type="submit" name="page_storage" class="btn btn-primary" value="{{$submit}}"/>
</div>
</div>
</div>