| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Notifications\Push; |
| 4 | |
| 5 | use MediaWiki\MediaWikiServices; |
| 6 | use MediaWiki\User\CentralId\CentralIdLookup; |
| 7 | use MediaWiki\User\UserIdentity; |
| 8 | |
| 9 | class Utils { |
| 10 | |
| 11 | /** |
| 12 | * Attempt to get a unique ID for the specified user, accounting for installations both with |
| 13 | * and without CentralAuth: Return the user's central ID, if available. If there is no central |
| 14 | * user associated with the local user (i.e., centralIdFromLocalUser returns 0), fall back to |
| 15 | * returning the local user ID. |
| 16 | * @param UserIdentity $user |
| 17 | * @return int |
| 18 | */ |
| 19 | public static function getPushUserId( UserIdentity $user ): int { |
| 20 | return MediaWikiServices::getInstance() |
| 21 | ->getCentralIdLookup() |
| 22 | ->centralIdFromLocalUser( |
| 23 | $user, |
| 24 | CentralIdLookup::AUDIENCE_RAW |
| 25 | ) ?: $user->getId(); |
| 26 | } |
| 27 | |
| 28 | } |