mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-01 01:24:32 +03:00
Replace "operator/performance.php" with a controller
This commit is contained in:
parent
3373095a66
commit
46e329471c
@ -0,0 +1,189 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Controller\Settings;
|
||||||
|
|
||||||
|
use Mibew\Controller\AbstractController;
|
||||||
|
use Mibew\Settings;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains actions which are related with performance system settings.
|
||||||
|
*/
|
||||||
|
class PerformanceController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Builds a page with form for performance system settings.
|
||||||
|
*
|
||||||
|
* @param Request $request Incoming request.
|
||||||
|
* @return string Rendered page content.
|
||||||
|
*/
|
||||||
|
public function showFormAction(Request $request)
|
||||||
|
{
|
||||||
|
set_csrf_token();
|
||||||
|
|
||||||
|
$operator = $request->attributes->get('_operator');
|
||||||
|
$page = array(
|
||||||
|
'agentId' => '',
|
||||||
|
// Use errors list stored in the request. We need to do so to have
|
||||||
|
// an ability to pass the request from the "submitForm" action.
|
||||||
|
'errors' => $request->attributes->get('errors', array()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Load settings from the database
|
||||||
|
$options = array(
|
||||||
|
'online_timeout',
|
||||||
|
'updatefrequency_operator',
|
||||||
|
'updatefrequency_chat',
|
||||||
|
'max_connections_from_one_host',
|
||||||
|
'updatefrequency_tracking',
|
||||||
|
'visitors_limit',
|
||||||
|
'invitation_lifetime',
|
||||||
|
'tracking_lifetime',
|
||||||
|
'thread_lifetime',
|
||||||
|
'statistics_aggregation_interval',
|
||||||
|
'max_uploaded_file_size',
|
||||||
|
);
|
||||||
|
|
||||||
|
$params = array();
|
||||||
|
foreach ($options as $opt) {
|
||||||
|
$params[$opt] = Settings::get($opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build form values
|
||||||
|
$form = $request->request;
|
||||||
|
|
||||||
|
$page['formonlinetimeout'] = $form->get('onlinetimeout', $params['online_timeout']);
|
||||||
|
$page['formfrequencyoperator'] = $form->get('frequencyoperator', $params['updatefrequency_operator']);
|
||||||
|
$page['formfrequencychat'] = $form->get('frequencychat', $params['updatefrequency_chat']);
|
||||||
|
$page['formonehostconnections'] = $form->get('onehostconnections', $params['max_connections_from_one_host']);
|
||||||
|
$page['formthreadlifetime'] = $form->get('threadlifetime', $params['thread_lifetime']);
|
||||||
|
$page['formmaxuploadedfilesize'] = $form->get('maxuploadedfilesize', $params['max_uploaded_file_size']);
|
||||||
|
$page['formstatistics_aggregation_interval'] = $form->get(
|
||||||
|
'statistics_aggregation_interval',
|
||||||
|
$params['statistics_aggregation_interval']
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Settings::get('enabletracking')) {
|
||||||
|
$page['formfrequencytracking'] = $form->get('frequencytracking', $params['updatefrequency_tracking']);
|
||||||
|
$page['formvisitorslimit'] = $form->get('visitorslimit', $params['visitors_limit']);
|
||||||
|
$page['forminvitationlifetime'] = $form->get('invitationlifetime', $params['invitation_lifetime']);
|
||||||
|
$page['formtrackinglifetime'] = $form->get('trackinglifetime', $params['tracking_lifetime']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$page['enabletracking'] = Settings::get('enabletracking');
|
||||||
|
$page['stored'] = $request->query->get('stored');
|
||||||
|
$page['title'] = getlocal("settings.title");
|
||||||
|
$page['menuid'] = "settings";
|
||||||
|
|
||||||
|
$page = array_merge($page, prepare_menu($operator));
|
||||||
|
$page['tabs'] = setup_settings_tabs(2);
|
||||||
|
|
||||||
|
return $this->render('settings_performance', $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes submitting of the form which is generated in
|
||||||
|
* {@link \Mibew\Controller\Settings\PerformanceController::showFormAction()}
|
||||||
|
* method.
|
||||||
|
*
|
||||||
|
* @param Request $request Incoming request.
|
||||||
|
* @return string Rendered page content.
|
||||||
|
*/
|
||||||
|
public function submitFormAction(Request $request)
|
||||||
|
{
|
||||||
|
csrf_check_token($request);
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
$params = array();
|
||||||
|
|
||||||
|
$params['online_timeout'] = $request->request->get('onlinetimeout');
|
||||||
|
if (!is_numeric($params['online_timeout'])) {
|
||||||
|
$errors[] = wrong_field("settings.onlinetimeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['updatefrequency_operator'] = $request->request->get('frequencyoperator');
|
||||||
|
if (!is_numeric($params['updatefrequency_operator'])) {
|
||||||
|
$errors[] = wrong_field("settings.frequencyoperator");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['updatefrequency_chat'] = $request->request->get('frequencychat');
|
||||||
|
if (!is_numeric($params['updatefrequency_chat'])) {
|
||||||
|
$errors[] = wrong_field("settings.frequencychat");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['max_connections_from_one_host'] = $request->request->get('onehostconnections');
|
||||||
|
if (!is_numeric($params['max_connections_from_one_host'])) {
|
||||||
|
$errors[] = getlocal("settings.wrong.onehostconnections");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['thread_lifetime'] = $request->request->get('threadlifetime');
|
||||||
|
if (!is_numeric($params['thread_lifetime'])) {
|
||||||
|
$errors[] = getlocal("settings.wrong.threadlifetime");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['statistics_aggregation_interval'] = $request->request->get('statistics_aggregation_interval');
|
||||||
|
if (!is_numeric($params['statistics_aggregation_interval'])) {
|
||||||
|
$errors[] = wrong_field("settings.statistics_aggregation_interval");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings::get('enabletracking')) {
|
||||||
|
$params['updatefrequency_tracking'] = $request->request->get('frequencytracking');
|
||||||
|
if (!is_numeric($params['updatefrequency_tracking'])) {
|
||||||
|
$errors[] = wrong_field("settings.frequencytracking");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['visitors_limit'] = $request->request->get('visitorslimit');
|
||||||
|
if (!is_numeric($params['visitors_limit'])) {
|
||||||
|
$errors[] = wrong_field("settings.visitorslimit");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['invitation_lifetime'] = $request->request->get('invitationlifetime');
|
||||||
|
if (!is_numeric($params['invitation_lifetime'])) {
|
||||||
|
$errors[] = wrong_field("settings.invitationlifetime");
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['tracking_lifetime'] = $request->request->get('trackinglifetime');
|
||||||
|
if (!is_numeric($params['tracking_lifetime'])) {
|
||||||
|
$errors[] = wrong_field("settings.trackinglifetime");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['max_uploaded_file_size'] = $request->request->get('maxuploadedfilesize');
|
||||||
|
if (!is_numeric($params['max_uploaded_file_size'])) {
|
||||||
|
$errors[] = wrong_field("settings.maxuploadedfilesize");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($errors) != 0) {
|
||||||
|
$request->attributes->set('errors', $errors);
|
||||||
|
|
||||||
|
// The form should be rebuild. Invoke appropriate action.
|
||||||
|
return $this->showFormAction($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update settings in the database
|
||||||
|
foreach ($params as $key => $value) {
|
||||||
|
Settings::set($key, $value);
|
||||||
|
}
|
||||||
|
Settings::update();
|
||||||
|
|
||||||
|
// Redirect the current operator to the same page using get method.
|
||||||
|
$redirect_to = $this->generateUrl('settings_performance', array('stored' => true));
|
||||||
|
|
||||||
|
return $this->redirect($redirect_to);
|
||||||
|
}
|
||||||
|
}
|
@ -377,6 +377,22 @@ settings_common_save:
|
|||||||
_access_permissions: [CAN_ADMINISTRATE]
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
settings_performance:
|
||||||
|
path: /operator/settings/performance
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Controller\Settings\PerformanceController::showFormAction
|
||||||
|
_access_check: Mibew\AccessControl\Check\PermissionsCheck
|
||||||
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
settings_performance_save:
|
||||||
|
path: /operator/settings/performance
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Controller\Settings\PerformanceController::submitFormAction
|
||||||
|
_access_check: Mibew\AccessControl\Check\PermissionsCheck
|
||||||
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
## Statistics
|
## Statistics
|
||||||
statistics:
|
statistics:
|
||||||
path: /operator/statistics/{type}
|
path: /operator/statistics/{type}
|
||||||
|
@ -35,7 +35,7 @@ function setup_settings_tabs($active)
|
|||||||
? (MIBEW_WEB_ROOT . "/operator/features.php")
|
? (MIBEW_WEB_ROOT . "/operator/features.php")
|
||||||
: ""),
|
: ""),
|
||||||
getlocal("page_settings.tab.performance") => ($active != 2
|
getlocal("page_settings.tab.performance") => ($active != 2
|
||||||
? (MIBEW_WEB_ROOT . "/operator/performance.php")
|
? (MIBEW_WEB_ROOT . "/operator/settings/performance")
|
||||||
: ""),
|
: ""),
|
||||||
getlocal("page_settings.tab.page_themes") => ($active != 3
|
getlocal("page_settings.tab.page_themes") => ($active != 3
|
||||||
? (MIBEW_WEB_ROOT . "/operator/page_themes.php")
|
? (MIBEW_WEB_ROOT . "/operator/page_themes.php")
|
||||||
|
@ -1,149 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Import namespaces and classes of the core
|
|
||||||
use Mibew\Settings;
|
|
||||||
use Mibew\Style\PageStyle;
|
|
||||||
|
|
||||||
// Initialize libraries
|
|
||||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
|
||||||
|
|
||||||
$operator = check_login();
|
|
||||||
csrf_check_token();
|
|
||||||
|
|
||||||
$page = array(
|
|
||||||
'agentId' => '',
|
|
||||||
'errors' => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'online_timeout',
|
|
||||||
'updatefrequency_operator',
|
|
||||||
'updatefrequency_chat',
|
|
||||||
'max_connections_from_one_host',
|
|
||||||
'updatefrequency_tracking',
|
|
||||||
'visitors_limit',
|
|
||||||
'invitation_lifetime',
|
|
||||||
'tracking_lifetime',
|
|
||||||
'thread_lifetime',
|
|
||||||
'statistics_aggregation_interval',
|
|
||||||
'max_uploaded_file_size',
|
|
||||||
);
|
|
||||||
|
|
||||||
$params = array();
|
|
||||||
foreach ($options as $opt) {
|
|
||||||
$params[$opt] = Settings::get($opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST['onlinetimeout'])) {
|
|
||||||
$params['online_timeout'] = get_param('onlinetimeout');
|
|
||||||
if (!is_numeric($params['online_timeout'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.onlinetimeout");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['updatefrequency_operator'] = get_param('frequencyoperator');
|
|
||||||
if (!is_numeric($params['updatefrequency_operator'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.frequencyoperator");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['updatefrequency_chat'] = get_param('frequencychat');
|
|
||||||
if (!is_numeric($params['updatefrequency_chat'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.frequencychat");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['max_connections_from_one_host'] = get_param('onehostconnections');
|
|
||||||
if (!is_numeric($params['max_connections_from_one_host'])) {
|
|
||||||
$page['errors'][] = getlocal("settings.wrong.onehostconnections");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['thread_lifetime'] = get_param('threadlifetime');
|
|
||||||
if (!is_numeric($params['thread_lifetime'])) {
|
|
||||||
$page['errors'][] = getlocal("settings.wrong.threadlifetime");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['statistics_aggregation_interval'] = get_param('statistics_aggregation_interval');
|
|
||||||
if (!is_numeric($params['statistics_aggregation_interval'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.statistics_aggregation_interval");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings::get('enabletracking')) {
|
|
||||||
|
|
||||||
$params['updatefrequency_tracking'] = get_param('frequencytracking');
|
|
||||||
if (!is_numeric($params['updatefrequency_tracking'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.frequencytracking");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['visitors_limit'] = get_param('visitorslimit');
|
|
||||||
if (!is_numeric($params['visitors_limit'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.visitorslimit");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['invitation_lifetime'] = get_param('invitationlifetime');
|
|
||||||
if (!is_numeric($params['invitation_lifetime'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.invitationlifetime");
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['tracking_lifetime'] = get_param('trackinglifetime');
|
|
||||||
if (!is_numeric($params['tracking_lifetime'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.trackinglifetime");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$params['max_uploaded_file_size'] = get_param('maxuploadedfilesize');
|
|
||||||
if (!is_numeric($params['max_uploaded_file_size'])) {
|
|
||||||
$page['errors'][] = wrong_field("settings.maxuploadedfilesize");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($page['errors']) == 0) {
|
|
||||||
foreach ($options as $opt) {
|
|
||||||
Settings::set($opt, $params[$opt]);
|
|
||||||
}
|
|
||||||
Settings::update();
|
|
||||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/performance.php?stored");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$page['formonlinetimeout'] = $params['online_timeout'];
|
|
||||||
$page['formfrequencyoperator'] = $params['updatefrequency_operator'];
|
|
||||||
$page['formfrequencychat'] = $params['updatefrequency_chat'];
|
|
||||||
$page['formonehostconnections'] = $params['max_connections_from_one_host'];
|
|
||||||
$page['formthreadlifetime'] = $params['thread_lifetime'];
|
|
||||||
$page['formstatistics_aggregation_interval'] = $params['statistics_aggregation_interval'];
|
|
||||||
|
|
||||||
if (Settings::get('enabletracking')) {
|
|
||||||
|
|
||||||
$page['formfrequencytracking'] = $params['updatefrequency_tracking'];
|
|
||||||
$page['formvisitorslimit'] = $params['visitors_limit'];
|
|
||||||
$page['forminvitationlifetime'] = $params['invitation_lifetime'];
|
|
||||||
$page['formtrackinglifetime'] = $params['tracking_lifetime'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$page['formmaxuploadedfilesize'] = $params['max_uploaded_file_size'];
|
|
||||||
|
|
||||||
$page['enabletracking'] = Settings::get('enabletracking');
|
|
||||||
$page['stored'] = isset($_GET['stored']);
|
|
||||||
|
|
||||||
$page['title'] = getlocal("settings.title");
|
|
||||||
$page['menuid'] = "settings";
|
|
||||||
|
|
||||||
$page = array_merge($page, prepare_menu($operator));
|
|
||||||
|
|
||||||
$page['tabs'] = setup_settings_tabs(2);
|
|
||||||
|
|
||||||
$page_style = new PageStyle(PageStyle::getCurrentStyle());
|
|
||||||
$page_style->render('performance', $page);
|
|
@ -13,7 +13,7 @@
|
|||||||
<div id="formmessage">{{l10n "settings.saved"}}</div>
|
<div id="formmessage">{{l10n "settings.saved"}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<form name="performance" method="post" action="{{mibewRoot}}/operator/performance.php">
|
<form name="performance" method="post" action="{{mibewRoot}}/operator/settings/performance">
|
||||||
{{csrfTokenInput}}
|
{{csrfTokenInput}}
|
||||||
|
|
||||||
<div>
|
<div>
|
Loading…
Reference in New Issue
Block a user