Extract Storage admin section to own page
This commit is contained in:
parent
e05c1821c2
commit
97bafb3a59
7 changed files with 143 additions and 79 deletions
|
@ -212,39 +212,6 @@ class Site extends BaseAdmin
|
||||||
$relay_user_tags = !empty($_POST['relay_user_tags']);
|
$relay_user_tags = !empty($_POST['relay_user_tags']);
|
||||||
$active_panel = (!empty($_POST['active_panel']) ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
|
$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
|
// Has the directory url changed? If yes, then resubmit the existing profiles there
|
||||||
if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) {
|
if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) {
|
||||||
DI::config()->set('system', 'directory', $global_directory);
|
DI::config()->set('system', 'directory', $global_directory);
|
||||||
|
@ -526,40 +493,6 @@ class Site extends BaseAdmin
|
||||||
|
|
||||||
$diaspora_able = (DI::baseUrl()->getUrlPath() == '');
|
$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');
|
$t = Renderer::getMarkupTemplate('admin/site.tpl');
|
||||||
return Renderer::replaceMacros($t, [
|
return Renderer::replaceMacros($t, [
|
||||||
'$title' => DI::l10n()->t('Administration'),
|
'$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.')],
|
'$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],
|
'$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.')],
|
'$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.')],
|
'$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.')],
|
'$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.')],
|
||||||
|
|
125
src/Module/Admin/Storage.php
Normal file
125
src/Module/Admin/Storage.php
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
<?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\Module\BaseAdmin;
|
||||||
|
use Friendica\Util\Strings;
|
||||||
|
use Psr\Log\LogLevel;
|
||||||
|
|
||||||
|
class Storage extends BaseAdmin
|
||||||
|
{
|
||||||
|
public static function post(array $parameters = [])
|
||||||
|
{
|
||||||
|
self::checkAdminAccess();
|
||||||
|
|
||||||
|
self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage');
|
||||||
|
|
||||||
|
$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/storage');
|
||||||
|
}
|
||||||
|
} elseif (!empty($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 = [];
|
||||||
|
|
||||||
|
// 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/storage.tpl');
|
||||||
|
|
||||||
|
return Renderer::replaceMacros($t, [
|
||||||
|
'$title' => DI::l10n()->t('Administration'),
|
||||||
|
'$page' => DI::l10n()->t('Storage'),
|
||||||
|
'$submit' => DI::l10n()->t('Save Settings'),
|
||||||
|
'$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],
|
||||||
|
'$storageform' => $storage_form,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -88,6 +88,7 @@ abstract class BaseAdmin extends BaseModule
|
||||||
]],
|
]],
|
||||||
'configuration' => [DI::l10n()->t('Configuration'), [
|
'configuration' => [DI::l10n()->t('Configuration'), [
|
||||||
'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
|
'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
|
||||||
|
'storage' => ['admin/storage' , DI::l10n()->t('Storage') , 'storage'],
|
||||||
'users' => ['admin/users' , DI::l10n()->t('Users') , 'users'],
|
'users' => ['admin/users' , DI::l10n()->t('Users') , 'users'],
|
||||||
'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
|
'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
|
||||||
'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
|
'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
|
||||||
|
|
|
@ -198,6 +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]],
|
||||||
|
|
||||||
'/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]],
|
||||||
'/themes/{theme}/embed' => [Module\Admin\Themes\Embed::class, [R::GET, R::POST]],
|
'/themes/{theme}/embed' => [Module\Admin\Themes\Embed::class, [R::GET, R::POST]],
|
||||||
|
|
|
@ -40,11 +40,6 @@
|
||||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
||||||
|
|
||||||
<h2>{{$upload}}</h2>
|
<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=$maximagesize}}
|
||||||
{{include file="field_input.tpl" field=$maximagelength}}
|
{{include file="field_input.tpl" field=$maximagelength}}
|
||||||
{{include file="field_input.tpl" field=$jpegimagequality}}
|
{{include file="field_input.tpl" field=$jpegimagequality}}
|
||||||
|
|
15
view/templates/admin/storage.tpl
Normal file
15
view/templates/admin/storage.tpl
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<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}}">
|
||||||
|
|
||||||
|
{{include file="field_select.tpl" field=$storagebackend}}
|
||||||
|
{{foreach from=$storageform item=$field}}
|
||||||
|
{{include file=$field.field field=$field}}
|
||||||
|
{{/foreach}}
|
||||||
|
|
||||||
|
<div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
|
@ -100,11 +100,6 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
|
<div id="admin-settings-upload-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="admin-settings-upload">
|
||||||
<div class="panel-body">
|
<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=$maximagesize}}
|
||||||
{{include file="field_input.tpl" field=$maximagelength}}
|
{{include file="field_input.tpl" field=$maximagelength}}
|
||||||
{{include file="field_input.tpl" field=$jpegimagequality}}
|
{{include file="field_input.tpl" field=$jpegimagequality}}
|
||||||
|
|
Loading…
Reference in a new issue