Skip to content

Fix: login-as crash 'Database Manager is not initialized' (backport #8661 to 2.0)#8677

Open
addow wants to merge 1 commit into
chamilo:2.0from
webstone:fix/login-as-legacy-2.0-backport
Open

Fix: login-as crash 'Database Manager is not initialized' (backport #8661 to 2.0)#8677
addow wants to merge 1 commit into
chamilo:2.0from
webstone:fix/login-as-legacy-2.0-backport

Conversation

@addow

@addow addow commented Jun 30, 2026

Copy link
Copy Markdown

Problem

When a platform admin uses the switch-user feature (/?_switch_user=...), a fatal error occurs:

Call to a member function get() on null (Database Manager is not initialized)

Root cause

The Symfony firewall fires the switch_user event at priority 8, before LegacyListener initialises the legacy Container at priority 7. The call chain:

SwitchUserListenerSwitchUserSubscriberLoginAsAuthorizationChecker::isGlobalPlatformAdmin()api_is_global_platform_admin()Database::getManager()fatal

Fix

Backport of upstream/master commit 8432203a14 ("Internal: Fix 'login as' admin/hrm - refs #8661"):

  1. LoginAsAuthorizationChecker::isGlobalPlatformAdmin() — replace api_is_global_platform_admin() with User::isSuperAdmin(), which reads directly from the already-loaded Doctrine entity and needs no legacy Container.

  2. LoginAsAuthorizationChecker::canDrhLoginAs() — replace the SessionManager/UserManager legacy helpers with a clean Doctrine UserRepository::isUserFollowedByDrh() call, eliminating the remaining legacy Container dependency from this service.

  3. UserRepository::isUserFollowedByDrh() — new Doctrine method, native replacement for UserManager::is_user_followed_by_drh().

  4. LoginAsAuthorizationCheckerTest — unit test for all impersonation policy paths (also from the original commit).

The fix on upstream/master was not backported to the 2.0 branch; this PR does exactly that.

Backport of upstream/master commit 8432203.

Replaces legacy api_is_global_platform_admin() with User::isSuperAdmin() to
avoid a fatal crash when the Symfony firewall fires the switch_user event at
priority 8, before LegacyListener initialises the legacy Container at priority 7.

Also replaces the legacy SessionManager/UserManager DRH path with a clean
Doctrine-based UserRepository::isUserFollowedByDrh() lookup, removing all
remaining legacy Container dependencies from this service.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant