Fix saving empty values in admin settings (#6143)

This commit is contained in:
Yuriy Bakhtin 2023-03-06 13:13:43 +04:00 committed by GitHub
parent d9986f4429
commit 6e9b819691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 19 deletions

View File

@ -10,6 +10,7 @@ HumHub Changelog
- Fix #6108: Fix log time in the `date()` function
- Fix #6122: Fix deleting a content with empty reason
- Fix #6128: Reset backuped content after submit form
- Fix #6142: Fix saving empty values in admin settings
1.13.1 (January 25, 2023)
-------------------------

View File

@ -67,6 +67,7 @@ class DesignSettingsForm extends Model
public function rules()
{
return [
['paginationSize', 'required'],
['paginationSize', 'integer', 'max' => 200, 'min' => 1],
['theme', 'in', 'range' => $this->getThemes()],
[['displayNameFormat', 'displayNameSubFormat', 'spaceOrder'], 'safe'],

View File

@ -43,7 +43,9 @@ class FileSettingsForm extends \yii\base\Model
{
return [
[['allowedExtensions'], 'match', 'pattern' => '/^[A-Za-z0-9_,]+$/u'],
[['maxFileSize', 'useXSendfile', 'excludeMediaFilesPreview'], 'integer'],
[['useXSendfile', 'excludeMediaFilesPreview'], 'integer'],
[['maxFileSize'], 'required'],
[['maxFileSize'], 'integer', 'min' => 1],
];
}
@ -69,7 +71,7 @@ class FileSettingsForm extends \yii\base\Model
public function save()
{
$settingsManager = Yii::$app->getModule('file')->settings;
$settingsManager->set('maxFileSize', $this->maxFileSize * 1024 * 1024);
$settingsManager->set('maxFileSize', (int) $this->maxFileSize * 1024 * 1024);
$settingsManager->set('excludeMediaFilesPreview', $this->excludeMediaFilesPreview);
$settingsManager->set('useXSendfile', $this->useXSendfile);
$settingsManager->set('allowedExtensions', strtolower($this->allowedExtensions));

View File

@ -18,8 +18,6 @@ $fileModule = Yii::$app->getModule('file');
<?php $form = ActiveForm::begin(['acknowledge' => true]); ?>
<?= $form->errorSummary($model); ?>
<?= $form->field($model, 'maxFileSize')->textInput(['class' => 'form-control', 'readonly' => $fileModule->settings->isFixed('maxFileSize')]); ?>
<p class="help-block" <?= ($model->maxFileSize > $maxUploadSize) ? 'style="color:' . $this->theme->variable('danger') . ' !important"' : '' ?>>
<?= Yii::t('AdminModule.settings', 'PHP reported a maximum of {maxUploadSize} MB', ['{maxUploadSize}' => $maxUploadSizeText]); ?>

View File

@ -8,14 +8,13 @@
namespace humhub\modules\search\controllers;
use humhub\modules\user\widgets\Image;
use Yii;
use yii\data\Pagination;
use humhub\components\Controller;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use humhub\modules\search\models\forms\SearchForm;
use humhub\modules\search\engine\Search;
use Yii;
use yii\data\Pagination;
/**
* Search Controller provides search functions inside the application.
@ -43,7 +42,7 @@ class SearchController extends Controller
{
$this->appendPageTitle(\Yii::t('SearchModule.base', 'Search'));
$this->view->setViewContext(static::VIEW_CONTEXT);
return parent::init();
parent::init();
}
/**
@ -74,7 +73,7 @@ class SearchController extends Controller
$options = [
'page' => $model->page,
'sort' => (empty($model->keyword)) ? 'title' : null,
'pageSize' => Yii::$app->settings->get('paginationSize'),
'pageSize' => $model->pageSize,
'limitSpaces' => $limitSpaces
];

View File

@ -8,16 +8,16 @@
namespace humhub\modules\search\engine;
use Yii;
use yii\base\Component;
use humhub\modules\search\interfaces\Searchable;
use humhub\modules\content\models\Content;
use humhub\modules\content\models\ContentTag;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\user\models\User;
use humhub\modules\space\models\Space;
use humhub\modules\search\events\SearchAttributesEvent;
use humhub\modules\search\interfaces\Searchable;
use humhub\modules\search\models\forms\SearchForm;
use humhub\modules\space\models\Space;
use yii\base\Component;
/**
* Description of HSearchComponent
@ -159,12 +159,12 @@ abstract class Search extends Component
protected function setDefaultFindOptions($options)
{
if (!isset($options['page']) || $options['page'] == '') {
if (empty($options['page'])) {
$options['page'] = 1;
}
if (!isset($options['pageSize']) || $options['pageSize'] == '') {
$options['pageSize'] = Yii::$app->settings->get('paginationSize');
if (empty($options['pageSize'])) {
$options['pageSize'] = (new SearchForm())->pageSize;
}
if (!isset($options['checkPermissions'])) {

View File

@ -24,13 +24,16 @@ class SearchForm extends Model
public $keyword = '';
public $scope = '';
public $page = 1;
public $pageSize;
public $limitSpaceGuids = [];
public function init()
{
if (Yii::$app->request->get('page')) {
$this->page = Yii::$app->request->get('page');
}
$page = (int) Yii::$app->request->get('page');
$this->page = $page < 1 ? 1 : $page;
$pageSize = (int) Yii::$app->settings->get('paginationSize');
$this->pageSize = $pageSize < 1 ? 1 : $pageSize;
}
/**