Jelajahi Sumber

Add editor_id field to posts table

Visman 4 tahun lalu
induk
melakukan
ab58de9f95

+ 1 - 0
app/Models/Pages/Admin/Install.php

@@ -676,6 +676,7 @@ class Install extends Admin
                 'posted'       => ['INT(10) UNSIGNED', false, 0],
                 'edited'       => ['INT(10) UNSIGNED', false, 0],
                 'editor'       => ['VARCHAR(190)', false, ''],
+                'editor_id'    => ['INT(10) UNSIGNED', false, 0],
                 'user_agent'   => ['VARCHAR(255)', false, ''],
                 'topic_id'     => ['INT(10) UNSIGNED', false, 0],
             ],

+ 10 - 1
app/Models/Pages/Admin/Update.php

@@ -1009,11 +1009,20 @@ class Update extends Admin
             SET f.last_poster_id=(
                 SELECT u.id
                 FROM ::users AS u
-                WHERE u.username=f.last_poster
+                WHERE u.username=f.last_poster AND u.id > 1
             )';
         $this->c->DB->exec($query);
 
         $this->c->DB->renameField('posts', 'edited_by', 'editor');
+        $this->c->DB->addField('posts', 'editor_id', 'INT(10) UNSIGNED', false, 0, 'editor');
+
+        $query = 'UPDATE ::posts AS p
+            SET p.editor_id=(
+                SELECT u.id
+                FROM ::users AS u
+                WHERE u.username=p.editor AND u.id > 1
+            )';
+        $this->c->DB->exec($query);
 
         return null;
     }

+ 2 - 0
app/Models/Pages/Edit.php

@@ -95,6 +95,7 @@ class Edit extends Page
             $post->message       = $v->message;
             $post->edited        = $now;
             $post->editor        = $this->user->username;
+            $post->editor_id     = $this->user->id;
             $calcPost            = true;
             if ($post->id === $topic->last_post_id) {
                 $calcTopic       = true;
@@ -122,6 +123,7 @@ class Edit extends Page
                 $topic->subject  = $v->subject;
                 $post->edited    = $now;
                 $post->editor    = $this->user->username;
+                $post->editor_id = $this->user->id;
                 $calcForum       = true;
             }
             // выделение темы

+ 3 - 1
app/Models/Pages/Post.php

@@ -211,7 +211,8 @@ class Post extends Page
             if ($newLength < $this->c->MAX_POST_SIZE - 100) {
                 $lastPost->message   = $lastPost->message . "\n[after=" . ($now - $topic->last_post) . "]\n" . $v->message; //????
                 $lastPost->edited    = $now;
-                $lastPost->editor    = $username;
+                $lastPost->editor    = $username;       // ???? может копировать из poster
+                $lastPost->editor_id = $this->user->id; // ???? может копировать из poster_id
 
                 $this->c->posts->update($lastPost);
             } else {
@@ -233,6 +234,7 @@ class Post extends Page
             $post->posted       = $now;
 #           $post->edited       =
 #           $post->editor       =
+#           $post->editor_id    =
             $post->user_agent   = $this->user->userAgent;
             $post->topic_id     = $topic->id;