Expire the cache of a User object when a group membership is set to expire
authorThis, that and the other <at.light@live.com.au>
Tue, 25 Apr 2017 03:55:26 +0000 (13:55 +1000)
committerThis, that and the other <at.light@live.com.au>
Tue, 25 Apr 2017 03:55:26 +0000 (13:55 +1000)
To avoid user permissions persisting for up to 1 hour beyond their expiry
time.

Bug: T163691
Change-Id: I85b578e6b7816639c3d0101d66efb1efedb17af6

includes/user/User.php

index b8a36b8..3edd49f 100644 (file)
@@ -509,6 +509,17 @@ class User implements IDBAccessObject {
 
                                $ttl = $cache->adaptiveTTL( wfTimestamp( TS_UNIX, $this->mTouched ), $ttl );
 
+                               // if a user group membership is about to expire, the cache needs to
+                               // expire at that time (T163691)
+                               foreach ( $this->mGroupMemberships as $ugm ) {
+                                       if ( $ugm->getExpiry() ) {
+                                               $secondsUntilExpiry = wfTimestamp( TS_UNIX, $ugm->getExpiry() ) - time();
+                                               if ( $secondsUntilExpiry > 0 && $secondsUntilExpiry < $ttl ) {
+                                                       $ttl = $secondsUntilExpiry;
+                                               }
+                                       }
+                               }
+
                                return $data;
 
                        },