diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index dfb61e1..07bbfdf 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3489,7 +3489,7 @@ function drupal_php_storage($name = 'default') { $configuration['bin'] = $name; } if (!isset($configuration['directory'])) { - $configuration['directory'] = DRUPAL_ROOT . '/' . variable_get('file_public_path', conf_path() . '/files') . '/php'; + $configuration['directory'] = DRUPAL_ROOT . '/' . config('system.file')->get('path.public') . '/php'; } $storage_controllers[$name] = new $class($configuration); } diff --git a/core/includes/file.inc b/core/includes/file.inc index 16ed619..b373189 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -320,7 +320,7 @@ function file_uri_target($uri) { * 'public', 'private' or any other file scheme defined as the default. */ function file_default_scheme() { - return variable_get('file_default_scheme', 'public'); + return config('system.file')->get('default_scheme'); } /** @@ -526,7 +526,7 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) */ function file_ensure_htaccess() { file_save_htaccess('public://', FALSE); - if (variable_get('file_private_path', FALSE)) { + if (config('system.file')->get('path.private')) { file_save_htaccess('private://', TRUE); } file_save_htaccess('temporary://', TRUE); @@ -1562,10 +1562,10 @@ function file_get_mimetype($uri, $mapping = NULL) { function drupal_chmod($uri, $mode = NULL) { if (!isset($mode)) { if (is_dir($uri)) { - $mode = variable_get('file_chmod_directory', 0775); + $mode = config('system.file')->get('chmod.directory'); } else { - $mode = variable_get('file_chmod_file', 0664); + $mode = config('system.file')->get('chmod.file'); } } @@ -1742,7 +1742,7 @@ function drupal_basename($uri, $suffix = NULL) { */ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { if (!isset($mode)) { - $mode = variable_get('file_chmod_directory', 0775); + $mode = config('system.file')->get('chmod.directory'); } if (!isset($context)) { @@ -1828,7 +1828,7 @@ function drupal_tempnam($directory, $prefix) { * Gets the path of system-appropriate temporary directory. */ function file_directory_temp() { - $temporary_directory = variable_get('file_temporary_path', NULL); + $temporary_directory = config('system.file')->get('path.temporary'); if (empty($temporary_directory)) { $directories = array(); @@ -1858,7 +1858,7 @@ function file_directory_temp() { if (empty($temporary_directory)) { // If no directory has been found default to 'files/tmp'. - $temporary_directory = variable_get('file_public_path', conf_path() . '/files') . '/tmp'; + $temporary_directory = config('system.file')->get('path.public') . '/tmp'; // Windows accepts paths with either slash (/) or backslash (\), but will // not accept a path which contains both a slash and a backslash. Since @@ -1866,8 +1866,9 @@ function file_directory_temp() { // everything to use slash which is supported on all platforms. $temporary_directory = str_replace('\\', '/', $temporary_directory); } + // Save the path of the discovered directory. - variable_set('file_temporary_path', $temporary_directory); + config('system.file')->set('path.temporary', $temporary_directory)->save(); } return $temporary_directory; diff --git a/core/lib/Drupal/Core/StreamWrapper/PrivateStream.php b/core/lib/Drupal/Core/StreamWrapper/PrivateStream.php index 87316eb..833580f 100644 --- a/core/lib/Drupal/Core/StreamWrapper/PrivateStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/PrivateStream.php @@ -19,7 +19,7 @@ class PrivateStream extends LocalStream { * Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath() */ public function getDirectoryPath() { - return variable_get('file_private_path', ''); + return config('system.file')->get('path.private'); } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/PublicStream.php b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php index 207b77a..dade4e9 100644 --- a/core/lib/Drupal/Core/StreamWrapper/PublicStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php @@ -19,7 +19,7 @@ class PublicStream extends LocalStream { * Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath() */ public function getDirectoryPath() { - return variable_get('file_public_path', conf_path() . '/files'); + return config('system.file')->get('path.public'); } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php b/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php index 52a6321..42dd4fd 100644 --- a/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php @@ -19,7 +19,7 @@ class TemporaryStream extends LocalStream { * Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath() */ public function getDirectoryPath() { - return variable_get('file_temporary_path', file_directory_temp()); + return file_directory_temp(); } /** diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 28a32a9..47581d0 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -16,7 +16,7 @@ function file_field_info() { 'settings' => array( 'display_field' => 0, 'display_default' => 0, - 'uri_scheme' => variable_get('file_default_scheme', 'public'), + 'uri_scheme' => file_default_scheme(), ), 'instance_settings' => array( 'file_extensions' => 'txt', diff --git a/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php b/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php index ed587d2..fb5e68b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php index a7e38ac..bd7825d 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php @@ -76,7 +76,7 @@ function setUp() { function testImageSource() { global $base_url; - $public_files_path = variable_get('file_public_path', conf_path() . '/files'); + $public_files_path = config('system.file')->get('path.public'); $http_base_url = preg_replace('/^https?/', 'http', $base_url); $https_base_url = preg_replace('/^https?/', 'https', $base_url); diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index da7f3ee..bbf1233 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -14,7 +14,7 @@ function image_field_info() { 'label' => t('Image'), 'description' => t('This field stores the ID of an image file as an integer value.'), 'settings' => array( - 'uri_scheme' => variable_get('file_default_scheme', 'public'), + 'uri_scheme' => file_default_scheme(), 'default_image' => 0, ), 'instance_settings' => array( diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php index a5ec856..bf7ce36 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php @@ -92,7 +92,7 @@ function _testImageStyleUrlAndPath($scheme, $clean_url = TRUE) { // Make the default scheme neither "public" nor "private" to verify the // functions work for other than the default scheme. - variable_set('file_default_scheme', 'temporary'); + config('system.file')->set('default_scheme', 'temporary')->save(); // Create the directories for the styles. $directory = $scheme . '://styles/' . $this->style_name; diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php index 017e2c5..7e1bfc7 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php @@ -189,7 +189,7 @@ function testCompareCheckLocal() { $timestamp_new = REQUEST_TIME; // Set up the environment. - $public_path = variable_get('file_public_path', conf_path() . '/files'); + $public_path = config('system.file')->get('path.public'); $this->setTranslationsDirectory($public_path . '/local'); $config->set('translation.default_filename', '%project-%version.%language.txt')->save(); diff --git a/core/modules/locale/tests/modules/locale_test/locale_test.module b/core/modules/locale/tests/modules/locale_test/locale_test.module index 03e455d..537fb88 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.module +++ b/core/modules/locale/tests/modules/locale_test/locale_test.module @@ -42,11 +42,11 @@ function locale_test_locale_translation_projects_alter(&$projects) { // Instead of the default ftp.drupal.org we use the file system of the test // instance to simulate a remote file location. $url = url(NULL, array('absolute' => TRUE)); - $remote_url = $url . variable_get('file_public_path', conf_path() . '/files') . '/remote/'; + $remote_url = $url . config('system.file')->get('path.public') . '/remote/'; // Completely replace the project data with a set of test projects. $base_url = url(); - $files_url = variable_get('file_public_path', conf_path() . '/files'); + $files_url = config('system.file')->get('path.public'); $projects = array ( 'drupal' => array ( 'name' => 'drupal', diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 9d151e0..d3f5b37 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -645,7 +645,7 @@ public function run(array $methods = array()) { if ($simpletest_config->get('verbose')) { // Initialize verbose debugging. $this->verbose = TRUE; - $this->verboseDirectory = variable_get('file_public_path', conf_path() . '/files') . '/simpletest/verbose'; + $this->verboseDirectory = config('system.file')->get('path.public') . '/simpletest/verbose'; $this->verboseDirectoryUrl = file_create_url($this->verboseDirectory); if (file_prepare_directory($this->verboseDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->verboseDirectory . '/.htaccess')) { file_put_contents($this->verboseDirectory . '/.htaccess', "\nExpiresActive Off\n\n"); @@ -821,7 +821,7 @@ protected function prepareEnvironment() { $this->originalTheme = $GLOBALS['theme']; // Save further contextual information. - $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files'); + $this->originalFileDirectory = config('system.file')->get('path.public'); $this->originalProfile = drupal_get_profile(); $this->originalUser = clone $user; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index c5dbd0b..f79ffb8 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -329,7 +329,7 @@ protected function drupalGetTestFiles($type, $size = NULL) { $original = drupal_get_path('module', 'simpletest') . '/files'; $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/'); foreach ($files as $file) { - file_unmanaged_copy($file->uri, variable_get('file_public_path', conf_path() . '/files')); + file_unmanaged_copy($file->uri, config('system.file')->get('path.public')); } $this->generatedTestFiles = TRUE; @@ -689,9 +689,11 @@ protected function setUp() { unset($conf['lock_backend']); // Set path variables. - variable_set('file_public_path', $this->public_files_directory); - variable_set('file_private_path', $this->private_files_directory); - variable_set('file_temporary_path', $this->temp_files_directory); + config('system.file') + ->set('path.public', $this->public_files_directory) + ->set('path.private', $this->private_files_directory) + ->set('path.temporary', $this->temp_files_directory) + ->save(); variable_set('locale_translate_file_directory', $this->translation_files_directory); // Set 'parent_profile' of simpletest to add the parent profile's diff --git a/core/modules/system/config/system.file.yml b/core/modules/system/config/system.file.yml new file mode 100644 index 0000000..bb49c66 --- /dev/null +++ b/core/modules/system/config/system.file.yml @@ -0,0 +1,8 @@ +path: + public: 'sites/default/files' + private: '' + temporary: '' +default_scheme: 'public' +chmod: + directory: 0775 + file: 0664 diff --git a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php index e6f3396..7fe367d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php @@ -24,7 +24,8 @@ public static function getInfo() { */ function testFileCheckDirectoryHandling() { // A directory to operate on. - $directory = file_default_scheme() . '://' . $this->randomName() . '/' . $this->randomName(); + $default_scheme = file_default_scheme(); + $directory = $default_scheme . '://' . $this->randomName() . '/' . $this->randomName(); $this->assertFalse(is_dir($directory), 'Directory does not exist prior to testing.'); // Non-existent directory. @@ -51,15 +52,15 @@ function testFileCheckDirectoryHandling() { } // Test that the directory has the correct permissions. - $this->assertDirectoryPermissions($directory, variable_get('file_chmod_directory', 0775)); + $this->assertDirectoryPermissions($directory, config('system.file')->get('chmod.directory')); // Remove .htaccess file to then test that it gets re-created. - @drupal_unlink(file_default_scheme() . '://.htaccess'); - $this->assertFalse(is_file(file_default_scheme() . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File'); + @drupal_unlink($default_scheme . '://.htaccess'); + @drupal_unlink($default_scheme . '://.htaccess');$this->assertFalse(is_file($default_scheme . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File'); file_ensure_htaccess(); - $this->assertTrue(is_file(file_default_scheme() . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File'); + $this->assertTrue(is_file($default_scheme . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File'); // Verify contents of .htaccess file. - $file = file_get_contents(file_default_scheme() . '://.htaccess'); + $file = file_get_contents($default_scheme . '://.htaccess'); $this->assertEqual($file, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks", 'The .htaccess file contains the proper content.', 'File'); } @@ -122,10 +123,10 @@ function testFileDestination() { */ function testFileDirectoryTemp() { // Start with an empty variable to ensure we have a clean slate. - variable_set('file_temporary_path', ''); + config('system.file')->set('path.temporary', ''); $tmp_directory = file_directory_temp(); $this->assertEqual(empty($tmp_directory), FALSE, 'file_directory_temp() returned a non-empty value.'); - $setting = variable_get('file_temporary_path', ''); - $this->assertEqual($setting, $tmp_directory, "The 'file_temporary_path' variable has the same value that file_directory_temp() returned."); + $setting = config('system.file')->get('path.temporary'); + $this->assertEqual($setting, $tmp_directory, "The 'path.temporary' variable has the same value that file_directory_temp() returned."); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileDirectoryTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileDirectoryTest.php index 89f9019..3434463 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileDirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileDirectoryTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileScanDirectoryTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileScanDirectoryTest.php index 279d722..4aaf805 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileScanDirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileScanDirectoryTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedCopyTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedCopyTest.php index 3f58ef4..897ab92 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedCopyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedCopyTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php index d45210e..1b0c253 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteTest.php index ea52cfe..515b6e8 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedMoveTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedMoveTest.php index c900fcf..b592401 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedMoveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedMoveTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedSaveDataTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedSaveDataTest.php index b66932b..9e77e85 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedSaveDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedSaveDataTest.php @@ -27,6 +27,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + config('system.file')->set('default_scheme', 'dummy-remote'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php index f94d7b1..a558d42 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php @@ -80,10 +80,10 @@ function testUriFunctions() { // Test file_build_uri() and // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath(). $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.'); - $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), variable_get('file_public_path'), 'Expected default directory path was returned.'); - $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), variable_get('file_temporary_path'), 'Expected temporary directory path was returned.'); + $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), config('system.file')->get('path.public'), 'Expected default directory path was returned.'); + $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), config('system.file')->get('path.temporary'), 'Expected temporary directory path was returned.'); - variable_set('file_default_scheme', 'private'); + config('system.file')->set('default_scheme', 'private')->save(); $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php index 7056946..c920baa 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php @@ -25,6 +25,7 @@ public static function getInfo() { function testNormal() { // Create a file for testing $uri = $this->createUri(); + $file_chmod_file = config('system.file')->get('chmod.file'); // Copying to a new name. $desired_filepath = 'public://' . $this->randomName(); @@ -33,7 +34,7 @@ function testNormal() { $this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($uri), 'Original file remains.'); $this->assertTrue(file_exists($new_filepath), 'New file exists.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, $file_chmod_file); // Copying with rename. $desired_filepath = 'public://' . $this->randomName(); @@ -43,7 +44,7 @@ function testNormal() { $this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($uri), 'Original file remains.'); $this->assertTrue(file_exists($newer_filepath), 'New file exists.'); - $this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($newer_filepath, $file_chmod_file); // TODO: test copying to a directory (rather than full directory/file path) // TODO: test copying normal files using normal paths (rather than only streams) @@ -66,6 +67,7 @@ function testNonExistent() { function testOverwriteSelf() { // Create a file for testing $uri = $this->createUri(); + $file_chmod_file = config('system.file')->get('chmod.file'); // Copy the file onto itself with renaming works. $new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_RENAME); @@ -73,7 +75,7 @@ function testOverwriteSelf() { $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, $file_chmod_file); // Copy the file onto itself without renaming fails. $new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_ERROR); @@ -91,6 +93,6 @@ function testOverwriteSelf() { $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, $file_chmod_file); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php index 6e0ec14..6d49900 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php @@ -25,6 +25,7 @@ public static function getInfo() { function testNormal() { // Create a file for testing $uri = $this->createUri(); + $file_chmod_file = config('system.file')->get('chmod.file'); // Moving to a new name. $desired_filepath = 'public://' . $this->randomName(); @@ -33,7 +34,7 @@ function testNormal() { $this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($new_filepath), 'File exists at the new location.'); $this->assertFalse(file_exists($uri), 'No file remains at the old location.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, $file_chmod_file); // Moving with rename. $desired_filepath = 'public://' . $this->randomName(); @@ -44,7 +45,7 @@ function testNormal() { $this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($newer_filepath), 'File exists at the new location.'); $this->assertFalse(file_exists($new_filepath), 'No file remains at the old location.'); - $this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($newer_filepath, $file_chmod_file); // TODO: test moving to a directory (rather than full directory/file path) // TODO: test creating and moving normal files (rather than streams) diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php index cde75c7..34db18b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php @@ -36,6 +36,6 @@ function testFileSaveData() { $this->assertTrue($filepath, 'Unnamed file saved correctly.'); $this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.'); $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.'); - $this->assertFilePermissions($filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($filepath, config('system.file')->get('chmod.file')); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/FileTransfer/FileTransferTest.php b/core/modules/system/lib/Drupal/system/Tests/FileTransfer/FileTransferTest.php index e106e04..2f73f15 100644 --- a/core/modules/system/lib/Drupal/system/Tests/FileTransfer/FileTransferTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/FileTransfer/FileTransferTest.php @@ -91,7 +91,7 @@ function testJail() { $gotit = TRUE; try { - $this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/'. variable_get('file_public_path', conf_path() . '/files')); + $this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/'. config('system.file')->get('path.public')); } catch (FileTransferException $e) { $gotit = FALSE; diff --git a/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php index 6280cc4..125393f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php @@ -25,11 +25,11 @@ function setUp() { parent::setUp(); $conf['php_storage']['simpletest'] = array( 'class' => 'Drupal\Component\PhpStorage\FileStorage', - 'directory' => DRUPAL_ROOT . '/' . variable_get('file_public_path', conf_path() . '/files') . '/php', + 'directory' => DRUPAL_ROOT . '/' . config('system.file')->get('path.public') . '/php', ); $conf['php_storage']['readonly'] = array( 'class' => 'Drupal\Component\PhpStorage\FileReadOnlyStorage', - 'directory' => DRUPAL_ROOT . '/' . variable_get('file_public_path', conf_path() . '/files') . '/php', + 'directory' => DRUPAL_ROOT . '/' . config('system.file')->get('path.public') . '/php', // Let this read from the bin where the other instance is writing. 'bin' => 'simpletest', ); diff --git a/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php index a0649cb..8a3998c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php @@ -36,7 +36,7 @@ function setUp() { $this->secret = $this->randomName(); $conf['php_storage']['simpletest'] = array( 'class' => $this->storageClass, - 'directory' => DRUPAL_ROOT . '/' . variable_get('file_public_path', conf_path() . '/files') . '/php', + 'directory' => DRUPAL_ROOT . '/' . config('system.file')->get('path.public') . '/php', 'secret' => $this->secret, ); } @@ -60,7 +60,7 @@ function testSecurity() { $php = drupal_php_storage('simpletest'); $name = 'simpletest.php'; $php->save($name, 'get('path.public') . '/php/simpletest'; $expected_directory = $expected_root_directory . '/' . $name; $directory_mtime = filemtime($expected_directory); $expected_filename = $expected_directory . '/' . hash_hmac('sha256', $name, $this->secret . $directory_mtime) . '.php'; diff --git a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php index 0c7ee72..bf84532 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php @@ -45,7 +45,7 @@ function setUp() { function testThemeSettings() { // Specify a filesystem path to be used for the logo. $file = current($this->drupalGetTestFiles('image')); - $file_relative = strtr($file->uri, array('public:/' => variable_get('file_public_path', conf_path() . '/files'))); + $file_relative = strtr($file->uri, array('public:/' => config('system.file')->get('path.public'))); $default_theme_path = 'core/themes/stark'; $supported_paths = array( @@ -97,7 +97,7 @@ function testThemeSettings() { if (file_uri_scheme($input) == 'public') { $implicit_public_file = file_uri_target($input); $explicit_file = $input; - $local_file = strtr($input, array('public:/' => variable_get('file_public_path', conf_path() . '/files'))); + $local_file = strtr($input, array('public:/' => config('system.file')->get('path.public'))); } // Adjust for fully qualified stream wrapper URI elsewhere. elseif (file_uri_scheme($input) !== FALSE) { @@ -107,7 +107,7 @@ function testThemeSettings() { elseif ($input == file_uri_target($file->uri)) { $implicit_public_file = $input; $explicit_file = 'public://' . $input; - $local_file = variable_get('file_public_path', conf_path() . '/files') . '/' . $input; + $local_file = config('system.file')->get('path.public') . '/' . $input; } $this->assertEqual((string) $elements[0], $implicit_public_file); $this->assertEqual((string) $elements[1], $explicit_file); @@ -132,9 +132,9 @@ function testThemeSettings() { // Relative path within the public filesystem to non-existing file. 'whatever.png', // Relative path to non-existing file in public filesystem. - variable_get('file_public_path', conf_path() . '/files') . '/whatever.png', + config('system.file')->get('path.public') . '/whatever.png', // Semi-absolute path to non-existing file in public filesystem. - '/' . variable_get('file_public_path', conf_path() . '/files') . '/whatever.png', + '/' . config('system.file')->get('path.public') . '/whatever.png', // Relative path to arbitrary non-existing file. 'core/misc/whatever.png', // Semi-absolute path to arbitrary non-existing file. diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php index fd194ec..2484c3b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php @@ -115,9 +115,9 @@ protected function setUp() { } // Set path variables. - $this->variable_set('file_public_path', $this->public_files_directory); - $this->variable_set('file_private_path', $this->private_files_directory); - $this->variable_set('file_temporary_path', $this->temp_files_directory); + config('system.file')->set('path.public', $this->public_files_directory); + config('system.file')->set('path.private', $this->private_files_directory); + config('system.file')->set('path.temporary', $this->temp_files_directory); $this->pass('Finished loading the dump.'); diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index c55289c..2b4dcea 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -523,7 +523,7 @@ function system_theme_settings($form, &$form_state, $key = '') { // Prepare local file path for description. if ($original_path && isset($friendly_path)) { - $local_file = strtr($original_path, array('public:/' => variable_get('file_public_path', conf_path() . '/files'))); + $local_file = strtr($original_path, array('public:/' => config('system.file')->get('path.public'))); } elseif ($key) { $local_file = drupal_get_path('theme', $key) . '/' . $default; @@ -1715,11 +1715,11 @@ function system_clear_page_cache_submit($form, &$form_state) { * @ingroup forms * @see system_settings_form() */ -function system_file_system_settings() { +function system_file_system_settings($form, &$form_state) { $form['file_public_path'] = array( '#type' => 'textfield', '#title' => t('Public file system path'), - '#default_value' => variable_get('file_public_path', conf_path() . '/files'), + '#default_value' => config('system.file')->get('path.public'), '#maxlength' => 255, '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'), '#after_build' => array('system_check_directory'), @@ -1728,16 +1728,17 @@ function system_file_system_settings() { $form['file_private_path'] = array( '#type' => 'textfield', '#title' => t('Private file system path'), - '#default_value' => variable_get('file_private_path', ''), + '#default_value' => config('system.file')->get('path.private'), '#maxlength' => 255, '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. See the online handbook for more information about securing private files.', array('@handbook' => 'http://drupal.org/documentation/modules/file')), '#after_build' => array('system_check_directory'), ); + $temporary_path = config('system.file')->get('path.temporary'); $form['file_temporary_path'] = array( '#type' => 'textfield', '#title' => t('Temporary directory'), - '#default_value' => variable_get('file_temporary_path', file_directory_temp()), + '#default_value' => ($temporary_path == NULL) ? file_directory_temp() : $temporary_path, '#maxlength' => 255, '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'), '#after_build' => array('system_check_directory'), @@ -1748,17 +1749,32 @@ function system_file_system_settings() { $options[$scheme] = check_plain($info['description']); } + $default_scheme = file_default_scheme(); if (!empty($options)) { $form['file_default_scheme'] = array( '#type' => 'radios', '#title' => t('Default download method'), - '#default_value' => variable_get('file_default_scheme', isset($options['public']) ? 'public' : key($options)), + '#default_value' => isset($options[$default_scheme]) ? $default_scheme : key($options), '#options' => $options, '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'), ); } - return system_settings_form($form); + return system_config_form($form, $form_state); +} + +/** + * Submit handler for the site file handling form. + * + * @see system_file_system_settings() + */ +function system_file_system_settings_submit($form, &$form_state) { + config('system.file') + ->set('path.public', $form_state['values']['file_public_path']) + ->set('path.private', $form_state['values']['file_private_path']) + ->set('path.temporary', $form_state['values']['file_temporary_path']) + ->set('default_scheme', $form_state['values']['file_default_scheme']) + ->save(); } /** diff --git a/core/modules/system/system.install b/core/modules/system/system.install index d0deae1..28821d9 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -311,21 +311,13 @@ function system_requirements($phase) { $require_settings = ($phase != 'install'); $reset_cache = !$require_settings; $directories = array( - variable_get('file_public_path', conf_path($require_settings, $reset_cache) . '/files'), + config('system.file')->get('path.public'), // By default no private files directory is configured. For private files // to be secure the admin needs to provide a path outside the webroot. - variable_get('file_private_path', FALSE), + config('system.file')->get('path.private'), ); - // Do not check for the temporary files directory during installation - // unless it has been set in settings.php. In this case the user has - // no alternative but to fix the directory if it is not writable. - if ($phase == 'install') { - $directories[] = variable_get('file_temporary_path', FALSE); - } - else { - $directories[] = variable_get('file_temporary_path', file_directory_temp()); - } + $directories[] = config('system.file')->get('path.temporary'); // Check the config directory if it is defined in settings.php. If it isn't // defined, the installer will create a valid config directory later, but @@ -2187,6 +2179,20 @@ function system_update_8030() { )); } +/* + * Moves file system settings from variables to config. + */ +function system_update_8031() { + update_variables_to_config('system.file', array( + 'file_default_scheme' => 'default_scheme', + 'file_chmod_file' => 'chmod.file', + 'file_chmod_directory' => 'chmod.directory', + 'file_public_path' => 'path.public', + 'file_private_path' => 'path.private', + 'file_temporary_path' => 'path.temporary', + )); +} + /** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index ea3dadc..e786cb3 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1982,7 +1982,7 @@ function system_stream_wrappers() { ); // Only register the private file stream wrapper if a file path has been set. - if (variable_get('file_private_path', FALSE)) { + if (config('system.file')->get('path.private')) { $wrappers['private'] = array( 'name' => t('Private files'), 'class' => 'Drupal\Core\StreamWrapper\PrivateStream', diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 5f340e4..d1bfdef 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -117,7 +117,7 @@ protected function preSave(EntityInterface $entity) { // and make it permanent. if (!$picture->status) { $info = image_get_info($picture->uri); - $picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); + $picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); // Prepare the pictures directory. file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY); diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index 396f4c0..91d9785 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -359,7 +359,7 @@ function user_admin_settings($form, &$form_state) { ); // If picture support is enabled, check whether the picture directory exists. if (variable_get('user_pictures', 0)) { - $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); + $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) { form_set_error('user_picture_path', t('The directory %directory does not exist or is not writable.', array('%directory' => $picture_path))); watchdog('file system', 'The directory %directory does not exist or is not writable.', array('%directory' => $picture_path), WATCHDOG_ERROR); diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 5aa8b22..cf000a1 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -464,7 +464,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { // Check whether a test file directory was setup already. // @see prepareEnvironment() - $public_files = variable_get('file_public_path', conf_path() . '/files'); + $public_files = config('system.file')->get('path.public'); $test_directory = $public_files . '/simpletest/' . substr($db_prefix, 10); if (is_dir($test_directory)) { // Output the error_log.