diff --git a/core/core.services.yml b/core/core.services.yml index 98b418f..f58e360 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1133,7 +1133,7 @@ services: alias: session_handler.storage session_handler.storage: class: Drupal\Core\Session\SessionHandler - arguments: ['@request_stack', '@database'] + arguments: ['@request_stack', '@database', '%session_write_interval%'] tags: - { name: backend_overridable } session_handler.write_check: diff --git a/core/lib/Drupal/Core/Session/SessionHandler.php b/core/lib/Drupal/Core/Session/SessionHandler.php index 42daba5..0001af8 100644 --- a/core/lib/Drupal/Core/Session/SessionHandler.php +++ b/core/lib/Drupal/Core/Session/SessionHandler.php @@ -41,16 +41,26 @@ class SessionHandler extends AbstractProxy implements \SessionHandlerInterface { protected $obsoleteSessionIds = array(); /** + * The session write interval. + * + * @var int + */ + protected $sessionWriteInterval; + + /** * Constructs a new SessionHandler instance. * * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. * @param \Drupal\Core\Database\Connection $connection * The database connection. + * @param int $session_write_interval + * The session write interval. */ - public function __construct(RequestStack $request_stack, Connection $connection) { + public function __construct(RequestStack $request_stack, Connection $connection, $session_write_interval = 180) { $this->requestStack = $request_stack; $this->connection = $connection; + $this->sessionWriteInterval = $session_write_interval; } /** @@ -126,7 +136,7 @@ public function write($sid, $value) { ->execute(); // Likewise, do not update access time more than once per 180 seconds. - if ($user->isAuthenticated() && REQUEST_TIME - $user->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { + if ($user->isAuthenticated() && REQUEST_TIME - $user->getLastAccessedTime() > $this->sessionWriteInterval) { /** @var \Drupal\user\UserStorageInterface $storage */ $storage = \Drupal::entityManager()->getStorage('user'); $storage->updateLastAccessTimestamp($user, REQUEST_TIME); diff --git a/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php index 0822063..5594b7c 100644 --- a/core/modules/system/src/Tests/File/DirectoryTest.php +++ b/core/modules/system/src/Tests/File/DirectoryTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\File; use Drupal\Component\PhpStorage\FileStorage; +use Drupal\Core\File\FileSystem; /** * Tests operations dealing with directories. @@ -81,7 +82,8 @@ function testFileCheckDirectoryHandling() { $this->assertFalse(file_prepare_directory($directory, 0), 'Error reported for a non-writeable directory.', 'File'); // Test directory permission modification. - $this->settingsSet('file_chmod_directory', 0777); + $this->container->set('file_system', new FileSystem($this->container->get('stream_wrapper_manager'), ['directory' => 0777], $this->container->get('logger.channel.file'))); + $this->assertTrue(file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS), 'No error reported when making directory writeable.', 'File'); } diff --git a/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php b/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php index fc715c6..2e1e507 100644 --- a/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php +++ b/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\system\Tests\File; +use Drupal\Core\File\FileSystem; /** * Tests the file_unmanaged_save_data() function. @@ -18,7 +19,8 @@ class UnmanagedSaveDataTest extends FileTestBase { */ function testFileSaveData() { $contents = $this->randomMachineName(8); - $this->settingsSet('file_chmod_file', 0777); + $this->container->set('file_system', new FileSystem($this->container->get('stream_wrapper_manager'), ['file' => 0777], $this->container->get('logger.channel.file'))); + // No filename. $filepath = file_unmanaged_save_data($contents); diff --git a/core/modules/system/src/Tests/Session/SessionTest.php b/core/modules/system/src/Tests/Session/SessionTest.php index 0921f66..c4f89c5 100644 --- a/core/modules/system/src/Tests/Session/SessionTest.php +++ b/core/modules/system/src/Tests/Session/SessionTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Session; +use Drupal\Component\Serialization\Yaml; use Drupal\simpletest\WebTestBase; /** @@ -228,13 +229,12 @@ function testSessionWrite() { $this->assertEqual($times4->timestamp, $times3->timestamp, 'Sessions table was not updated.'); // Force updating of users and sessions table once per second. - $this->settingsSet('session_write_interval', 0); - // Write that value also into the test settings.php file. - $settings['settings']['session_write_interval'] = (object) array( - 'value' => 0, - 'required' => TRUE, - ); - $this->writeSettings($settings); + $filename = $this->siteDirectory . '/services.yml'; + $data = Yaml::decode(file_get_contents($filename)); + $data['parameters']['session_write_interval'] = 0; + file_put_contents($filename, Yaml::encode($data)); + $this->rebuildContainer(); + $this->drupalGet(''); $times5 = db_query($sql, array(':uid' => $user->id()))->fetchObject(); $this->assertNotEqual($times5->access, $times4->access, 'Users table was updated.');