Page MenuHomeIn-Portal Phabricator

D447.id1174.diff
No OneTemporary

File Metadata

Created
Thu, Feb 6, 4:32 PM

D447.id1174.diff

Index: branches/5.2.x/core/units/helpers/user_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/user_helper.php
+++ branches/5.2.x/core/units/helpers/user_helper.php
@@ -722,4 +722,32 @@
return $object->Update() ? '' : 'restore_impossible';
}
+
+ /**
+ * Returns user's primary group.
+ *
+ * @param integer $user_id User ID.
+ *
+ * @return integer
+ */
+ public function getPrimaryGroup($user_id)
+ {
+ if ( $user_id <= 0 ) {
+ return $this->Application->ConfigValue('User_LoggedInGroup');
+ }
+
+ $cache_key = 'user' . $user_id . '_primary_group[%UIDSerial:' . $user_id . '%]';
+ $cache_value = $this->Application->getCache($cache_key);
+
+ if ( $cache_value === false ) {
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'Users
+ WHERE PortalUserId = ' . $user_id;
+ $cache_value = $this->Conn->GetOne($sql);
+ $this->Application->setCache($cache_key, $cache_value);
+ }
+
+ return $cache_value;
+ }
+
}
Index: branches/5.2.x/core/units/users/users_event_handler.php
===================================================================
--- branches/5.2.x/core/units/users/users_event_handler.php
+++ branches/5.2.x/core/units/users/users_event_handler.php
@@ -1665,6 +1665,12 @@
WHERE PortalUserId IN (' . implode(',', $user_ids) . ')';
$this->Conn->Query($sql);
+ foreach ( $user_ids as $user_id ) {
+ $this->Application->incrementCacheSerial('u', $user_id);
+ }
+
+ $this->Application->incrementCacheSerial('u');
+
$sql = 'SELECT PortalUserId
FROM ' . $table_name . '
WHERE (GroupId = ' . $primary_group_id . ') AND (PortalUserId IN (' . implode(',', $user_ids) . '))';

Event Timeline