Sfoglia il codice sorgente

Fix sql queries UPDATE for SQLite #10

Visman 3 anni fa
parent
commit
efae0295e4

+ 13 - 20
app/Models/Topic/Merge.php

@@ -54,26 +54,19 @@ class Merge extends Action
         }
 
         //???? перенести обработку в посты?
-        $vars = [
-            'start'  => "[from]",
-            'end'    => "[/from]\n",
-            'topics' => $ids,
-        ];
-        $query = 'UPDATE ::posts AS p, ::topics as t
-            SET p.message=CONCAT(?s:start, t.subject, ?s:end, p.message)
-            WHERE p.topic_id IN (?ai:topics) AND t.id=p.topic_id';
-
-        $this->c->DB->exec($query, $vars);
-
-        $vars = [
-            'id'     => $firstTopic->id,
-            'topics' => $ids,
-        ];
-        $query = 'UPDATE ::posts AS p
-            SET p.topic_id=?i:id
-            WHERE p.topic_id IN (?ai:topics)';
-
-        $this->c->DB->exec($query, $vars);
+        $query = 'UPDATE ::posts
+            SET message=CONCAT(?s:prefix, message), topic_id=?i:new
+            WHERE topic_id=?i:id';
+
+        foreach ($otherTopics as $topic) {
+            $vars = [
+                ':new'    => $firstTopic->id,
+                ':id'     => $topic->id,
+                ':prefix' => "[from]{$topic->subject}[/from]\n",
+            ];
+
+            $this->c->DB->exec($query, $vars);
+        }
 
         // добавить перенос подписок на первую тему?
 

+ 3 - 3
app/Models/User/ChangeGroup.php

@@ -71,9 +71,9 @@ class ChangeGroup extends Action
             ':new' => $newGroupId,
             ':ids' => $ids,
         ];
-        $query = 'UPDATE ::users AS u
-            SET u.group_id = ?i:new
-            WHERE u.id IN (?ai:ids)';
+        $query = 'UPDATE ::users
+            SET group_id = ?i:new
+            WHERE id IN (?ai:ids)';
 
         $this->c->DB->exec($query, $vars);
 

+ 5 - 5
app/Models/User/UpdateCountPosts.php

@@ -38,22 +38,22 @@ class UpdateCountPosts extends Action
         unset($ids[0]); // ????
 
         if (empty($ids)) {
-            $where = 'u.id > 0';
+            $where = '::users.id > 0';
             $vars  = [];
         } else {
-            $where = 'u.id IN (?ai:ids)';
+            $where = '::users.id IN (?ai:ids)';
             $vars  = [
                 ':ids' => \array_keys($ids),
             ];
         }
 
-        $query = 'UPDATE ::users AS u
-            SET u.num_posts = COALESCE((
+        $query = 'UPDATE ::users
+            SET num_posts = COALESCE((
                 SELECT COUNT(p.id)
                 FROM ::posts AS p
                 INNER JOIN ::topics AS t ON t.id=p.topic_id
                 INNER JOIN ::forums AS f ON f.id=t.forum_id
-                WHERE p.poster_id=u.id AND f.no_sum_mess=0
+                WHERE p.poster_id=::users.id AND f.no_sum_mess=0
                 GROUP BY p.poster_id
             ), 0)
             WHERE ' . $where;

+ 5 - 5
app/Models/User/UpdateCountTopics.php

@@ -38,21 +38,21 @@ class UpdateCountTopics extends Action
         unset($ids[0]); // ????
 
         if (empty($ids)) {
-            $where = 'u.id > 0';
+            $where = '::users.id > 0';
             $vars  = [];
         } else {
-            $where = 'u.id IN (?ai:ids)';
+            $where = '::users.id IN (?ai:ids)';
             $vars  = [
                 ':ids' => \array_keys($ids),
             ];
         }
 
-        $query = 'UPDATE ::users AS u
-            SET u.num_topics = COALESCE((
+        $query = 'UPDATE ::users
+            SET num_topics = COALESCE((
                 SELECT COUNT(t.id)
                 FROM ::topics AS t
                 INNER JOIN ::posts AS p ON t.first_post_id=p.id
-                WHERE p.poster_id=u.id AND t.moved_to=0
+                WHERE p.poster_id=::users.id AND t.moved_to=0
                 GROUP BY p.poster_id
             ), 0)
             WHERE ' . $where;