浏览代码

* Changed stats processing

Visman 6 年之前
父节点
当前提交
078193f70a

+ 0 - 2
app/Models/Pages/Admin/Users/Action.php

@@ -129,7 +129,6 @@ class Action extends Users
 
 
             $this->c->users->delete(...$this->userList);
             $this->c->users->delete(...$this->userList);
 
 
-            $this->c->Cache->delete('stats');       //???? перенести в manager
             $this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
             $this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
 
 
             return $this->c->Redirect->page('AdminUsers')->message('Users delete redirect');
             return $this->c->Redirect->page('AdminUsers')->message('Users delete redirect');
@@ -275,7 +274,6 @@ class Action extends Users
 
 
                 $this->c->users->changeGroup($v->new_group, ...$this->userList);
                 $this->c->users->changeGroup($v->new_group, ...$this->userList);
 
 
-                $this->c->Cache->delete('stats');       //???? перенести в manager
                 $this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
                 $this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
 
 
                 if ($profile) {
                 if ($profile) {

+ 2 - 1
app/Models/Pages/Auth.php

@@ -353,8 +353,9 @@ class Auth extends Page
         if ($user->isUnverified) {
         if ($user->isUnverified) {
             $user->group_id        = $this->c->config->o_default_user_group;
             $user->group_id        = $this->c->config->o_default_user_group;
             $user->email_confirmed = 1;
             $user->email_confirmed = 1;
+
             $this->c->users->update($user);
             $this->c->users->update($user);
-            $this->c->Cache->delete('stats');
+
             $this->fIswev = ['i', \ForkBB\__('Account activated')];
             $this->fIswev = ['i', \ForkBB\__('Account activated')];
         }
         }
 
 

+ 0 - 7
app/Models/Pages/Register.php

@@ -157,11 +157,6 @@ class Register extends Page
 
 
         $newUserId = $this->c->users->insert($user);
         $newUserId = $this->c->users->insert($user);
 
 
-        // обновление статистики по пользователям
-        if ('1' != $this->c->config->o_regs_verify) {
-            $this->c->Cache->delete('stats');
-        }
-
         // уведомление о регистрации
         // уведомление о регистрации
         if ('1' == $this->c->config->o_regs_report && '' != $this->c->config->o_mailing_list) {
         if ('1' == $this->c->config->o_regs_report && '' != $this->c->config->o_mailing_list) {
             $tplData = [
             $tplData = [
@@ -254,8 +249,6 @@ class Register extends Page
 
 
         $this->c->users->update($user);
         $this->c->users->update($user);
 
 
-        $this->c->Cache->delete('stats');
-
         $this->c->Lang->load('register');
         $this->c->Lang->load('register');
 
 
         $auth = $this->c->Auth;
         $auth = $this->c->Auth;

+ 0 - 29
app/Models/Stats.php

@@ -1,29 +0,0 @@
-<?php
-
-namespace ForkBB\Models;
-
-use ForkBB\Models\Model;
-use PDO;
-
-class Stats extends Model
-{
-    /**
-     * Загружает статистику из кеша/БД
-     *
-     * @return Stats
-     */
-    public function init()
-    {
-        if ($this->c->Cache->has('stats')) {
-            $list = $this->c->Cache->get('stats');
-            $this->userTotal = $list['total'];
-            $this->userLast  = $list['last'];
-        } else {
-            $this->load();
-        }
-
-        list($this->topicTotal, $this->postTotal) = $this->c->DB->query('SELECT SUM(f.num_topics), SUM(f.num_posts) FROM ::forums AS f')->fetch(PDO::FETCH_NUM);
-
-        return $this;
-    }
-}

+ 0 - 27
app/Models/Stats/Load.php

@@ -1,27 +0,0 @@
-<?php
-
-namespace ForkBB\Models\Stats;
-
-use ForkBB\Models\Method;
-
-class Load extends Method
-{
-    /**
-     * Заполняет модель данными из БД
-     * Создает кеш
-     *
-     * @return Stats
-     */
-    public function load()
-    {
-        $total = $this->c->DB->query('SELECT COUNT(u.id)-1 FROM ::users AS u WHERE u.group_id!=0')->fetchColumn();
-        $last  = $this->c->DB->query('SELECT u.id, u.username FROM ::users AS u WHERE u.group_id!=0 ORDER BY u.registered DESC LIMIT 1')->fetch();
-        $this->model->userTotal = $total;
-        $this->model->userLast  = $last;
-        $this->c->Cache->set('stats', [
-            'total' => $total,
-            'last'  => $last,
-        ]);
-        return $this->model;
-    }
-}

+ 41 - 0
app/Models/Stats/Model.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace ForkBB\Models\Stats;
+
+use ForkBB\Models\Model as BaseModel;
+use PDO;
+
+class Model extends BaseModel
+{
+    /**
+     * Загружает статистику из кеша/БД
+     *
+     * @return Models\Stats
+     */
+    public function init()
+    {
+        if ($this->c->Cache->has('stats')) {
+            $list = $this->c->Cache->get('stats');
+        } else {
+            $list = $this->c->users->stats();
+            $this->c->Cache->set('stats', $list);
+        }
+        $this->userTotal = $list['total'];
+        $this->userLast  = $list['last'];
+
+        list($this->topicTotal, $this->postTotal) = $this->c->DB->query('SELECT SUM(f.num_topics), SUM(f.num_posts) FROM ::forums AS f')->fetch(PDO::FETCH_NUM);
+
+        return $this;
+    }
+
+    /**
+     * Сбрасывает кеш статистики
+     *
+     * @return Models\Stats
+     */
+    public function reset()
+    {
+        $this->c->Cache->delete('stats');
+        return $this;
+    }
+}

+ 7 - 0
app/Models/User/ChangeGroup.php

@@ -29,6 +29,7 @@ class ChangeGroup extends Action
         $ids = [];
         $ids = [];
         $moderators = [];
         $moderators = [];
         $adminPresent = $newGroup->groupAdmin;
         $adminPresent = $newGroup->groupAdmin;
+        $unverPresent = false;
         foreach ($users as $user) {
         foreach ($users as $user) {
             if (! $user instanceof User) {
             if (! $user instanceof User) {
                 throw new InvalidArgumentException('Expected User');
                 throw new InvalidArgumentException('Expected User');
@@ -43,6 +44,9 @@ class ChangeGroup extends Action
             if ($user->isAdmin) {
             if ($user->isAdmin) {
                 $adminPresent = true;
                 $adminPresent = true;
             }
             }
+            if ($user->isUnverified) {
+                $unverPresent = true;
+            }
 
 
             $ids[] = $user->id;
             $ids[] = $user->id;
             $user->__group_id = $newGroupId;
             $user->__group_id = $newGroupId;
@@ -70,5 +74,8 @@ class ChangeGroup extends Action
         if ($adminPresent) {
         if ($adminPresent) {
             $this->c->admins->reset();
             $this->c->admins->reset();
         }
         }
+        if ($unverPresent) {
+            $this->c->stats->reset();
+        }
     }
     }
 }
 }

+ 1 - 0
app/Models/User/Delete.php

@@ -77,5 +77,6 @@ class Delete extends Action
         if ($adminPresent) {
         if ($adminPresent) {
             $this->c->admins->reset();
             $this->c->admins->reset();
         }
         }
+        $this->c->stats->reset();
     }
     }
 }
 }

+ 7 - 3
app/Models/User/Save.php

@@ -38,7 +38,7 @@ class Save extends Action
             $where  = 'id=?i';
             $where  = 'id=?i';
         }
         }
         $set = $vars = [];
         $set = $vars = [];
