Merge pull request #10516 from nupplaphil/bug/storage_manager
Refactor Storage admin section
This commit is contained in:
commit
507b992248
|
@ -212,39 +212,6 @@ class Site extends BaseAdmin
|
|||
$relay_user_tags = !empty($_POST['relay_user_tags']);
|
||||
$active_panel = (!empty($_POST['active_panel']) ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
|
||||
|
||||
$storagebackend = Strings::escapeTags(trim($_POST['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;
|
||||
}
|
||||
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/site' . $active_panel);
|
||||
}
|
||||
} elseif (!empty($storagebackend)) {
|
||||
notice(DI::l10n()->t('Invalid storage backend setting value.'));
|
||||
}
|
||||
|
||||
// Has the directory url changed? If yes, then resubmit the existing profiles there
|
||||
if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) {
|
||||
DI::config()->set('system', 'directory', $global_directory);
|
||||
|
@ -526,40 +493,6 @@ class Site extends BaseAdmin
|
|||
|
||||
$diaspora_able = (DI::baseUrl()->getUrlPath() == '');
|
||||
|
||||
$current_storage_backend = DI::storage();
|
||||
$available_storage_backends = [];
|
||||
|
||||
// show legacy option only if it is the current backend:
|
||||
// once changed can't be selected anymore
|
||||
if ($current_storage_backend == null) {
|
||||
$available_storage_backends[''] = DI::l10n()->t('Database (legacy)');
|
||||
}
|
||||
|
||||
foreach (DI::storageManager()->listBackends() as $name => $class) {
|
||||
$available_storage_backends[$name] = $name;
|
||||
}
|
||||
|
||||
// build storage config form,
|
||||
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|' ,'', $current_storage_backend);
|
||||
|
||||
$storage_form = [];
|
||||
if (!is_null($current_storage_backend) && $current_storage_backend != '') {
|
||||
foreach ($current_storage_backend->getOptions() as $name => $info) {
|
||||
$type = $info[0];
|
||||
// Backward compatibilty with yesno field description
|
||||
if ($type == 'yesno') {
|
||||
$type = 'checkbox';
|
||||
// Remove translated labels Yes No from field info
|
||||
unset($info[4]);
|
||||
}
|
||||
|
||||
$info[0] = $storage_form_prefix . '_' . $name;
|
||||
$info['type'] = $type;
|
||||
$info['field'] = 'field_' . $type . '.tpl';
|
||||
$storage_form[$name] = $info;
|
||||
}
|
||||
}
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/site.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$title' => DI::l10n()->t('Administration'),
|
||||
|
@ -600,8 +533,6 @@ class Site extends BaseAdmin
|
|||
'$hide_help' => ['hide_help', DI::l10n()->t('Hide help entry from navigation menu'), DI::config()->get('system', 'hide_help'), DI::l10n()->t('Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.')],
|
||||
'$singleuser' => ['singleuser', DI::l10n()->t('Single user instance'), DI::config()->get('system', 'singleuser', '---'), DI::l10n()->t('Make this instance multi-user or single-user for the named user'), $user_names],
|
||||
|
||||
'$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,
|
||||
'$maximagesize' => ['maximagesize', DI::l10n()->t('Maximum image size'), DI::config()->get('system', 'maximagesize'), DI::l10n()->t('Maximum size in bytes of uploaded images. Default is 0, which means no limits.')],
|
||||
'$maximagelength' => ['maximagelength', DI::l10n()->t('Maximum image length'), DI::config()->get('system', 'max_image_length'), DI::l10n()->t('Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.')],
|
||||
'$jpegimagequality' => ['jpegimagequality', DI::l10n()->t('JPEG image quality'), DI::config()->get('system', 'jpeg_quality'), DI::l10n()->t('Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.')],
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Admin;
|
||||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Storage\IStorage;
|
||||
use Friendica\Module\BaseAdmin;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class Storage extends BaseAdmin
|
||||
{
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::checkAdminAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
|
||||
|
||||
$storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
|
||||
|
||||
/** @var IStorage $newstorage */
|
||||
$newstorage = DI::storageManager()->getByName($storagebackend);
|
||||
|
||||
// save storage backend form
|
||||
$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] ?? '';
|
||||
}
|
||||
$storage_opts_data[$name] = $value;
|
||||
}
|
||||
unset($name);
|
||||
unset($info);
|
||||
|
||||
$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);
|
||||
}
|
||||
DI::baseUrl()->redirect('admin/storage');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
parent::content($parameters);
|
||||
|
||||
$current_storage_backend = DI::storage();
|
||||
$available_storage_backends = [];
|
||||
$available_storage_forms = [];
|
||||
|
||||
// show legacy option only if it is the current backend:
|
||||
// once changed can't be selected anymore
|
||||
if ($current_storage_backend == null) {
|
||||
$available_storage_backends[''] = DI::l10n()->t('Database (legacy)');
|
||||
}
|
||||
|
||||
foreach (DI::storageManager()->listBackends() as $name => $class) {
|
||||
$available_storage_backends[$name] = $name;
|
||||
|
||||
// build storage config form,
|
||||
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $name);
|
||||
|
||||
$storage_form = [];
|
||||
foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) {
|
||||
$type = $info[0];
|
||||
// Backward compatibilty with yesno field description
|
||||
if ($type == 'yesno') {
|
||||
$type = 'checkbox';
|
||||
// Remove translated labels Yes No from field info
|
||||
unset($info[4]);
|
||||
}
|
||||
|
||||
$info[0] = $storage_form_prefix . '_' . $option;
|
||||
$info['type'] = $type;
|
||||
$info['field'] = 'field_' . $type . '.tpl';
|
||||
$storage_form[$option] = $info;
|
||||
}
|
||||
|
||||
$available_storage_forms[] = [
|
||||
'name' => $name,
|
||||
'prefix' => $storage_form_prefix,
|
||||
'form' => $storage_form,
|
||||
'active' => $name === $current_storage_backend::getName(),
|
||||
];
|
||||
}
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/storage.tpl');
|
||||
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$title' => DI::l10n()->t('Administration'),
|
||||
'$page' => DI::l10n()->t('Storage'),
|
||||
'$save' => DI::l10n()->t('Save'),
|
||||
'$save_activate' => DI::l10n()->t('Save & Activate'),
|
||||
'$activate' => DI::l10n()->t('Activate'),
|
||||
'$save_reload' => DI::l10n()->t('Save & Reload'),
|
||||
'$noconfig' => DI::l10n()->t('This backend doesn\'t have custom settings'),
|
||||
'$baseurl' => DI::baseUrl()->get(true),
|
||||
'$form_security_token' => self::getFormSecurityToken("admin_storage"),
|
||||
'$storagebackend' => $current_storage_backend,
|
||||
'$availablestorageforms' => $available_storage_forms,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -88,6 +88,7 @@ abstract class BaseAdmin extends BaseModule
|
|||
]],
|
||||
'configuration' => [DI::l10n()->t('Configuration'), [
|
||||
'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
|
||||
'storage' => ['admin/storage' , DI::l10n()->t('Storage') , 'storage'],
|
||||
'users' => ['admin/users' , DI::l10n()->t('Users') , 'users'],
|
||||
'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
|
||||
'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
|
||||
|
|
|
@ -198,6 +198,9 @@ return [
|
|||
|
||||
'/site' => [Module\Admin\Site::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]],
|
||||
'/themes/{theme}/embed' => [Module\Admin\Themes\Embed::class, [R::GET, R::POST]],
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -40,11 +40,6 @@
|
|||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
||||
|
||||
<h2>{{$upload}}</h2>
|
||||
{{include file="field_select.tpl" field=$storagebackend}}
|
||||
{{foreach from=$storageform item=$field}}
|
||||
{{include file=$field.field field=$field}}
|
||||
{{/foreach}}
|
||||
<hr>
|
||||
{{include file="field_input.tpl" field=$maximagesize}}
|
||||
{{include file="field_input.tpl" field=$maximagelength}}
|
||||
{{include file="field_input.tpl" field=$jpegimagequality}}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<div id='adminpage'>
|
||||
<h1>{{$title}} - {{$page}}</h1>
|
||||
|
||||
<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>
|
||||
{{if $storage.form}}
|
||||
{{foreach from=$storage.form item=$field}}
|
||||
{{include file=$field.field field=$field}}
|
||||
{{/foreach}}
|
||||
{{else}}
|
||||
{{$noconfig}}
|
||||
{{/if}}
|
||||
|
||||
{{if $storage.form}}
|
||||
<input type="submit" name="submit_save" value="{{$save}}"/>
|
||||
{{if $storage.active}}
|
||||
<input type="submit" name="submit_save_set" value="{{$save_reload}}"/>
|
||||
{{else}}
|
||||
<input type="submit" name="submit_save_set" value="{{$save_activate}}"/>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<br /><input type="submit" name="submit_save_set" {{if $storage.active}}disabled="disabled"{{/if}} value="{{$activate}}"/>
|
||||
{{/if}}
|
||||
</form>
|
||||
{{/foreach}}
|
||||
|
||||
</div>
|
|
@ -100,11 +100,6 @@
|
|||
</div>
|
||||
<div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
|
||||
<div class="panel-body">
|
||||
{{include file="field_select.tpl" field=$storagebackend}}
|
||||
{{foreach from=$storageform item=$field}}
|
||||
{{include file=$field.field field=$field}}
|
||||
{{/foreach}}
|
||||
<hr>
|
||||
{{include file="field_input.tpl" field=$maximagesize}}
|
||||
{{include file="field_input.tpl" field=$maximagelength}}
|
||||
{{include file="field_input.tpl" field=$jpegimagequality}}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<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>
|
||||
|
||||
<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-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}}
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
<div id="admin-settings-{{$storage.prefix}}-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-{{$storage.prefix}}">
|
||||
<div class="panel-body">
|
||||
{{if $storage.form}}
|
||||
{{foreach from=$storage.form item=$field}}
|
||||
{{include file=$field.field field=$field}}
|
||||
{{/foreach}}
|
||||
{{else}}
|
||||
{{$noconfig}}
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
{{if $storage.form}}
|
||||
<input type="submit" name="submit_save" class="btn btn-primary" value="{{$save}}"/>
|
||||
{{if $storage.active}}
|
||||
<input type="submit" name="submit_save_set" class="btn btn-primary" value="{{$save_reload}}"/>
|
||||
{{else}}
|
||||
<input type="submit" name="submit_save_set" class="btn btn-primary" value="{{$save_activate}}"/>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<input type="submit" name="submit_save_set" class="btn btn-primary" {{if $storage.active}}disabled="disabled"{{/if}} value="{{$activate}}"/>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{{/foreach}}
|
||||
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user