Skip to content

Commit 866202f

Browse files
committed
Fix queries with no free result
1 parent 3e2a743 commit 866202f

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

factory/idea.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,7 @@ public function vote(&$idea, $user_id, $value)
286286
}
287287

288288
// Check whether user has already voted - update if they have
289-
$sql = 'SELECT idea_id, vote_value
290-
FROM ' . $this->table_votes . '
291-
WHERE idea_id = ' . (int) $idea['idea_id'] . '
292-
AND user_id = ' . (int) $user_id;
293-
$this->db->sql_query_limit($sql, 1);
294-
if ($row = $this->db->sql_fetchrow())
289+
if ($row = $this->get_users_vote($idea['idea_id'], $user_id))
295290
{
296291
if ($row['vote_value'] != $value)
297292
{
@@ -370,12 +365,7 @@ public function vote(&$idea, $user_id, $value)
370365
public function remove_vote(&$idea, $user_id)
371366
{
372367
// Only change something if user has already voted
373-
$sql = 'SELECT idea_id, vote_value
374-
FROM ' . $this->table_votes . '
375-
WHERE idea_id = ' . (int) $idea['idea_id'] . '
376-
AND user_id = ' . (int) $user_id;
377-
$this->db->sql_query_limit($sql, 1);
378-
if ($row = $this->db->sql_fetchrow())
368+
if ($row = $this->get_users_vote($idea['idea_id'], $user_id))
379369
{
380370
$sql = 'DELETE FROM ' . $this->table_votes . '
381371
WHERE idea_id = ' . (int) $idea['idea_id'] . '
@@ -430,4 +420,24 @@ public function get_voters($id)
430420

431421
return $rows;
432422
}
423+
424+
/**
425+
* Get a user's stored vote value for a given idea
426+
*
427+
* @param int $idea_id The idea id
428+
* @param int $user_id The user id
429+
* @return mixed Array with the row data, false if the row does not exist
430+
*/
431+
protected function get_users_vote($idea_id, $user_id)
432+
{
433+
$sql = 'SELECT idea_id, vote_value
434+
FROM ' . $this->table_votes . '
435+
WHERE idea_id = ' . (int) $idea_id . '
436+
AND user_id = ' . (int) $user_id;
437+
$result = $this->db->sql_query_limit($sql, 1);
438+
$row = $this->db->sql_fetchrow();
439+
$this->db->sql_freeresult($result);
440+
441+
return $row;
442+
}
433443
}

factory/permission_helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public function set_ideas_forum_permissions($forum_id)
5959
$sql = 'SELECT group_id
6060
FROM ' . GROUPS_TABLE . "
6161
WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'";
62-
$this->db->sql_query($sql);
62+
$result = $this->db->sql_query($sql);
6363
$group_id = (int) $this->db->sql_fetchfield('group_id');
64+
$this->db->sql_freeresult($result);
6465

6566
// Get 'f_' local REGISTERED users group permissions array for the ideas forum
6667
// Default undefined permissions to ACL_NO

0 commit comments

Comments
 (0)