Navigation Menu

Skip to content

Commit

Permalink
Bug 1735 fixed : Comment page is not PostgreSQL compatible
Browse files Browse the repository at this point in the history
Fixed by adding all fields except category_id in group by clause
category_id is retrieved later in an another query.

Fixed also problem of FROM_UNIXTIME function not POstgreSQL compatible.

git-svn-id: http://piwigo.org/svn/trunk@6596 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Jun 24, 2010
1 parent ad07b1c commit e1ecc62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
39 changes: 23 additions & 16 deletions comments.php
Expand Up @@ -359,22 +359,27 @@
$category_ids = array();

$query = '
SELECT com.id AS comment_id
, com.image_id
, ic.category_id
, com.author
, com.author_id
, com.date
, com.content
, com.validated
SELECT com.id AS comment_id,
com.image_id,
com.author,
com.author_id,
com.date,
com.content,
com.validated
FROM '.IMAGE_CATEGORY_TABLE.' AS ic
INNER JOIN '.COMMENTS_TABLE.' AS com
LEFT JOIN '.COMMENTS_TABLE.' AS com
ON ic.image_id = com.image_id
LEFT JOIN '.USERS_TABLE.' As u
ON u.'.$conf['user_fields']['id'].' = com.author_id
WHERE '.implode('
AND ', $page['where_clauses']).'
GROUP BY comment_id
GROUP BY comment_id,
com.image_id,
com.author,
com.author_id,
com.date,
com.content,
com.validated
ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
if ('all' != $page['items_number'])
{
Expand All @@ -388,7 +393,6 @@
{
array_push($comments, $row);
array_push($element_ids, $row['image_id']);
array_push($category_ids, $row['category_id']);
}

if (count($comments) > 0)
Expand All @@ -408,11 +412,14 @@

// retrieving category informations
$query = '
SELECT id, name, permalink, uppercats
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.implode(',', $category_ids).')
SELECT c.id, name, permalink, uppercats, com.id as comment_id
FROM '.CATEGORIES_TABLE.' AS c
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
ON c.id=ic.category_id
LEFT JOIN '.COMMENTS_TABLE.' AS com
ON ic.image_id=com.image_id
;';
$categories = hash_from_query($query, 'id');
$categories = hash_from_query($query, 'comment_id');

foreach ($comments as $comment)
{
Expand All @@ -431,7 +438,7 @@
// link to the full size picture
$url = make_picture_url(
array(
'category' => $categories[ $comment['category_id'] ],
'category' => $categories[ $comment['comment_id'] ],
'image_id' => $comment['image_id'],
'image_file' => $elements[$comment['image_id']]['file'],
)
Expand Down
4 changes: 2 additions & 2 deletions include/functions_comment.inc.php
Expand Up @@ -133,10 +133,10 @@ function insert_user_comment( &$comm, $key, &$infos )

if ($comment_action!='reject' and $conf['anti-flood_time']>0 )
{ // anti-flood system
$reference_date = time() - $conf['anti-flood_time'];
$reference_date = date('c', time() - $conf['anti-flood_time']);
$query = '
SELECT id FROM '.COMMENTS_TABLE.'
WHERE date > FROM_UNIXTIME('.$reference_date.')
WHERE date > \''.$reference_date.'\'
AND author_id = '.$comm['author_id'];
if ( pwg_db_num_rows( pwg_query( $query ) ) > 0 )
{
Expand Down

0 comments on commit e1ecc62

Please sign in to comment.