Pārlūkot izejas kodu

Fix calcStat for Forum and Topic

Visman 5 gadi atpakaļ
vecāks
revīzija
88458ad942
2 mainītis faili ar 14 papildinājumiem un 14 dzēšanām
  1. 8 2
      app/Models/Forum/CalcStat.php
  2. 6 12
      app/Models/Topic/CalcStat.php

+ 8 - 2
app/Models/Forum/CalcStat.php

@@ -22,13 +22,19 @@ class CalcStat extends Method
         }
         }
 
 
         $vars = [':fid' => $this->model->id];
         $vars = [':fid' => $this->model->id];
+        $sql = 'SELECT COUNT(t.id)
+                FROM ::topics AS t
+                WHERE t.forum_id=?i:fid AND t.moved_to!=0';
+
+        $moved = $this->c->DB->query($sql, $vars)->fetchColumn();
+
         $sql = 'SELECT COUNT(t.id) as num_topics, SUM(t.num_replies) as num_replies
         $sql = 'SELECT COUNT(t.id) as num_topics, SUM(t.num_replies) as num_replies
                 FROM ::topics AS t
                 FROM ::topics AS t
-                WHERE t.forum_id=?i:fid';
+                WHERE t.forum_id=?i:fid AND t.moved_to=0';
 
 
         $result = $this->c->DB->query($sql, $vars)->fetch();
         $result = $this->c->DB->query($sql, $vars)->fetch();
 
 
-        $this->model->num_topics = $result['num_topics'];
+        $this->model->num_topics = $result['num_topics'] + $moved;
         $this->model->num_posts  = $result['num_topics'] + $result['num_replies'];
         $this->model->num_posts  = $result['num_topics'] + $result['num_replies'];
 
 
         $sql = 'SELECT t.last_post, t.last_post_id, t.last_poster, t.subject as last_topic
         $sql = 'SELECT t.last_post, t.last_post_id, t.last_poster, t.subject as last_topic

+ 6 - 12
app/Models/Topic/CalcStat.php

@@ -23,13 +23,6 @@ class CalcStat extends Method
 
 
         if ($this->model->moved_to) {
         if ($this->model->moved_to) {
             $num_replies = 0;
             $num_replies = 0;
-            $result = [
-                'id'        => 0,
-                'poster'    => '',
-                'poster_id' => 0,
-                'posted'    => 0,
-                'edited'    => 0,
-            ];
         } else {
         } else {
             $vars = [
             $vars = [
                 ':tid' => $this->model->id
                 ':tid' => $this->model->id
@@ -47,14 +40,15 @@ class CalcStat extends Method
                     LIMIT 1';
                     LIMIT 1';
 
 
             $result = $this->c->DB->query($sql, $vars)->fetch();
             $result = $this->c->DB->query($sql, $vars)->fetch();
+
+            $this->model->last_post_id   = $result['id'];
+            $this->model->last_poster    = $result['poster'];
+            $this->model->last_poster_id = $result['poster_id'];
+            $this->model->last_post      = $result['edited'] > 0 && $result['edited'] > $result['posted'] ? $result['edited'] : $result['posted'];
         }
         }
 
 
         //????
         //????
-        $this->model->num_replies    = $num_replies;
-        $this->model->last_post_id   = $result['id'];
-        $this->model->last_poster    = $result['poster'];
-        $this->model->last_poster_id = $result['poster_id'];
-        $this->model->last_post      = $result['edited'] > 0 && $result['edited'] > $result['posted'] ? $result['edited'] : $result['posted'];
+        $this->model->num_replies = $num_replies;
 
 
         return $this->model;
         return $this->model;
     }
     }