|
@@ -25,39 +25,43 @@ class Delete extends Action
|
|
|
throw new InvalidArgumentException('No arguments, expected User(s), Forum(s), Topic(s) or Post(s)');
|
|
|
}
|
|
|
|
|
|
- $users = [];
|
|
|
- $usersToGuest = [];
|
|
|
- $usersDel = [];
|
|
|
- $forums = [];
|
|
|
- $topics = [];
|
|
|
- $posts = [];
|
|
|
- $parents = [];
|
|
|
- $isUser = 0;
|
|
|
- $isForum = 0;
|
|
|
- $isTopic = 0;
|
|
|
- $isPost = 0;
|
|
|
+ $uidsToGuest = [];
|
|
|
+ $uidsDelete = [];
|
|
|
+ $uidsUpdate = [];
|
|
|
+ $forums = [];
|
|
|
+ $topics = [];
|
|
|
+ $pids = [];
|
|
|
+ $parents = [];
|
|
|
+ $isUser = 0;
|
|
|
+ $isForum = 0;
|
|
|
+ $isTopic = 0;
|
|
|
+ $isPost = 0;
|
|
|
|
|
|
foreach ($args as $arg) {
|
|
|
if ($arg instanceof User) {
|
|
|
if ($arg->isGuest) {
|
|
|
throw new RuntimeException('Guest can not be deleted');
|
|
|
}
|
|
|
+
|
|
|
if (true === $arg->deleteAllPost) {
|
|
|
- $usersDel[] = $arg->id;
|
|
|
+ $uidsDelete[$arg->id] = $arg->id;
|
|
|
} else {
|
|
|
- $usersToGuest[] = $arg->id;
|
|
|
+ $uidsToGuest[$arg->id] = $arg->id;
|
|
|
}
|
|
|
+
|
|
|
$isUser = 1;
|
|
|
} elseif ($arg instanceof Forum) {
|
|
|
if (! $this->c->forums->get($arg->id) instanceof Forum) {
|
|
|
throw new RuntimeException('Forum unavailable');
|
|
|
}
|
|
|
+
|
|
|
$forums[$arg->id] = $arg;
|
|
|
$isForum = 1;
|
|
|
} elseif ($arg instanceof Topic) {
|
|
|
if (! $arg->parent instanceof Forum) {
|
|
|
throw new RuntimeException('Parent unavailable');
|
|
|
}
|
|
|
+
|
|
|
$topics[$arg->id] = $arg;
|
|
|
$isTopic = 1;
|
|
|
} elseif ($arg instanceof Post) {
|
|
@@ -67,10 +71,11 @@ class Delete extends Action
|
|
|
) {
|
|
|
throw new RuntimeException('Parents unavailable');
|
|
|
}
|
|
|
- $posts[$arg->id] = $arg->id;
|
|
|
- $parents[$arg->topic_id] = $arg->parent;
|
|
|
- $users[$arg->poster_id] = $arg->poster_id;
|
|
|
- $isPost = 1;
|
|
|
+
|
|
|
+ $pids[$arg->id] = $arg->id;
|
|
|
+ $parents[$arg->topic_id] = $arg->parent;
|
|
|
+ $uidsUpdate[$arg->poster_id] = $arg->poster_id;
|
|
|
+ $isPost = 1;
|
|
|
} else {
|
|
|
throw new InvalidArgumentException('Expected User(s), Forum(s), Topic(s) or Post(s)');
|
|
|
}
|
|
@@ -82,11 +87,11 @@ class Delete extends Action
|
|
|
|
|
|
$this->c->search->delete(...$args);
|
|
|
|
|
|
- //???? подписки, опросы, предупреждения
|
|
|
+ //???? предупреждения
|
|
|
|
|
|
- if ($usersToGuest) {
|
|
|
- $vars = [
|
|
|
- ':users' => $usersToGuest,
|
|
|
+ if ($uidsToGuest) {
|
|
|
+ $vars = [
|
|
|
+ ':users' => $uidsToGuest,
|
|
|
];
|
|
|
$query = 'UPDATE ::posts
|
|
|
SET poster_id=1
|
|
@@ -100,45 +105,43 @@ class Delete extends Action
|
|
|
|
|
|
$this->c->DB->exec($query, $vars);
|
|
|
}
|
|
|
- if ($usersDel) {
|
|
|
- $vars = [
|
|
|
- ':users' => $usersDel,
|
|
|
- ];
|
|
|
- $query = 'UPDATE ::posts
|
|
|
- SET editor_id=1
|
|
|
- WHERE editor_id IN (?ai:users)';
|
|
|
-
|
|
|
- $this->c->DB->exec($query, $vars);
|
|
|
|
|
|
+ if ($uidsDelete) {
|
|
|
+ $vars = [
|
|
|
+ ':users' => $uidsDelete,
|
|
|
+ ];
|
|
|
$query = 'SELECT p.topic_id
|
|
|
FROM ::posts as p
|
|
|
WHERE p.poster_id IN (?ai:users)
|
|
|
GROUP BY p.topic_id';
|
|
|
|
|
|
- $parents = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ $tids = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+
|
|
|
+# $query = 'SELECT t.id
|
|
|
+# FROM ::topics AS t
|
|
|
+# WHERE t.poster_id IN (?ai:users)';
|
|
|
+#
|
|
|
+# $notUse = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); // эти темы удаляются
|
|
|
+#
|
|
|
+# $tids = \array_diff($tids, $notUse);
|
|
|
|
|
|
- $query = 'SELECT t.id
|
|
|
- FROM ::topics AS t
|
|
|
- INNER JOIN ::posts AS p ON t.first_post_id=p.id
|
|
|
- WHERE p.poster_id IN (?ai:users)';
|
|
|
+ $parents = $this->c->topics->loadByIds($tids, false);
|
|
|
|
|
|
- $notUse = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ $query = 'UPDATE ::posts
|
|
|
+ SET editor_id=1
|
|
|
+ WHERE editor_id IN (?ai:users)';
|
|
|
|
|
|
- $parents = \array_diff($parents, $notUse); //????
|
|
|
+ $this->c->DB->exec($query, $vars);
|
|
|
|
|
|
$query = 'DELETE
|
|
|
FROM ::posts
|
|
|
WHERE poster_id IN (?ai:users)';
|
|
|
|
|
|
$this->c->DB->exec($query, $vars);
|
|
|
-
|
|
|
- foreach ($parents as &$parent) {
|
|
|
- $parent = $this->c->topics->load($parent); //???? ааааАААААААААААААА О_о
|
|
|
- }
|
|
|
- unset($parent);
|
|
|
}
|
|
|
+
|
|
|
if ($forums) {
|
|
|
- $vars = [
|
|
|
+ $vars = [
|
|
|
':forums' => \array_keys($forums),
|
|
|
];
|
|
|
$query = 'SELECT p.poster_id
|
|
@@ -147,7 +150,7 @@ class Delete extends Action
|
|
|
WHERE t.forum_id IN (?ai:forums)
|
|
|
GROUP BY p.poster_id';
|
|
|
|
|
|
- $users = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ $uidsUpdate = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
|
|
$query = 'DELETE
|
|
|
FROM ::posts
|
|
@@ -156,10 +159,12 @@ class Delete extends Action
|
|
|
FROM ::topics
|
|
|
WHERE forum_id IN (?ai:forums)
|
|
|
)';
|
|
|
+
|
|
|
$this->c->DB->exec($query, $vars);
|
|
|
}
|
|
|
+
|
|
|
if ($topics) {
|
|
|
- $vars = [
|
|
|
+ $vars = [
|
|
|
':topics' => \array_keys($topics),
|
|
|
];
|
|
|
$query = 'SELECT p.poster_id
|
|
@@ -167,7 +172,7 @@ class Delete extends Action
|
|
|
WHERE p.topic_id IN (?ai:topics)
|
|
|
GROUP BY p.poster_id';
|
|
|
|
|
|
- $users = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ $uidsUpdate = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
|
|
$query = 'DELETE
|
|
|
FROM ::posts
|
|
@@ -175,9 +180,10 @@ class Delete extends Action
|
|
|
|
|
|
$this->c->DB->exec($query, $vars);
|
|
|
}
|
|
|
- if ($posts) {
|
|
|
- $vars = [
|
|
|
- ':posts' => $posts,
|
|
|
+
|
|
|
+ if ($pids) {
|
|
|
+ $vars = [
|
|
|
+ ':posts' => $pids,
|
|
|
];
|
|
|
$query = 'DELETE
|
|
|
FROM ::posts
|
|
@@ -185,21 +191,25 @@ class Delete extends Action
|
|
|
|
|
|
$this->c->DB->exec($query, $vars);
|
|
|
}
|
|
|
+
|
|
|
if ($parents) {
|
|
|
$topics = $parents;
|
|
|
$parents = [];
|
|
|
|
|
|
foreach ($topics as $topic) {
|
|
|
- $parents[$topic->forum_id] = $topic->parent;
|
|
|
+ $parents[$topic->parent->id] = $topic->parent;
|
|
|
$this->c->topics->update($topic->calcStat());
|
|
|
}
|
|
|
|
|
|
- foreach($parents as $forum) {
|
|
|
- $this->c->forums->update($forum->calcStat());
|
|
|
+ if (! $forums) {
|
|
|
+ foreach ($parents as $forum) {
|
|
|
+ $this->c->forums->update($forum->calcStat());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if ($users) {
|
|
|
- $this->c->users->updateCountPosts(...$users);
|
|
|
+
|
|
|
+ if ($uidsUpdate) {
|
|
|
+ $this->c->users->updateCountPosts(...$uidsUpdate);
|
|
|
}
|
|
|
}
|
|
|
}
|