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