]> git.mxchange.org Git - friendica.git/commitdiff
Allow setting & saving storages per type
authorPhilipp <admin@philipp.info>
Tue, 20 Jul 2021 21:33:35 +0000 (23:33 +0200)
committerPhilipp <admin@philipp.info>
Sat, 24 Jul 2021 17:00:58 +0000 (19:00 +0200)
src/Module/Admin/Storage.php
static/routes.config.php
view/templates/admin/storage.tpl
view/theme/frio/templates/admin/storage.tpl

index 689f67d372391d5f2b0e5a43e873b9d6bb4afbb8..6b07cf5b05a03f049a4c15166d1acc3a06e51e13 100644 (file)
@@ -35,7 +35,8 @@ class Storage extends BaseAdmin
 
                self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
 
-               $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
+               $storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
+
                /** @var IStorage $newstorage */
                $newstorage = DI::storageManager()->getByName($storagebackend);
 
@@ -66,8 +67,10 @@ class Storage extends BaseAdmin
                        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'])) {
+                       if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) {
+                               notice(DI::l10n()->t('Invalid storage backend setting value.'));
+                       }
                }
 
                DI::baseUrl()->redirect('admin/storage');
@@ -109,13 +112,11 @@ class Storage extends BaseAdmin
                                $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,
+                       ];
                }
 
                $t = Renderer::getMarkupTemplate('admin/storage.tpl');
@@ -123,11 +124,12 @@ class Storage extends BaseAdmin
                return Renderer::replaceMacros($t, [
                        '$title'                 => DI::l10n()->t('Administration'),
                        '$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'),
                        '$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,
                        '$availablestorageforms' => $available_storage_forms,
                ]);
        }
index 05e266ff1023efad588e5da77a4b98a41085f371..74cc59df810cb419fba530ba04092e3995e45d0f 100644 (file)
@@ -198,7 +198,8 @@ return [
 
                '/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/{theme}'       => [Module\Admin\Themes\Details::class, [R::GET, R::POST]],
index 10bdb1e0f8dd023b5b47526943da36341a608d7a..bfe6511bf0697a36ddbd8374f7c186f497b1bec0 100644 (file)
@@ -1,24 +1,23 @@
 <div id='adminpage'>
        <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}}
-               <div class="submit"><input type="submit" name="page_storage" value="{{$submit}}" /></div>
+               <h2>Current Storage Backend: <b>{{$storagebackend}}</b></h2>
 
                <h2>Storage Configuration</h2>
 
                {{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>
                {{foreach from=$storage.form item=$field}}
                {{include file=$field.field field=$field}}
                {{/foreach}}
-               {{/foreach}}
-
-               <div class="submit"><input type="submit" name="page_storage" value="{{$submit}}" /></div>
 
+               {{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}}
+
 </div>
index ed889bf1d8932fdc32a443b134ebe9fcbef54998..0827c06acf49dfd5e65a041f85e84529b1b74bf2 100644 (file)
@@ -3,19 +3,17 @@
 <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_storage" class="btn btn-primary" value="{{$submit}}"/>
+       <div class="well well-lg">
+                       Current Storage Backend: <b>{{$storagebackend}}</b>
+       </div>
 
                <h2>Storage Configuration</h2>
 
                {{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="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>
                                        <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}}
                                        {{/foreach}}
                                </div>
                                <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>
+       </form>
 
                {{/foreach}}