Pluralise user role relations table name.
This commit is contained in:
parent
b4d4e8578c
commit
70623d3a7c
9 changed files with 19 additions and 10 deletions
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
|
||||
final class PluraliseUsersForRoleRelations_20230727_130516 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
$conn->execute('RENAME TABLE msz_user_roles TO msz_users_roles');
|
||||
}
|
||||
}
|
|
@ -103,7 +103,7 @@ $getUsers = DB::prepare(sprintf(
|
|||
FROM `msz_users` AS u
|
||||
LEFT JOIN `msz_roles` AS r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
LEFT JOIN `msz_user_roles` AS ur
|
||||
LEFT JOIN `msz_users_roles` AS ur
|
||||
ON ur.`user_id` = u.`user_id`
|
||||
WHERE ur.`role_id` = :role_id
|
||||
%1$s
|
||||
|
|
|
@ -71,7 +71,7 @@ if(!empty($searchQuery)) {
|
|||
FROM `msz_users` AS u
|
||||
LEFT JOIN `msz_roles` AS r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
LEFT JOIN `msz_user_roles` AS ur
|
||||
LEFT JOIN `msz_users_roles` AS ur
|
||||
ON ur.`user_id` = u.`user_id`
|
||||
WHERE LOWER(u.`username`) LIKE CONCAT("%%", LOWER(:query), "%%")
|
||||
GROUP BY u.`user_id`
|
||||
|
|
|
@ -138,7 +138,7 @@ if(isset($_POST['action']) && is_string($_POST['action'])) {
|
|||
$tmpFiles[] = db_to_zip($archive, $currentUserId, 'sessions', ['session_id:s', 'user_id:s', 'session_key:n', 'session_ip:a', 'session_ip_last:a:n', 'session_user_agent:s', 'session_country:s', 'session_expires:t', 'session_expires_bump:b', 'session_created:t', 'session_active:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $currentUserId, 'users', ['user_id:s', 'username:s', 'password:n', 'email:s', 'register_ip:a', 'last_ip:a', 'user_super:b', 'user_country:s', 'user_colour:i:n', 'user_created:t', 'user_active:t:n', 'user_deleted:t:n', 'display_role:s:n', 'user_totp_key:n', 'user_about_content:s:n', 'user_about_parser:i', 'user_signature_content:s:n', 'user_signature_parser:i', 'user_birthdate:s:n', 'user_background_settings:i:n', 'user_title:s:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $currentUserId, 'users_password_resets', ['user_id:s', 'reset_ip:a', 'reset_requested:t', 'verification_code:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $currentUserId, 'user_roles', ['user_id:s', 'role_id:s']);
|
||||
$tmpFiles[] = db_to_zip($archive, $currentUserId, 'users_roles', ['user_id:s', 'role_id:s']);
|
||||
$tmpFiles[] = db_to_zip($archive, $currentUserId, 'user_warnings', ['warning_id:s', 'user_id:s', 'user_ip:a', 'issuer_id:n', 'issuer_ip:n', 'warning_created:t', 'warning_duration:t:n', 'warning_type:i', 'warning_note:s', 'warning_note_private:s:n']);
|
||||
|
||||
$archive->close();
|
||||
|
|
|
@ -75,7 +75,7 @@ function forum_perms_get_user(?int $forum, int $user): array {
|
|||
`user_id` IS NULL
|
||||
AND `role_id` IN (
|
||||
SELECT `role_id`
|
||||
FROM `msz_user_roles`
|
||||
FROM `msz_users_roles`
|
||||
WHERE `user_id` = :user_id_2
|
||||
)
|
||||
)
|
||||
|
|
|
@ -9,7 +9,7 @@ class UserRoleRelation {
|
|||
private $user_id = -1;
|
||||
private $role_id = -1;
|
||||
|
||||
public const TABLE = 'user_roles';
|
||||
public const TABLE = 'users_roles';
|
||||
private const QUERY_SELECT = 'SELECT %1$s FROM `' . DB::PREFIX . self::TABLE . '` AS '. self::TABLE;
|
||||
private const SELECT = '%1$s.`user_id`, %1$s.`role_id`';
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ function perms_get_user(int $user): array {
|
|||
`user_id` IS NULL
|
||||
AND `role_id` IN (
|
||||
SELECT `role_id`
|
||||
FROM `msz_user_roles`
|
||||
FROM `msz_users_roles`
|
||||
WHERE `user_id` = :user_id_2
|
||||
)
|
||||
)
|
||||
|
|
|
@ -51,10 +51,10 @@ msz_sched_task_sql('Ensure main role exists.', true,
|
|||
'INSERT IGNORE INTO msz_roles (role_id, role_name, role_hierarchy, role_colour, role_description, role_created) VALUES (1, "Member", 1, 1073741824, NULL, NOW())');
|
||||
|
||||
msz_sched_task_sql('Ensure all users have the main role.', true,
|
||||
'INSERT INTO msz_user_roles (user_id, role_id) SELECT user_id, 1 FROM msz_users AS u WHERE NOT EXISTS (SELECT 1 FROM msz_user_roles AS ur WHERE role_id = 1 AND u.user_id = ur.user_id)');
|
||||
'INSERT INTO msz_users_roles (user_id, role_id) SELECT user_id, 1 FROM msz_users AS u WHERE NOT EXISTS (SELECT 1 FROM msz_users_roles AS ur WHERE role_id = 1 AND u.user_id = ur.user_id)');
|
||||
|
||||
msz_sched_task_sql('Ensure all display_role field values are correct with msz_user_roles.', true,
|
||||
'UPDATE msz_users AS u SET display_role = (SELECT ur.role_id FROM msz_user_roles AS ur LEFT JOIN msz_roles AS r ON r.role_id = ur.role_id WHERE ur.user_id = u.user_id ORDER BY role_hierarchy DESC LIMIT 1) WHERE NOT EXISTS (SELECT 1 FROM msz_user_roles AS ur WHERE ur.role_id = u.display_role AND ur.user_id = u.user_id)');
|
||||
msz_sched_task_sql('Ensure all display_role field values are correct with msz_users_roles.', true,
|
||||
'UPDATE msz_users AS u SET display_role = (SELECT ur.role_id FROM msz_users_roles AS ur LEFT JOIN msz_roles AS r ON r.role_id = ur.role_id WHERE ur.user_id = u.user_id ORDER BY role_hierarchy DESC LIMIT 1) WHERE NOT EXISTS (SELECT 1 FROM msz_users_roles AS ur WHERE ur.role_id = u.display_role AND ur.user_id = u.user_id)');
|
||||
|
||||
msz_sched_task_sql('Remove expired sessions.', false,
|
||||
'DELETE FROM msz_sessions WHERE session_expires < NOW()');
|
||||
|
|
|
@ -220,7 +220,7 @@ $dbConn->execute('ALTER TABLE msz_users AUTO_INCREMENT = 1');
|
|||
|
||||
mkv_log('Preparing user insert statements...');
|
||||
$cu = $dbConn->prepare('INSERT INTO msz_users (username, password, email, register_ip, last_ip, user_super, user_country, user_about_content, user_about_parser, user_signature_content, user_signature_parser, user_birthdate, user_title, display_role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
$ur = $dbConn->prepare('REPLACE INTO msz_user_roles (user_id, role_id) VALUES (?, ?)');
|
||||
$ur = $dbConn->prepare('REPLACE INTO msz_users_roles (user_id, role_id) VALUES (?, ?)');
|
||||
|
||||
mkv_log('Creating admin user...');
|
||||
mkv_log('NOTICE: All passwords will be set to: ' . MKV_PASSWD);
|
||||
|
|
Loading…
Reference in a new issue