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', '');
$group = is_null($thread->groupId) ? null : group_by_id($thread->groupId);
$group = $thread->groupId ? group_by_id($thread->groupId) : null;
$page['formemail'] = $email;
$page['chat.thread.id'] = $thread->id;
@ -93,7 +93,7 @@ class MailController extends AbstractController
}
$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) {
$errors[] = no_field('Your 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}.',
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.');
}
} else {

View File

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

View File

@ -618,13 +618,13 @@ class ThreadProcessor extends ClientSideProcessor implements
$referrer = $args['referrer'];
// Verify group id
$group_id = '';
$group_id = 0;
$group = null;
if (Settings::get('enablegroups') == '1') {
if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) {
$group = group_by_id($args['groupId']);
if ($group) {
$group_id = $args['groupId'];
$group_id = (int)$args['groupId'];
}
}
}
@ -752,12 +752,12 @@ class ThreadProcessor extends ClientSideProcessor implements
}
// Verify group id
$group_id = '';
$group_id = 0;
if (Settings::get('enablegroups') == '1') {
if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) {
$group = group_by_id($args['groupId']);
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.
*
* If there is no attached group the value should be equal to 0 (zero).
*
* @var int
*/
public $groupId;