namespace MediaWiki\Session;
+use MediaWiki\MediaWikiServices;
use Psr\Log\LoggerInterface;
use BagOStuff;
use CachedBagOStuff;
}
$session = null;
+ $info = new SessionInfo( SessionInfo::MIN_PRIORITY, [ 'id' => $id, 'idIsSafe' => true ] );
- // Test this here to provide a better log message for the common case
- // of "no such ID"
+ // If we already have the backend loaded, use it directly
+ if ( isset( $this->allSessionBackends[$id] ) ) {
+ return $this->getSessionFromInfo( $info, $request );
+ }
+
+ // Test if the session is in storage, and if so try to load it.
$key = wfMemcKey( 'MWSession', $id );
if ( is_array( $this->store->get( $key ) ) ) {
- $create = false;
- $info = new SessionInfo( SessionInfo::MIN_PRIORITY, [ 'id' => $id, 'idIsSafe' => true ] );
+ $create = false; // If loading fails, don't bother creating because it probably will fail too.
if ( $this->loadSessionInfoFromStore( $info, $request ) ) {
$session = $this->getSessionFromInfo( $info, $request );
}
* The intention is that the named account will never again be usable for
* normal login (i.e. there is no way to undo the prevention of access).
*
- * @private For use from \\User::newSystemUser only
+ * @private For use from \User::newSystemUser only
* @param string $username
*/
public function preventSessionsForUser( $username ) {
if ( defined( 'MW_NO_SESSION' ) ) {
if ( MW_NO_SESSION === 'warn' ) {
// Undocumented safety case for converting existing entry points
- $this->logger->error( 'Sessions are supposed to be disabled for this entry point' );
+ $this->logger->error( 'Sessions are supposed to be disabled for this entry point', [
+ 'exception' => new \BadMethodCallException( 'Sessions are disabled for this entry point' ),
+ ] );
} else {
throw new \BadMethodCallException( 'Sessions are disabled for this entry point' );
}
/**
* Deregister a SessionBackend
- * @private For use from \\MediaWiki\\Session\\SessionBackend only
+ * @private For use from \MediaWiki\Session\SessionBackend only
* @param SessionBackend $backend
*/
public function deregisterSessionBackend( SessionBackend $backend ) {
/**
* Change a SessionBackend's ID
- * @private For use from \\MediaWiki\\Session\\SessionBackend only
+ * @private For use from \MediaWiki\Session\SessionBackend only
* @param SessionBackend $backend
*/
public function changeBackendId( SessionBackend $backend ) {
* Reset the internal caching for unit testing
*/
public static function resetCache() {
- if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
- // @codeCoverageIgnoreStart
- throw new MWException( __METHOD__ . ' may only be called from unit tests!' );
- // @codeCoverageIgnoreEnd
- }
+ MediaWikiServices::failUnlessBootstrapping( __METHOD__ );
self::$globalSession = null;
self::$globalSessionRequest = null;