diff --git a/core/includes/file.inc b/core/includes/file.inc index f1c6ac9..0376855 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1554,10 +1554,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.site')->get('file_chmod_directory'); } else { - $mode = variable_get('file_chmod_file', 0664); + $mode = config('system.site')->get('file_chmod_file'); } } @@ -1734,7 +1734,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.site')->get('file_chmod_directory'); } if (!isset($context)) { diff --git a/core/modules/system/config/system.site.yml b/core/modules/system/config/system.site.yml index 010dedf..43afb5b 100644 --- a/core/modules/system/config/system.site.yml +++ b/core/modules/system/config/system.site.yml @@ -1,3 +1,5 @@ +file_chmod_directory: '0775' +file_chmod_file: '0664' name: Drupal mail: '' slogan: '' 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 878dae4..f6cbefb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php @@ -51,7 +51,7 @@ class DirectoryTest extends FileTestBase { } // Test that the directory has the correct permissions. - $this->assertDirectoryPermissions($directory, variable_get('file_chmod_directory', 0775)); + $this->assertDirectoryPermissions($directory, config('system.site')->get('file_chmod_directory')); // Remove .htaccess file to then test that it gets re-created. @drupal_unlink(file_default_scheme() . '://.htaccess'); 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 ca01900..40542a5 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 @@ class UnmanagedCopyTest extends FileTestBase { function testNormal() { // Create a file for testing $uri = $this->createUri(); + $file_chmod_file = config('system.site')->get('file_chmod_file'); // Copying to a new name. $desired_filepath = 'public://' . $this->randomName(); @@ -33,7 +34,7 @@ class UnmanagedCopyTest extends FileTestBase { $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 @@ class UnmanagedCopyTest extends FileTestBase { $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 @@ class UnmanagedCopyTest extends FileTestBase { function testOverwriteSelf() { // Create a file for testing $uri = $this->createUri(); + $file_chmod_file = config('system.site')->get('file_chmod_file'); // Copy the file onto itself with renaming works. $new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_RENAME); @@ -73,7 +75,7 @@ class UnmanagedCopyTest extends FileTestBase { $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 @@ class UnmanagedCopyTest extends FileTestBase { $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..4a356eb 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 @@ class UnmanagedMoveTest extends FileTestBase { function testNormal() { // Create a file for testing $uri = $this->createUri(); + $file_chmod_file = config('system.site')->get('file_chmod_file'); // Moving to a new name. $desired_filepath = 'public://' . $this->randomName(); @@ -33,7 +34,7 @@ class UnmanagedMoveTest extends FileTestBase { $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 @@ class UnmanagedMoveTest extends FileTestBase { $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..928102d 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 @@ class UnmanagedSaveDataTest extends FileTestBase { $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.site')->get('file_chmod_file')); } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 3790f2b..5ab14a7 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1976,6 +1976,16 @@ function system_update_8021() { } /** + * Moves file_chmod_directory and file_chmod_file from variables to config + */ +function system_update_8023() { + update_variables_to_config('system.site', array( + 'file_chmod_file' => 'file_chmod_file', + 'file_chmod_directory' => 'file_chmod_directory', + )); +} + +/** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */