function SessionTestController::triggerWriteException

Same name in other branches
  1. 10 core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php \Drupal\session_test\Controller\SessionTestController::triggerWriteException()

Trigger an exception when the session is written.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

1 string reference to 'SessionTestController::triggerWriteException'
session_test.routing.yml in core/modules/system/tests/modules/session_test/session_test.routing.yml
core/modules/system/tests/modules/session_test/session_test.routing.yml

File

core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php, line 256

Class

SessionTestController
Controller providing page callbacks for the action admin interface.

Namespace

Drupal\session_test\Controller

Code

public function triggerWriteException(Request $request) {
    $session = $request->getSession();
    $session->set('test_value', 'Ensure session contains some data');
    // Move sessions table out of the way.
    $schema = \Drupal::database()->schema();
    $schema->renameTable('sessions', 'sessions_tmp');
    // There needs to be a session table, otherwise
    // InstallerRedirectTrait::shouldRedirectToInstaller() will instruct the
    // handleException::handleException to redirect to the installer.
    $schema->createTable('sessions', [
        'description' => "Fake sessions table missing some columns.",
        'fields' => [
            'sid' => [
                'description' => "A fake session ID column.",
                'type' => 'varchar_ascii',
                'length' => 128,
                'not null' => TRUE,
            ],
        ],
        'primary key' => [
            'sid',
        ],
    ]);
    drupal_register_shutdown_function(function () {
        $schema = \Drupal::database()->schema();
        $schema->dropTable('sessions');
        $schema->renameTable('sessions_tmp', 'sessions');
    });
    return new Response();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.