Allow setting & saving storages per type

This commit is contained in:
Philipp 2021-07-20 23:33:35 +02:00
parent 2fe28af74f
commit e19b9824cd
No known key found for this signature in database
GPG Key ID: 9A28B7D4FF5667BD
4 changed files with 36 additions and 32 deletions

View File

@ -35,7 +35,8 @@ class Storage extends BaseAdmin
self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage'); self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
$storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? '')); $storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
/** @var IStorage $newstorage */ /** @var IStorage $newstorage */
$newstorage = DI::storageManager()->getByName($storagebackend); $newstorage = DI::storageManager()->getByName($storagebackend);
@ -66,8 +67,10 @@ class Storage extends BaseAdmin
DI::baseUrl()->redirect('admin/storage'); DI::baseUrl()->redirect('admin/storage');
} }
if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) { if (!empty($_POST['submit_save_set'])) {
notice(DI::l10n()->t('Invalid storage backend setting value.')); if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) {
notice(DI::l10n()->t('Invalid storage backend setting value.'));
}
} }
DI::baseUrl()->redirect('admin/storage'); DI::baseUrl()->redirect('admin/storage');
@ -109,13 +112,11 @@ class Storage extends BaseAdmin
$storage_form[$option] = $info; $storage_form[$option] = $info;
} }
if (count($storage_form) > 0) { $available_storage_forms[] = [
$available_storage_forms[] = [ 'name' => $name,
'name' => $name, 'prefix' => $storage_form_prefix,
'prefix' => $storage_form_prefix, 'form' => $storage_form,
'form' => $storage_form, ];
];
}
} }
$t = Renderer::getMarkupTemplate('admin/storage.tpl'); $t = Renderer::getMarkupTemplate('admin/storage.tpl');
@ -123,11 +124,12 @@ class Storage extends BaseAdmin
return Renderer::replaceMacros($t, [ return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'), '$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Storage'), '$page' => DI::l10n()->t('Storage'),
'$submit' => DI::l10n()->t('Save Settings'), '$save' => DI::l10n()->t('Save Settings'),
'$save_set' => DI::l10n()->t('Set Backend'),
'$clear' => DI::l10n()->t('Clear'), '$clear' => DI::l10n()->t('Clear'),
'$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' => $current_storage_backend,
'$availablestorageforms' => $available_storage_forms, '$availablestorageforms' => $available_storage_forms,
]); ]);
} }

View File

@ -198,7 +198,8 @@ return [
'/site' => [Module\Admin\Site::class, [R::GET, R::POST]], '/site' => [Module\Admin\Site::class, [R::GET, R::POST]],
'/storage' => [Module\Admin\Storage::class, [R::GET, R::POST]], '/storage' => [Module\Admin\Storage::class, [R::GET, R::POST]],
'/storage/{name}' => [Module\Admin\Storage::class, [ R::POST]],
'/themes' => [Module\Admin\Themes\Index::class, [R::GET, R::POST]], '/themes' => [Module\Admin\Themes\Index::class, [R::GET, R::POST]],
'/themes/{theme}' => [Module\Admin\Themes\Details::class, [R::GET, R::POST]], '/themes/{theme}' => [Module\Admin\Themes\Details::class, [R::GET, R::POST]],

View File

@ -1,24 +1,23 @@
<div id='adminpage'> <div id='adminpage'>
<h1>{{$title}} - {{$page}}</h1> <h1>{{$title}} - {{$page}}</h1>
<form action="{{$baseurl}}/admin/storage" method="post"> <h2>Current Storage Backend: <b>{{$storagebackend}}</b></h2>
<input type='hidden' name='form_security_token' value="{{$form_security_token}}">
<h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}}
<div class="submit"><input type="submit" name="page_storage" value="{{$submit}}" /></div>
<h2>Storage Configuration</h2> <h2>Storage Configuration</h2>
{{foreach from=$availablestorageforms item=$storage}} {{foreach from=$availablestorageforms item=$storage}}
<form action="{{$baseurl}}/admin/storage/{{$storage.prefix}}" method="post">
<input type='hidden' name='form_security_token' value="{{$form_security_token}}">
<h3>{{$storage.name}}</h3> <h3>{{$storage.name}}</h3>
{{foreach from=$storage.form item=$field}} {{foreach from=$storage.form item=$field}}
{{include file=$field.field field=$field}} {{include file=$field.field field=$field}}
{{/foreach}} {{/foreach}}
{{if $storage.form}}
<div class="submit"><input type="submit" name="submit_save" value="{{$save}}" /></div>
{{/if}}
<div class="submit"><input type="submit" name="submit_save_set" value="{{$save_set}}" /></div>
</form>
{{/foreach}} {{/foreach}}
<div class="submit"><input type="submit" name="page_storage" value="{{$submit}}" /></div>
</form>
</div> </div>

View File

@ -3,19 +3,17 @@
<div id="adminpage" class="adminpage generic-page-wrapper"> <div id="adminpage" class="adminpage generic-page-wrapper">
<h1>{{$title}} - {{$page}}</h1> <h1>{{$title}} - {{$page}}</h1>
<form action="{{$baseurl}}/admin/storage" method="post"> <div class="well well-lg">
<input type='hidden' name='form_security_token' value="{{$form_security_token}}"> Current Storage Backend: <b>{{$storagebackend}}</b>
</div>
<h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}}
<input type="submit" name="page_storage" class="btn btn-primary" value="{{$submit}}"/>
<h2>Storage Configuration</h2> <h2>Storage Configuration</h2>
{{foreach from=$availablestorageforms item=$storage}} {{foreach from=$availablestorageforms item=$storage}}
<form action="{{$baseurl}}/admin/storage/{{$storage.prefix}}" method="post">
<input type='hidden' name='form_security_token' value="{{$form_security_token}}">
<div class="panel"> <div class="panel">
<div class="section-subtitle-wrapper panel-heading" role="tab" id="admin-settings-{{$storage.prefix}}"> <div class="section-subtitle-wrapper panel-title" role="tab" id="admin-settings-{{$storage.prefix}}">
<h3> <h3>
<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"> <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}} {{$storage.name}}
@ -29,10 +27,14 @@
{{/foreach}} {{/foreach}}
</div> </div>
<div class="panel-footer"> <div class="panel-footer">
<input type="submit" name="page_storage" class="btn btn-primary" value="{{$submit}}"/> {{if $storage.form}}
<input type="submit" name="submit_save" class="btn btn-primary" value="{{$save}}"/>
{{/if}}
<input type="submit" name="submit_save_set" class="btn btn-primary" value="{{$save_set}}"/>
</div> </div>
</div> </div>
</div> </div>
</form>
{{/foreach}} {{/foreach}}