Fixed invalid SQL in some circumstances

This commit is contained in:
Marcin Kurczewski 2014-01-04 12:47:49 +01:00
parent b1fb329fc7
commit 4a9cc4b3bc
2 changed files with 13 additions and 6 deletions

View file

@ -11,9 +11,10 @@ class PostSearchService extends AbstractSearchService
protected static function filterUserSafety(SqlQuery $sqlQuery) protected static function filterUserSafety(SqlQuery $sqlQuery)
{ {
$allowedSafety = PrivilegesHelper::getAllowedSafety(); $allowedSafety = PrivilegesHelper::getAllowedSafety();
$sqlQuery->raw('safety')->in()->genSlots($allowedSafety); if (empty($allowedSafety))
foreach ($allowedSafety as $s) $sqlQuery->raw('0');
$sqlQuery->put($s); else
$sqlQuery->raw('safety')->in()->genSlots($allowedSafety)->put($allowedSafety);
} }
protected static function filterUserHidden(SqlQuery $sqlQuery) protected static function filterUserHidden(SqlQuery $sqlQuery)
@ -55,6 +56,9 @@ class PostSearchService extends AbstractSearchService
{ {
$ids = preg_split('/[;,]/', $val); $ids = preg_split('/[;,]/', $val);
$ids = array_map('intval', $ids); $ids = array_map('intval', $ids);
if (empty($ids))
$sqlQuery->raw('0');
else
$sqlQuery->raw('id')->in()->genSlots($ids)->put($ids); $sqlQuery->raw('id')->in()->genSlots($ids)->put($ids);
} }

View file

@ -12,8 +12,11 @@ class TagSearchService extends AbstractSearchService
->innerJoin('post_tag') ->innerJoin('post_tag')
->on('tag.id = post_tag.tag_id') ->on('tag.id = post_tag.tag_id')
->innerJoin('post') ->innerJoin('post')
->on('post.id = post_tag.post_id') ->on('post.id = post_tag.post_id');
->where('safety')->in()->genSlots($allowedSafety); if (empty($allowedSafety))
$sqlQuery->where('0');
else
$sqlQuery->where('safety')->in()->genSlots($allowedSafety);
foreach ($allowedSafety as $s) foreach ($allowedSafety as $s)
$sqlQuery->put($s); $sqlQuery->put($s);