* Delete moderators in Forum for delete users

This commit is contained in:
Visman 2018-09-15 15:52:32 +07:00
parent 1542fd7414
commit e6c978bd14
2 changed files with 31 additions and 16 deletions

View file

@ -122,7 +122,8 @@ class Action extends Users
$this->c->DB->commit();
$this->c->Cache->delete('stats');
$this->c->Cache->delete('stats'); //???? перенести в manager
$this->c->Cache->delete('forums_mark'); //???? с авто обновлением кеша
return $this->c->Redirect->page('AdminUsers')->message('Users delete redirect');
}

View file

@ -12,40 +12,54 @@ class Delete extends Action
/**
* Удаляет пользователя(ей)
*
* @param mixed ...$args
* @param mixed ...$users
*
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function delete(...$args)
public function delete(...$users)
{
if (empty($args)) {
if (empty($users)) {
throw new InvalidArgumentException('No arguments, expected User(s)');
}
$users = [];
foreach ($args as $arg) {
if ($arg instanceof User) {
if ($arg->isGuest) {
throw new RuntimeException('Guest can not be deleted');
}
$users[] = $arg->id;
} else {
$ids = [];
$moderators = [];
foreach ($users as $user) {
if (! $user instanceof User) {
throw new InvalidArgumentException('Expected User');
}
if ($user->isGuest) {
throw new RuntimeException('Guest can not be deleted');
}
$ids[] = $user->id;
if ($user->isAdmMod) {
$moderators[$user->id] = $user;
}
}
$this->c->forums->delete(...$args);
if (! empty($moderators)) {
$root = $this->c->forums->get(0);
if ($root instanceof Forum) {
foreach ($this->c->forums->depthList($root, 0) as $forum) {
$forum->modDelete(...$moderators);
$this->c->forums->update($forum);
}
}
}
$this->c->forums->delete(...$users);
//???? подписки, опросы, предупреждения
foreach ($args as $user) {
foreach ($users as $user) {
$this->c->Online->delete($user);
}
$vars = [
':users' => $users,
':users' => $ids,
];
$sql = 'DELETE FROM ::users
WHERE id IN (?ai:users)';