public static function doAsSuperUser($function)
    {
        $isSuperUser = self::getInstance()->hasSuperUserAccess();

        $access = self::getInstance();
        $login = $access->getLogin();
        $shouldResetLogin = empty($login); // make sure to reset login if a login was set by "makeSureLoginNameIsSet()"
        $access->setSuperUserAccess(true);

        try {
            $result = $function();
        } catch (Exception $ex) {
            $access->setSuperUserAccess($isSuperUser);
            if ($shouldResetLogin) {
                $access->login = null;
            }

            throw $ex;
        }

        if ($shouldResetLogin) {
            $access->login = null;
        }
        $access->setSuperUserAccess($isSuperUser);

        return $result;
    }
public static function doAsSuperUser($function)
    {
        $isSuperUser = self::getInstance()->hasSuperUserAccess();

        $access = self::getInstance();
        $login = $access->getLogin();
        $shouldResetLogin = empty($login); // make sure to reset login if a login was set by "makeSureLoginNameIsSet()"
        $access->setSuperUserAccess(true);

        try {
            $result = $function();
        } catch (Exception $ex) {
            $access->setSuperUserAccess($isSuperUser);
            if ($shouldResetLogin) {
                $access->login = null;
            }

            throw $ex;
        }

        if ($shouldResetLogin) {
            $access->login = null;
        }
        $access->setSuperUserAccess($isSuperUser);

        return $result;
    }
public static function doAsSuperUser ( $ function ) { $ isSuperUser = self :: getInstance ( ) -> hasSuperUserAccess ( ) ; $ access = self :: getInstance ( ) ; $ login = $ access -> getLogin ( ) ; $ shouldResetLogin = empty ( $ login ) ; // make sure to reset login if a login was set by "makeSureLoginNameIsSet()" $ access -> setSuperUserAccess ( true ) ; try { $ result = $ function ( ) ; } catch ( Exception $ ex ) { $ access -> setSuperUserAccess ( $ isSuperUser ) ; if ( $ shouldResetLogin ) { $ access -> login = null ; } throw $ ex ; } if ( $ shouldResetLogin ) { $ access -> login = null ; } $ access -> setSuperUserAccess ( $ isSuperUser ) ; return $ result ; }
Executes a callback with superuser privileges, making sure those privileges are rescinded
before this method exits. Privileges will be rescinded even if an exception is thrown.

@param callback $function The callback to execute. Should accept no arguments.
@return mixed The result of `$function`.
@throws Exception rethrows any exceptions thrown by `$function`.
@api
Executes a callback with superuser privileges making sure those privileges are rescinded before this method exits . Privileges will be rescinded even if an exception is thrown .