-        $resAdmins = false;
+        $grChange = false;
         foreach ($modified as $name) {
         foreach ($modified as $name) {
             if (! isset($fileds[$name])) {
             if (! isset($fileds[$name])) {
                 continue;
                 continue;
@@ -46,7 +46,7 @@ class Save extends Action
             $vars[] = $values[$name];
             $vars[] = $values[$name];
             $set[] = $name . '=?' . $fileds[$name];
             $set[] = $name . '=?' . $fileds[$name];
             if ('group_id' === $name) {
             if ('group_id' === $name) {
-                $resAdmins = true;
+                $grChange = true;
             }
             }
         }
         }
         if (empty($set)) {
         if (empty($set)) {
@@ -60,8 +60,9 @@ class Save extends Action
         $this->c->DB->query('UPDATE ::' . $table . ' SET ' . \implode(', ', $set) . ' WHERE ' . $where, $vars);
         $this->c->DB->query('UPDATE ::' . $table . ' SET ' . \implode(', ', $set) . ' WHERE ' . $where, $vars);
         $user->resModified();
         $user->resModified();
 
 
-        if ($resAdmins) {
+        if ($grChange) {
             $this->c->admins->reset();
             $this->c->admins->reset();
+            $this->c->stats->reset();
         }
         }
 
 
         return $user;
         return $user;
@@ -102,6 +103,9 @@ class Save extends Action
         if ($user->isAdmin) {
         if ($user->isAdmin) {
             $this->c->admins->reset();
             $this->c->admins->reset();
         }
         }
+        if (! $user->isUnverified) {
+            $this->c->stats->reset();
+        }
 
 
         return $user->id;
         return $user->id;
     }
     }

+ 24 - 0
app/Models/User/Stats.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace ForkBB\Models\User;
+
+use ForkBB\Models\Action;
+
+class Stats extends Action
+{
+    /**
+     * Возвращает данные по статистике пользователей
+     *
+     * @return array
+     */
+    public function stats()
+    {
+        $total = $this->c->DB->query('SELECT COUNT(u.id)-1 FROM ::users AS u WHERE u.group_id!=0')->fetchColumn();
+        $last  = $this->c->DB->query('SELECT u.id, u.username FROM ::users AS u WHERE u.group_id!=0 ORDER BY u.registered DESC LIMIT 1')->fetch();
+
+        return [
+            'total' => $total,
+            'last'  => $last,
+        ];
+    }
+}

+ 3 - 3
app/config/main.dist.php

@@ -88,7 +88,7 @@ return [
         'config'     => '@ConfigModel:init',
         'config'     => '@ConfigModel:init',
         'bans'       => '@ModelBanList:init',
         'bans'       => '@ModelBanList:init',
         'censorship' => '@CensorshipModel:init',
         'censorship' => '@CensorshipModel:init',
-        'stats'      => '@ModelStats:init',
+        'stats'      => '@StatsModel:init',
         'admins'     => '@AdminListModel:init',
         'admins'     => '@AdminListModel:init',
         'smilies'    => '@ModelSmileyList:init',
         'smilies'    => '@ModelSmileyList:init',
         'dbMap'      => '@ModelDBMap:init',
         'dbMap'      => '@ModelDBMap:init',
@@ -191,8 +191,7 @@ return [
         'CensorshipModelLoad'    => \ForkBB\Models\Censorship\Load::class,
         'CensorshipModelLoad'    => \ForkBB\Models\Censorship\Load::class,
         'CensorshipModelSave'    => \ForkBB\Models\Censorship\Save::class,
         'CensorshipModelSave'    => \ForkBB\Models\Censorship\Save::class,
 
 
-        'ModelStats'          => \ForkBB\Models\Stats::class,
-        'StatsLoad' => \ForkBB\Models\Stats\Load::class,
+        'StatsModel' => \ForkBB\Models\Stats\Model::class,
 
 
         'AdminListModel' => \ForkBB\Models\AdminList\Model::class,
         'AdminListModel' => \ForkBB\Models\AdminList\Model::class,
 
 
@@ -217,6 +216,7 @@ return [
         'UserManagerDelete'           => \ForkBB\Models\User\Delete::class,
         'UserManagerDelete'           => \ForkBB\Models\User\Delete::class,
         'UserManagerChangeGroup'      => \ForkBB\Models\User\ChangeGroup::class,
         'UserManagerChangeGroup'      => \ForkBB\Models\User\ChangeGroup::class,
         'UserManagerAdminsIds'        => \ForkBB\Models\User\AdminsIds::class,
         'UserManagerAdminsIds'        => \ForkBB\Models\User\AdminsIds::class,
+        'UserManagerStats'            => \ForkBB\Models\User\Stats::class,
 
 
         'ForumModel'           => \ForkBB\Models\Forum\Model::class,
         'ForumModel'           => \ForkBB\Models\Forum\Model::class,
         'ForumModelCalcStat'   => \ForkBB\Models\Forum\CalcStat::class,
         'ForumModelCalcStat'   => \ForkBB\Models\Forum\CalcStat::class,