Make sure Thread::groupId is always integer

See https://mibew.org/forums/index.php/topic,191756.0.html for details
about why it's needed.
This commit is contained in:
Dmitriy Simushev 2015-05-08 12:46:50 +00:00
parent eae5b8bb06
commit 5628f42782
5 changed files with 14 additions and 13 deletions

View File

@ -57,7 +57,7 @@ class MailController extends AbstractController
} }
$email = $request->request->get('email', ''); $email = $request->request->get('email', '');
$group = is_null($thread->groupId) ? null : group_by_id($thread->groupId); $group = $thread->groupId ? group_by_id($thread->groupId) : null;
$page['formemail'] = $email; $page['formemail'] = $email;
$page['chat.thread.id'] = $thread->id; $page['chat.thread.id'] = $thread->id;
@ -93,7 +93,7 @@ class MailController extends AbstractController
} }
$email = $request->request->get('email'); $email = $request->request->get('email');
$group = is_null($thread->groupId) ? null : group_by_id($thread->groupId); $group = $thread->groupId ? group_by_id($thread->groupId) : null;
if (!$email) { if (!$email) {
$errors[] = no_field('Your email'); $errors[] = no_field('Your email');
} elseif (!MailUtils::isValidAddress($email)) { } elseif (!MailUtils::isValidAddress($email)) {

View File

@ -118,7 +118,7 @@ class RedirectController extends AbstractController
'The visitor has been placed in a priorty queue of the group {0}.', 'The visitor has been placed in a priorty queue of the group {0}.',
array(get_group_name($next_group)) array(get_group_name($next_group))
); );
if (!$this->redirectToGroup($thread, $next_id)) { if (!$this->redirectToGroup($thread, (int)$next_id)) {
$page['errors'][] = getlocal('You are not chatting with the visitor.'); $page['errors'][] = getlocal('You are not chatting with the visitor.');
} }
} else { } else {

View File

@ -102,19 +102,17 @@ class UserChatController extends AbstractController
// Create new thread // Create new thread
if (!$thread) { if (!$thread) {
// Load group info // Load group info
$group_id = ''; $group_id = 0;
$group_name = ''; $group_name = '';
$group = null; $group = null;
if (Settings::get('enablegroups') == '1') { if (Settings::get('enablegroups') == '1') {
$group_id = $request->query->get('group'); // ID of the group can be either positive integer or zero.
if (!preg_match("/^\d{1,10}$/", $group_id)) { $group_id = max(0, $request->query->getInt('group'));
$group_id = false;
}
if ($group_id) { if ($group_id) {
$group = group_by_id($group_id); $group = group_by_id($group_id);
if (!$group) { if (!$group) {
$group_id = false; $group_id = 0;
} else { } else {
$group_name = get_group_name($group); $group_name = get_group_name($group);
} }

View File

@ -618,13 +618,13 @@ class ThreadProcessor extends ClientSideProcessor implements
$referrer = $args['referrer']; $referrer = $args['referrer'];
// Verify group id // Verify group id
$group_id = ''; $group_id = 0;
$group = null; $group = null;
if (Settings::get('enablegroups') == '1') { if (Settings::get('enablegroups') == '1') {
if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) { if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) {
$group = group_by_id($args['groupId']); $group = group_by_id($args['groupId']);
if ($group) { if ($group) {
$group_id = $args['groupId']; $group_id = (int)$args['groupId'];
} }
} }
} }
@ -752,12 +752,12 @@ class ThreadProcessor extends ClientSideProcessor implements
} }
// Verify group id // Verify group id
$group_id = ''; $group_id = 0;
if (Settings::get('enablegroups') == '1') { if (Settings::get('enablegroups') == '1') {
if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) { if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) {
$group = group_by_id($args['groupId']); $group = group_by_id($args['groupId']);
if ($group) { if ($group) {
$group_id = $args['groupId']; $group_id = (int)$args['groupId'];
} }
} }
} }

View File

@ -147,6 +147,9 @@ class Thread
/** /**
* ID of the group related with the thread. * ID of the group related with the thread.
*
* If there is no attached group the value should be equal to 0 (zero).
*
* @var int * @var int
*/ */
public $groupId; public $groupId;