Dotclear

Changeset 1561:9ab4292a9cb0


Ignore:
Timestamp:
08/24/13 14:52:27 (11 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
2.5
Message:

Refix (or not) comments counts on trigger comments, addresses #1401

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.blog.php

    r1545 r1561  
    207207     public function triggerComments($ids, $del=false, $affected_posts=null) 
    208208     { 
    209           $co_ids = dcUtils::cleanIds($ids); 
    210           $a_ids = dcUtils::cleanIds($affected_posts); 
    211           $a_tbs = array(); 
     209          $comments_ids = dcUtils::cleanIds($ids); 
     210          $affected_posts_ids = dcUtils::cleanIds($affected_posts); 
     211          $affected_is_trackback =  
     212          $counted_posts_ids =  
     213          $counted_is_trackback =  
     214          $counted_nb_comments = array(); 
    212215           
    213216          # a) Retrieve posts affected by comments edition 
    214           if (empty($a_ids)) { 
     217          if (empty($affected_posts_ids)) { 
    215218               $strReq =  
    216219                    'SELECT post_id, comment_trackback '. 
    217220                    'FROM '.$this->prefix.'comment '. 
    218                     'WHERE comment_id'.$this->con->in($co_ids). 
     221                    'WHERE comment_id'.$this->con->in($comments_ids). 
    219222                    'GROUP BY post_id,comment_trackback'; 
    220223                
     
    222225                
    223226               while ($rs->fetch()) { 
    224                     $a_ids[] = (integer) $rs->post_id; 
    225                     $a_tbs[] = (integer) $rs->comment_trackback; 
     227                    $affected_posts_ids[] = (integer) $rs->post_id; 
     228                    $affected_is_trackback[] = (boolean) $rs->comment_trackback; 
    226229               } 
    227230          } 
     
    233236               'FROM '.$this->prefix.'comment '. 
    234237               'WHERE comment_status = 1 '. 
    235                (count($a_ids) > 0 ? 'AND post_id'.$this->con->in($a_ids) : ' '); 
     238               (count($affected_posts_ids) > 0 ? 'AND post_id'.$this->con->in($affected_posts_ids) : ' '); 
    236239           
    237240          if ($del) { 
    238241               $strReq .=  
    239                     'AND comment_id NOT'.$this->con->in($co_ids); 
     242                    'AND comment_id NOT'.$this->con->in($comments_ids); 
    240243          } 
    241244           
     
    245248          $rs = $this->con->select($strReq); 
    246249           
    247           $b_ids = $b_tbs = $b_nbs = array(); 
    248250          while ($rs->fetch()) { 
    249                $b_ids[] = (integer) $rs->post_id; 
    250                $b_tbs[] = (integer) $rs->comment_trackback; 
    251                $b_nbs[] = (integer) $rs->nb_comment; 
     251               $counted_posts_ids[] = (integer) $rs->post_id; 
     252               $counted_is_trackback[] = (boolean) $rs->comment_trackback; 
     253               $counted_nb_comments[] = (integer) $rs->nb_comment; 
    252254          } 
    253255           
     
    256258          $cur = $this->con->openCursor($this->prefix.'post'); 
    257259           
    258           foreach($a_ids as $a_key => $a_id) 
    259           { 
     260          foreach($affected_posts_ids as $affected_key => $affected_post_id) 
     261          { 
     262               if (!array_key_exists($affected_key, $affected_is_trackback)) { 
     263                    $affected_is_trackback[$affected_key] = false; 
     264               } 
    260265               $nb_comment = $nb_trackback = 0; 
    261                //$cur->nb_comment = $nb_comment; 
    262                foreach($b_ids as $b_key => $b_id) 
     266                
     267               foreach($counted_posts_ids as $counted_key => $counted_post_id) 
    263268               { 
    264                     if ($a_id != $b_id || $a_tbs[$a_key] != $b_tbs[$b_key]) { 
     269                    if ($affected_post_id != $counted_post_id  
     270                    || $affected_is_trackback[$affected_key] != $counted_is_trackback[$counted_key]) { 
    265271                         continue; 
    266272                    } 
    267273                     
    268                     if ($b_tbs[$b_key]) { 
    269                          $nb_trackback = $b_nbs[$b_key]; 
     274                    if ($counted_is_trackback[$counted_key]) { 
     275                         $nb_trackback = $counted_nb_comments[$counted_key]; 
    270276                    } else { 
    271                          $nb_comment = $b_nbs[$b_key]; 
     277                         $nb_comment = $counted_nb_comments[$counted_key]; 
    272278                    } 
    273279               } 
    274280                
    275                if ($a_tbs[$a_key]) { 
     281               if ($affected_is_trackback[$affected_key]) { 
    276282                    $cur->nb_trackback = $nb_trackback; 
    277283               } else { 
    278284                    $cur->nb_comment = $nb_comment; 
    279285               } 
    280                $cur->update('WHERE post_id = '.$a_id); 
     286 
     287               $cur->update('WHERE post_id = '.$affected_post_id); 
     288               $cur->clean(); 
    281289          } 
    282290     } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map