Changeset 1570:f06130921ca2
- Timestamp:
- 08/24/13 22:36:09 (10 years ago)
- Branch:
- 2.5
- Children:
- 1583:cbb6d70613a0, 1584:5808766f506f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.blog.php
r1561 r1570 208 208 { 209 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(); 215 216 # a) Retrieve posts affected by comments edition 217 if (empty($affected_posts_ids)) { 210 211 # Get posts affected by comments edition 212 if (empty($affected_posts)) { 218 213 $strReq = 219 'SELECT post_id , comment_trackback'.214 'SELECT post_id '. 220 215 'FROM '.$this->prefix.'comment '. 221 216 'WHERE comment_id'.$this->con->in($comments_ids). 222 'GROUP BY post_id ,comment_trackback';217 'GROUP BY post_id'; 223 218 224 219 $rs = $this->con->select($strReq); 225 220 221 $affected_posts = array(); 226 222 while ($rs->fetch()) { 227 $affected_posts_ids[] = (integer) $rs->post_id; 228 $affected_is_trackback[] = (boolean) $rs->comment_trackback; 229 } 230 } 231 232 # b) Count comments of each posts previously retrieved 233 # Note that this does not return posts without comment 223 $affected_posts[] = (integer) $rs->post_id; 224 } 225 } 226 227 if (!is_array($affected_posts) || empty($affected_posts)) { 228 return; 229 } 230 231 # Count number of comments if exists for affected posts 234 232 $strReq = 235 'SELECT post_id, COUNT(post_id) AS nb_comment, comment_trackback '.233 'SELECT post_id, COUNT(post_id) AS nb_comment, comment_trackback '. 236 234 'FROM '.$this->prefix.'comment '. 237 235 'WHERE comment_status = 1 '. 238 (count($affected_posts_ids) > 0 ? 'AND post_id'.$this->con->in($affected_posts_ids) : ' '); 239 240 if ($del) { 241 $strReq .= 242 'AND comment_id NOT'.$this->con->in($comments_ids); 243 } 244 245 $strReq .= 236 'AND post_id'.$this->con->in($affected_posts). 246 237 'GROUP BY post_id,comment_trackback'; 247 238 248 239 $rs = $this->con->select($strReq); 249 240 241 $posts = array(); 250 242 while ($rs->fetch()) { 251 $counted_posts_ids[] = (integer) $rs->post_id; 252 $counted_is_trackback[] = (boolean) $rs->comment_trackback; 253 $counted_nb_comments[] = (integer) $rs->nb_comment; 254 } 255 256 # c) Update comments numbers on posts 257 # This compare previous requests to update also posts without comment 243 if ($rs->comment_trackback) { 244 $posts[$rs->post_id]['trackback'] = $rs->nb_comment; 245 } else { 246 $posts[$rs->post_id]['comment'] = $rs->nb_comment; 247 } 248 } 249 250 # Update number of comments on affected posts 258 251 $cur = $this->con->openCursor($this->prefix.'post'); 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 } 265 $nb_comment = $nb_trackback = 0; 266 267 foreach($counted_posts_ids as $counted_key => $counted_post_id) 268 { 269 if ($affected_post_id != $counted_post_id 270 || $affected_is_trackback[$affected_key] != $counted_is_trackback[$counted_key]) { 271 continue; 272 } 273 274 if ($counted_is_trackback[$counted_key]) { 275 $nb_trackback = $counted_nb_comments[$counted_key]; 276 } else { 277 $nb_comment = $counted_nb_comments[$counted_key]; 278 } 279 } 280 281 if ($affected_is_trackback[$affected_key]) { 282 $cur->nb_trackback = $nb_trackback; 252 foreach($affected_posts as $post_id) 253 { 254 $cur->clean(); 255 256 if (!array_key_exists($post_id,$posts)) { 257 $cur->nb_trackback = 0; 258 $cur->nb_comment = 0; 283 259 } else { 284 $cur->nb_ comment = $nb_comment;285 }286 287 $cur->update('WHERE post_id = '.$affected_post_id);288 $cur-> clean();260 $cur->nb_trackback = empty($posts[$post_id]['trackback']) ? 0 : $posts[$post_id]['trackback']; 261 $cur->nb_comment = empty($posts[$post_id]['comment']) ? 0 : $posts[$post_id]['comment']; 262 } 263 264 $cur->update('WHERE post_id = '.$post_id); 289 265 } 290 266 } … … 2254 2230 $affected_posts = array(); 2255 2231 $strReq = 2256 'SELECT distinct(post_id)'.2232 'SELECT post_id '. 2257 2233 'FROM '.$this->prefix.'comment '. 2258 'WHERE comment_id'.$this->con->in($co_ids); 2234 'WHERE comment_id'.$this->con->in($co_ids). 2235 'GROUP BY post_id'; 2259 2236 2260 2237 $rs = $this->con->select($strReq);
Note: See TracChangeset
for help on using the changeset viewer.