Add last_poster_id field for forums table

This commit is contained in:
Visman 2020-11-01 17:47:12 +07:00
parent 02e292fca4
commit 59c3578b4e
2 changed files with 21 additions and 2 deletions

View file

@ -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]);

View file

@ -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;
}
}