Bug 1735 fixed : merge from trunk

Comment page is not PostgreSQL compatible
Fixed by adding all fields except category_id in group by clause
category_id is retrieved later in an another query (with permissions filter)

Fixed also problem of FROM_UNIXTIME function not POstgreSQL compatible

git-svn-id: http://piwigo.org/svn/branches/2.1@6602 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
nikrou 2010-06-24 20:35:46 +00:00
parent 3a57b93baa
commit 6394613e9f
2 changed files with 33 additions and 17 deletions

View file

@ -359,14 +359,13 @@ $element_ids = array();
$category_ids = array(); $category_ids = array();
$query = ' $query = '
SELECT com.id AS comment_id SELECT com.id AS comment_id,
, com.image_id com.image_id,
, ic.category_id com.author,
, com.author com.author_id,
, com.author_id com.date,
, com.date com.content,
, com.content com.validated
, com.validated
FROM '.IMAGE_CATEGORY_TABLE.' AS ic FROM '.IMAGE_CATEGORY_TABLE.' AS ic
INNER JOIN '.COMMENTS_TABLE.' AS com INNER JOIN '.COMMENTS_TABLE.' AS com
ON ic.image_id = com.image_id ON ic.image_id = com.image_id
@ -374,7 +373,13 @@ SELECT com.id AS comment_id
ON u.'.$conf['user_fields']['id'].' = com.author_id ON u.'.$conf['user_fields']['id'].' = com.author_id
WHERE '.implode(' WHERE '.implode('
AND ', $page['where_clauses']).' 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']; ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
if ('all' != $page['items_number']) if ('all' != $page['items_number'])
{ {
@ -388,7 +393,6 @@ while ($row = pwg_db_fetch_assoc($result))
{ {
array_push($comments, $row); array_push($comments, $row);
array_push($element_ids, $row['image_id']); array_push($element_ids, $row['image_id']);
array_push($category_ids, $row['category_id']);
} }
if (count($comments) > 0) if (count($comments) > 0)
@ -408,11 +412,23 @@ SELECT id, name, file, path, tn_ext
// retrieving category informations // retrieving category informations
$query = ' $query = '
SELECT id, name, permalink, uppercats SELECT c.id, name, permalink, uppercats, com.id as comment_id
FROM '.CATEGORIES_TABLE.' FROM '.CATEGORIES_TABLE.' AS c
WHERE id IN ('.implode(',', $category_ids).') 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
'.get_sql_condition_FandF
(
array
(
'forbidden_categories' => 'c.id',
'visible_categories' => 'c.id'
),
'WHERE'
).'
;'; ;';
$categories = hash_from_query($query, 'id'); $categories = hash_from_query($query, 'comment_id');
foreach ($comments as $comment) foreach ($comments as $comment)
{ {
@ -431,7 +447,7 @@ SELECT id, name, permalink, uppercats
// link to the full size picture // link to the full size picture
$url = make_picture_url( $url = make_picture_url(
array( array(
'category' => $categories[ $comment['category_id'] ], 'category' => $categories[ $comment['comment_id'] ],
'image_id' => $comment['image_id'], 'image_id' => $comment['image_id'],
'image_file' => $elements[$comment['image_id']]['file'], 'image_file' => $elements[$comment['image_id']]['file'],
) )

View file

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