This patch adds an ug_expiry column to the user_groups table, a timestamp giving a date when the user group expires. A new UserGroupMembership class, based on the Block class, manages entries in this table. When the expiry date passes, the row in user_groups is ignored, and will eventually be purged from the DB when UserGroupMembership::insert is next called. Old, expired user group memberships are not kept; instead, the log entries are available to find the history of these memberships, similar to the way it has always worked for blocks and protections. Anyone getting user group info through the User object will get correct information. However, code that reads the user_groups table directly will now need to skip over rows with ug_expiry < wfTimestampNow(). See UsersPager for an example of how to do this. NULL is used to represent infinite (no) expiry, rather than a string 'infinity' or similar (except in the API). This allows existing user group assignments and log entries, which are all infinite in duration, to be treated the same as new, infinite-length memberships, without special casing everything. The whole thing is behind the temporary feature flag $wgDisableUserGroupExpiry, in accordance with the WMF schema change policy. The opportunity has been taken to refactor some static user-group-related functions out of User into UserGroupMembership, and also to add a primary key (ug_user, ug_group) to the user_groups table. There are a few breaking changes: - UserRightsProxy-like objects are now required to have a getGroupMemberships() function. - $user->mGroups (on a User object) is no longer present. - Some protected functions in UsersPager are altered or removed. - The UsersPagerDoBatchLookups hook (unused in any Wikimedia Git-hosted extension) has a change of parameter. Bug: T12493 Depends-On: Ia9616e1e35184fed9058d2d39afbe1038f56d7fa Depends-On: I86eb1d5619347ce54a5f33a591417742ebe5d6f8 Change-Id: I93c955dc7a970f78e32aa503c01c67da30971d1a
21 lines
605 B
SQL
21 lines
605 B
SQL
DROP TABLE IF EXISTS /*_*/user_groups_tmp;
|
|
|
|
CREATE TABLE /*$wgDBprefix*/user_groups_tmp (
|
|
ug_user int unsigned NOT NULL default 0,
|
|
ug_group varbinary(255) NOT NULL default '',
|
|
ug_expiry varbinary(14) NULL default NULL,
|
|
PRIMARY KEY (ug_user, ug_group)
|
|
);
|
|
|
|
INSERT OR IGNORE INTO /*_*/user_groups_tmp (
|
|
ug_user, ug_group )
|
|
SELECT
|
|
ug_user, ug_group
|
|
FROM /*_*/user_groups;
|
|
|
|
DROP TABLE /*_*/user_groups;
|
|
|
|
ALTER TABLE /*_*/user_groups_tmp RENAME TO /*_*/user_groups;
|
|
|
|
CREATE INDEX /*i*/ug_group ON /*_*/user_groups (ug_group);
|
|
CREATE INDEX /*i*/ug_expiry ON /*_*/user_groups (ug_expiry);
|