Author Topic: Update comments count  (Read 3481 times)

0 Members and 1 Guest are viewing this topic.

Offline alekinna

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Gallery of cross-stitching
Update comments count
« on: December 23, 2008, 04:11:53 AM »
I do little mod that uses user_comments from USERS_TABLE and found that this value not changed if:

1. whole category was deleted
2. image was deleted in ACP  (member.php work fine)

To fix first problem I did
in the file admin/categories.php

find two times
Code: [Select]
$image_ids_sql .= (($image_ids_sql != "") ? ", " : "").$image_row['image_id'];
add below
Code: [Select]
$sql2 = "SELECT user_id
              FROM ".COMMENTS_TABLE."
              WHERE image_id = ".$image_row['image_id']." AND user_id <> ".GUEST;
      $result = $site_db->query($sql2);

      while ($row = $site_db->fetch_array($result)) {
        $sql3 = "UPDATE ".USERS_TABLE."
                SET ".get_user_table_field("", "user_comments")." = ".get_user_table_field("", "user_comments")." - 1
                WHERE ".get_user_table_field("", "user_id")." = ".$row['user_id'];
        $site_db->query($sql3);
      }


To fix second problem I did

in the file admin/images.php

find
Code: [Select]
    if (!empty($user_table_fields['user_comments'])) {
      $sql = "SELECT user_id
              FROM ".COMMENTS_TABLE."
              WHERE image_id = ".$image_row['image_id']." AND user_id <> ".GUEST;
      $result = $site_db->query($sql);

      while ($row = $site_db->fetch_array($result)) {
        $sql = "UPDATE ".USERS_TABLE."
                SET ".get_user_table_field("", "user_comments")." = ".get_user_table_field("", "user_comments")." - 1
                WHERE ".get_user_table_field("", "user_id")." = ".$row['user_id'];
        $site_db->query($sql);
      }
    }

replace with
Code: [Select]
//    if (!empty($user_table_fields['user_comments'])) {
      $sql = "SELECT user_id
              FROM ".COMMENTS_TABLE."
              WHERE image_id = ".$image_row['image_id']." AND user_id <> ".GUEST;
      $result = $site_db->query($sql);

      while ($row = $site_db->fetch_array($result)) {
        $sql = "UPDATE ".USERS_TABLE."
                SET ".get_user_table_field("", "user_comments")." = ".get_user_table_field("", "user_comments")." - 1
                WHERE ".get_user_table_field("", "user_id")." = ".$row['user_id'];
        $site_db->query($sql);
      }
//    }


Can someone just check my solution and tell me if I did right?
« Last Edit: December 23, 2008, 05:32:30 AM by alekinna »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Update comments count
« Reply #1 on: December 23, 2008, 07:12:51 AM »
Thank you for reporting this bug and providing the fix.

I've posted it in bugs report section.

The actual fix is different then you've provided.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)