This commit is contained in:
Philipp 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\Core\Renderer;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Storage\IStorage;
use Friendica\Module\BaseAdmin; use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -35,10 +36,11 @@ 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($_POST['storagebackend'] ?? ''));
/** @var IStorage $newstorage */
$newstorage = DI::storageManager()->getByName($storagebackend);
// save storage backend form // save storage backend form
if (DI::storageManager()->setBackend($storagebackend)) { $storage_opts = $newstorage->getOptions();
$storage_opts = DI::storage()->getOptions();
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend); $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
$storage_opts_data = []; $storage_opts_data = [];
foreach ($storage_opts as $name => $info) { foreach ($storage_opts as $name => $info) {
@ -56,14 +58,15 @@ class Storage extends BaseAdmin
unset($name); unset($name);
unset($info); unset($info);
$storage_form_errors = DI::storage()->saveOptions($storage_opts_data); $storage_form_errors = $newstorage->saveOptions($storage_opts_data);
if (count($storage_form_errors)) { if (count($storage_form_errors)) {
foreach ($storage_form_errors as $name => $err) { foreach ($storage_form_errors as $name => $err) {
notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err); notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
} }
DI::baseUrl()->redirect('admin/storage'); DI::baseUrl()->redirect('admin/storage');
} }
} elseif (!empty($storagebackend)) {
if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) {
notice(DI::l10n()->t('Invalid storage backend setting value.')); notice(DI::l10n()->t('Invalid storage backend setting value.'));
} }
@ -88,7 +91,7 @@ class Storage extends BaseAdmin
$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]|', '', $name);
$storage_form = []; $storage_form = [];
foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) { foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) {
@ -109,6 +112,7 @@ class Storage extends BaseAdmin
if (count($storage_form) > 0) { if (count($storage_form) > 0) {
$available_storage_forms[] = [ $available_storage_forms[] = [
'name' => $name, 'name' => $name,
'prefix' => $storage_form_prefix,
'form' => $storage_form, 'form' => $storage_form,
]; ];
} }

View File

@ -7,7 +7,7 @@
<h2>Storage Backend</h2> <h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}} {{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> <h2>Storage Configuration</h2>
@ -18,7 +18,7 @@
{{/foreach}} {{/foreach}}
{{/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> </form>
</div> </div>

View File

@ -9,27 +9,27 @@
<h2>Storage Backend</h2> <h2>Storage Backend</h2>
{{include file="field_select.tpl" field=$storagebackend}} {{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> <h2>Storage Configuration</h2>
{{foreach from=$availablestorageforms item=$storage}} {{foreach from=$availablestorageforms item=$storage}}
<div class="panel"> <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> <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}} {{$storage.name}}
</a> </a>
</h3> </h3>
</div> </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"> <div class="panel-body">
{{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}}
</div> </div>
<div class="panel-footer"> <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> </div>
</div> </div>