* Changed stats processing
This commit is contained in:
parent
6a9665135e
commit
078193f70a
11 changed files with 85 additions and 72 deletions
|
@ -129,7 +129,6 @@ class Action extends Users
|
|||
|
||||
$this->c->users->delete(...$this->userList);
|
||||
|
||||
$this->c->Cache->delete('stats'); //???? перенести в manager
|
||||
$this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
|
||||
|
||||
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->Cache->delete('stats'); //???? перенести в manager
|
||||
$this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
|
||||
|
||||
if ($profile) {
|
||||
|
|
|
@ -353,8 +353,9 @@ class Auth extends Page
|
|||
if ($user->isUnverified) {
|
||||
$user->group_id = $this->c->config->o_default_user_group;
|
||||
$user->email_confirmed = 1;
|
||||
|
||||
$this->c->users->update($user);
|
||||
$this->c->Cache->delete('stats');
|
||||
|
||||
$this->fIswev = ['i', \ForkBB\__('Account activated')];
|
||||
}
|
||||
|
||||
|
|
|
@ -157,11 +157,6 @@ class Register extends Page
|
|||
|
||||
$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) {
|
||||
$tplData = [
|
||||
|
@ -254,8 +249,6 @@ class Register extends Page
|
|||
|
||||
$this->c->users->update($user);
|
||||
|
||||
$this->c->Cache->delete('stats');
|
||||
|
||||
$this->c->Lang->load('register');
|
||||
|
||||
$auth = $this->c->Auth;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
app/Models/Stats/Model.php
Normal file
41
app/Models/Stats/Model.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ class ChangeGroup extends Action
|
|||
$ids = [];
|
||||
$moderators = [];
|
||||
$adminPresent = $newGroup->groupAdmin;
|
||||
$unverPresent = false;
|
||||
foreach ($users as $user) {
|
||||
if (! $user instanceof User) {
|
||||
throw new InvalidArgumentException('Expected User');
|
||||
|
@ -43,6 +44,9 @@ class ChangeGroup extends Action
|
|||
if ($user->isAdmin) {
|
||||
$adminPresent = true;
|
||||
}
|
||||
if ($user->isUnverified) {
|
||||
$unverPresent = true;
|
||||
}
|
||||
|
||||
$ids[] = $user->id;
|
||||
$user->__group_id = $newGroupId;
|
||||
|
@ -70,5 +74,8 @@ class ChangeGroup extends Action
|
|||
if ($adminPresent) {
|
||||
$this->c->admins->reset();
|
||||
}
|
||||
if ($unverPresent) {
|
||||
$this->c->stats->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,5 +77,6 @@ class Delete extends Action
|
|||
if ($adminPresent) {
|
||||
$this->c->admins->reset();
|
||||
}
|
||||
$this->c->stats->reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class Save extends Action
|
|||
$where = 'id=?i';
|
||||
}
|
||||
$set = $vars = [];
|
||||
$resAdmins = false;
|
||||
$grChange = false;
|
||||
foreach ($modified as $name) {
|
||||
if (! isset($fileds[$name])) {
|
||||
continue;
|
||||
|
@ -46,7 +46,7 @@ class Save extends Action
|
|||
$vars[] = $values[$name];
|
||||
$set[] = $name . '=?' . $fileds[$name];
|
||||
if ('group_id' === $name) {
|
||||
$resAdmins = true;
|
||||
$grChange = true;
|
||||
}
|
||||
}
|
||||
if (empty($set)) {
|
||||
|
@ -60,8 +60,9 @@ class Save extends Action
|
|||
$this->c->DB->query('UPDATE ::' . $table . ' SET ' . \implode(', ', $set) . ' WHERE ' . $where, $vars);
|
||||
$user->resModified();
|
||||
|
||||
if ($resAdmins) {
|
||||
if ($grChange) {
|
||||
$this->c->admins->reset();
|
||||
$this->c->stats->reset();
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
@ -102,6 +103,9 @@ class Save extends Action
|
|||
if ($user->isAdmin) {
|
||||
$this->c->admins->reset();
|
||||
}
|
||||
if (! $user->isUnverified) {
|
||||
$this->c->stats->reset();
|
||||
}
|
||||
|
||||
return $user->id;
|
||||
}
|
||||
|
|
24
app/Models/User/Stats.php
Normal file
24
app/Models/User/Stats.php
Normal file
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -88,7 +88,7 @@ return [
|
|||
'config' => '@ConfigModel:init',
|
||||
'bans' => '@ModelBanList:init',
|
||||
'censorship' => '@CensorshipModel:init',
|
||||
'stats' => '@ModelStats:init',
|
||||
'stats' => '@StatsModel:init',
|
||||
'admins' => '@AdminListModel:init',
|
||||
'smilies' => '@ModelSmileyList:init',
|
||||
'dbMap' => '@ModelDBMap:init',
|
||||
|
@ -191,8 +191,7 @@ return [
|
|||
'CensorshipModelLoad' => \ForkBB\Models\Censorship\Load::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,
|
||||
|
||||
|
@ -217,6 +216,7 @@ return [
|
|||
'UserManagerDelete' => \ForkBB\Models\User\Delete::class,
|
||||
'UserManagerChangeGroup' => \ForkBB\Models\User\ChangeGroup::class,
|
||||
'UserManagerAdminsIds' => \ForkBB\Models\User\AdminsIds::class,
|
||||
'UserManagerStats' => \ForkBB\Models\User\Stats::class,
|
||||
|
||||
'ForumModel' => \ForkBB\Models\Forum\Model::class,
|
||||
'ForumModelCalcStat' => \ForkBB\Models\Forum\CalcStat::class,
|
||||
|
|
Loading…
Add table
Reference in a new issue