Selaa lähdekoodia

Add last_poster_id field for forums table

Visman 4 vuotta sitten
vanhempi
commit
59c3578b4e
2 muutettua tiedostoa jossa 21 lisäystä ja 2 poistoa
  1. 2 1
      app/Models/Pages/Admin/Install.php
  2. 19 1
      app/Models/Pages/Admin/Update.php

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

@@ -586,6 +586,7 @@ class Install extends Admin
                 'last_post'       => ['INT(10) UNSIGNED', false, 0],
                 'last_post_id'    => ['INT(10) UNSIGNED', false, 0],
                 'last_poster'     => ['VARCHAR(190)', false, ''],
+                'last_poster_id'  => ['INT(10) UNSIGNED', false, 0],
                 'last_topic'      => ['VARCHAR(255)', false, ''],
                 'sort_by'         => ['TINYINT(1)', false, 0],
                 'disp_position'   => ['INT(10)', false, 0],
@@ -1143,7 +1144,7 @@ class Install extends Admin
         }
 
         $this->c->DB->exec('INSERT INTO ::categories (cat_name, disp_position) VALUES (?s, ?i)', [__('Test category'), 1]);
-        $this->c->DB->exec('INSERT INTO ::forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, last_topic, disp_position, cat_id, moderators) VALUES (?s, ?s, ?i, ?i, ?i, ?i, ?s, ?s, ?i, ?i, \'\')', [__('Test forum'), __('This is just a test forum'), 1, 1, $now, 1, $v->username, __('Test post'), 1, 1]);
+        $this->c->DB->exec('INSERT INTO ::forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, last_poster_id, last_topic, disp_position, cat_id, moderators) VALUES (?s, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?s, ?i, ?i, \'\')', [__('Test forum'), __('This is just a test forum'), 1, 1, $now, 1, $v->username, 2, __('Test post'), 1, 1]);
         $this->c->DB->exec('INSERT INTO ::topics (poster, subject, posted, first_post_id, last_post, last_post_id, last_poster, forum_id) VALUES(?s, ?s, ?i, ?i, ?i, ?i, ?s, ?i)', [$v->username, __('Test post'), $now, 1, $now, 1, $v->username, 1]);
         $this->c->DB->exec('INSERT INTO ::posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(?s, ?i, ?s, ?s, ?i, ?i)', [$v->username, 2, $ip, __('Test message'), $now, 1]);
 

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

@@ -19,7 +19,7 @@ class Update extends Admin
 {
     const PHP_MIN = '7.3.0';
 
-    const LATEST_REV_WITH_DB_CHANGES = 19;
+    const LATEST_REV_WITH_DB_CHANGES = 24;
 
     const LOCK_NAME = 'lock_update';
     const LOCk_TTL  = 1800;
@@ -997,4 +997,22 @@ class Update extends Admin
 
         return null;
     }
+
+    /**
+     * rev.23 to rev.24
+     */
+    protected function stageNumber23(array $args): ?int
+    {
+        $this->c->DB->addField('forums', 'last_poster_id', 'INT(10) UNSIGNED', false, 0, 'last_poster');
+
+        $query = 'UPDATE ::forums AS f
+            SET f.last_poster_id=(
+                SELECT u.id
+                FROM ::users AS u
+                WHERE u.username=f.last_poster
+            )';
+        $this->c->DB->exec($query);
+
+        return null;
+    }
 }