diff --git a/core/includes/file.inc b/core/includes/file.inc index bcd3033..808979f 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -322,7 +322,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'); } /** @@ -528,7 +528,8 @@ 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)) { + $private_path = config('system.file')->get('path.private'); + if (!empty($private_path)) { file_save_htaccess('private://', TRUE); } file_save_htaccess('temporary://', TRUE); @@ -797,9 +798,9 @@ function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXIST * between 2 and 5 characters in length, internal to the file name, and not * included in $extensions. * - * Function behavior is also controlled by the Drupal variable - * 'allow_insecure_uploads'. If 'allow_insecure_uploads' evaluates to TRUE, no - * alterations will be made, if it evaluates to FALSE, the filename is 'munged'. + * Function behavior is also controlled by the configuration + * 'system.file:allow_insecure_uploads'. If it evaluates to TRUE, no alterations + * will be made, if it evaluates to FALSE, the filename is 'munged'. * * @param $filename * File name to modify. @@ -816,7 +817,7 @@ function file_munge_filename($filename, $extensions, $alerts = TRUE) { $original = $filename; // Allow potentially insecure uploads for very savvy users and admin - if (!variable_get('allow_insecure_uploads', 0)) { + if (!config('system.file')->get('allow_insecure_uploads')) { $whitelist = array_unique(explode(' ', trim($extensions))); // Split the filename up by periods. The first part becomes the basename @@ -1149,7 +1150,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, // rename filename.php.foo and filename.php to filename.php.foo.txt and // filename.php.txt, respectively). Don't rename if 'allow_insecure_uploads' // evaluates to TRUE. - if (!variable_get('allow_insecure_uploads', 0) && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) { + if (!config('system.file')->get('allow_insecure_uploads') && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) { $file->filemime = 'text/plain'; $file->uri .= '.txt'; $file->filename .= '.txt'; @@ -1525,13 +1526,13 @@ function file_get_mimetype($uri, $mapping = NULL) { /** * Sets the permissions on a file or directory. * - * This function will use the 'file_chmod_directory' and 'file_chmod_file' - * variables for the default modes for directories and uploaded/generated - * files. By default these will give everyone read access so that users - * accessing the files with a user account without the webserver group (e.g. - * via FTP) can read these files, and give group write permissions so webserver - * group members (e.g. a vhost account) can alter files uploaded and owned by - * the webserver. + * This function will use the system.file:chmod.directory and + * system.file:chmod.file configuration for the default modes for directories + * and uploaded/generated files. By default these will give everyone read access + * so that users accessing the files with a user account without the webserver + * group (e.g. via FTP) can read these files, and give group write permissions + * so webserver group members (e.g. a vhost account) can alter files uploaded + * and owned by the webserver. * * PHP's chmod does not support stream wrappers so we use our wrapper * implementation which interfaces with chmod() by default. Contrib wrappers @@ -1550,11 +1551,20 @@ function file_get_mimetype($uri, $mapping = NULL) { */ function drupal_chmod($uri, $mode = NULL) { if (!isset($mode)) { + // Configuration system stores default modes as strings. We use octdec() so + // that the octal permission numbers can be expressed as integers or strings + // and will be converted correctly in both cases. if (is_dir($uri)) { - $mode = variable_get('file_chmod_directory', 0775); + $mode = octdec(config('system.file')->get('chmod.directory')); + if (!$mode) { + $mode = 0775; + } } else { - $mode = variable_get('file_chmod_file', 0664); + $mode = octdec(config('system.file')->get('chmod.file')); + if (!$mode) { + $mode = 0664; + } } } @@ -1731,7 +1741,11 @@ 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); + // Configuration system stores default mode as strings. + $mode = octdec(config('system.file')->get('chmod.directory')); + if (!$mode) { + $mode = 0775; + } } if (!isset($context)) { @@ -1814,54 +1828,67 @@ function drupal_tempnam($directory, $prefix) { } /** - * Gets the path of system-appropriate temporary directory. + * Gets and sets the path of the configured temporary directory. + * + * @return + * A string containing the path to the temporary directory. */ function file_directory_temp() { - $temporary_directory = variable_get('file_temporary_path', NULL); + $config = config('system.file'); + $temporary_directory = $config->get('path.temporary'); if (empty($temporary_directory)) { - $directories = array(); - - // Has PHP been set with an upload_tmp_dir? - if (ini_get('upload_tmp_dir')) { - $directories[] = ini_get('upload_tmp_dir'); - } - - // Operating system specific dirs. - if (substr(PHP_OS, 0, 3) == 'WIN') { - $directories[] = 'c:\\windows\\temp'; - $directories[] = 'c:\\winnt\\temp'; - } - else { - $directories[] = '/tmp'; - } - // PHP may be able to find an alternative tmp directory. - $directories[] = sys_get_temp_dir(); - - foreach ($directories as $directory) { - if (is_dir($directory) && is_writable($directory)) { - $temporary_directory = $directory; - break; - } - } - + $temporary_directory = file_directory_os_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->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 - // the 'file_public_path' variable may have either format, we sanitize - // everything to use slash which is supported on all platforms. + // the 'system.file:path.public' setting may have either format, we + // sanitize 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->set('path.temporary', $temporary_directory)->save(); } return $temporary_directory; } /** + * Discovers a writable system-appropriate temporary directory. + * + * @return + * A string containing the path to the temporary directory. + */ +function file_directory_os_temp() { + $directories = array(); + + // Has PHP been set with an upload_tmp_dir? + if (ini_get('upload_tmp_dir')) { + $directories[] = ini_get('upload_tmp_dir'); + } + + // Operating system specific dirs. + if (substr(PHP_OS, 0, 3) == 'WIN') { + $directories[] = 'c:\\windows\\temp'; + $directories[] = 'c:\\winnt\\temp'; + } + else { + $directories[] = '/tmp'; + } + // PHP may be able to find an alternative tmp directory. + $directories[] = sys_get_temp_dir(); + + foreach ($directories as $directory) { + if (is_dir($directory) && is_writable($directory)) { + return $directory; + } + } + return FALSE; +} + +/** * @} End of "defgroup file". */ diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 8e0e29c..d0686d6 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1308,9 +1308,23 @@ function install_find_translations() { * @see file_scan_directory() */ function install_find_translation_files($langcode = NULL) { - $directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations'); - $files = file_scan_directory($directory, '!drupal-\d+\.\d+\.' . (!empty($langcode) ? preg_quote($langcode, '!') : '[^\.]+') . '\.po$!', array('recurse' => FALSE)); - return $files; + return file_scan_directory(install_translation_directory(), '!drupal-\d+\.\d+\.' . (!empty($langcode) ? preg_quote($langcode, '!') : '[^\.]+') . '\.po$!', array('recurse' => FALSE)); +} + +/** + * Get installation translations directory path. + * + * @return + * A string containing the installation translations directory path. + */ +function install_translation_directory() { + if (isset($GLOBALS['conf']['locale.settings']['translation.path'])) { + $directory = $GLOBALS['conf']['locale.settings']['translation.path']; + } + else { + $directory = conf_path() . '/files/translations'; + } + return $directory; } /** @@ -1348,14 +1362,12 @@ function install_select_language(&$install_state) { // is doing. if (count($files) == 1) { if ($install_state['interactive']) { - $directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations'); - drupal_set_title(st('Choose language')); if (!empty($install_state['parameters']['translate'])) { $output = '

Follow these steps to translate Drupal into your language:

'; $output .= '
    '; $output .= '
  1. Download a translation from the translation server.
  2. '; - $output .= '
  3. Place it into the following directory:
    ' . $directory . '
  4. '; + $output .= '
  5. Place it into the following directory:
    ' . install_translation_directory() . '
  6. '; $output .= '
'; $output .= '

For more information on installing Drupal in different languages, visit the drupal.org handbook page.

'; $output .= '

How should the installation continue?

'; 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 a43849d..9bb7ff8 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/file/lib/Drupal/file/Tests/SaveUploadTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php index c2adbd6..90fec9d 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php @@ -180,6 +180,7 @@ function testHandleExtension() { * Test dangerous file handling. */ function testHandleDangerousFile() { + $config = config('system.file'); // Allow the .php extension and make sure it gets renamed to .txt for // safety. Also check to make sure its MIME type was changed. $edit = array( @@ -201,7 +202,7 @@ function testHandleDangerousFile() { // Ensure dangerous files are not renamed when insecure uploads is TRUE. // Turn on insecure uploads. - variable_set('allow_insecure_uploads', 1); + $config->set('allow_insecure_uploads', 1)->save(); // Reset the hook counters. file_test_reset(); @@ -215,7 +216,7 @@ function testHandleDangerousFile() { $this->assertFileHooksCalled(array('validate', 'insert')); // Turn off insecure uploads. - variable_set('allow_insecure_uploads', 0); + $config->set('allow_insecure_uploads', 0)->save(); } /** @@ -223,7 +224,7 @@ function testHandleDangerousFile() { */ function testHandleFileMunge() { // Ensure insecure uploads are disabled for this test. - variable_set('allow_insecure_uploads', 0); + config('system.file')->set('allow_insecure_uploads', 0)->save(); $this->image = file_move($this->image, $this->image->uri . '.foo.' . $this->image_extension); // Reset the hook counters to get rid of the 'move' we just called. diff --git a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php index 0651f37..4836f09 100644 --- a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php +++ b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php @@ -16,7 +16,7 @@ */ class DummyStreamWrapper extends LocalStream { function getDirectoryPath() { - return variable_get('stream_public_path', 'sites/default/files'); + return 'sites/default/files'; } /** 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 ab5f8d5..1486a31 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 1138f18..cc7ff80 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/config/locale.settings.yml b/core/modules/locale/config/locale.settings.yml index a1c9f35..f45760e 100644 --- a/core/modules/locale/config/locale.settings.yml +++ b/core/modules/locale/config/locale.settings.yml @@ -3,3 +3,4 @@ translation: check_disabled_modules: false default_filename: '%project-%version.%language.po' default_server_pattern: 'http://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po' + path: 'public://translations' diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php index 017e2c5..47cc09e 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php @@ -60,7 +60,7 @@ function setUp() { private function setTranslationsDirectory($path) { $this->tranlations_directory = $path; file_prepare_directory($path, FILE_CREATE_DIRECTORY); - variable_set('locale_translate_file_directory', $path); + config('locale.settings')->set('translation.path', $path)->save(); } /** @@ -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/lib/Drupal/locale/TranslationsStream.php b/core/modules/locale/lib/Drupal/locale/TranslationsStream.php index 3028a32..34ef38e 100644 --- a/core/modules/locale/lib/Drupal/locale/TranslationsStream.php +++ b/core/modules/locale/lib/Drupal/locale/TranslationsStream.php @@ -20,8 +20,7 @@ class TranslationsStream extends LocalStream { * Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath() */ function getDirectoryPath() { - return variable_get('locale_translate_file_directory', - conf_path() . '/files/translations'); + return config('locale.settings')->get('translation.path'); } /** diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index d29cf6f..9b81252 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -362,7 +362,7 @@ function locale_translate_batch_import_files($options, $force = FALSE) { * An array of interface translation files. */ function locale_translate_get_interface_translation_files($langcode = NULL) { - $directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations'); + $directory = config('locale.settings')->get('translation.path'); $return = file_scan_directory($directory, '!' . (!empty($langcode) ? '\.' . preg_quote($langcode, '!') : '') . '\.po$!', array('recurse' => FALSE)); foreach ($return as $filepath => $file) { diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index efe944b..c5d1be3 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -487,7 +487,7 @@ function locale_translation_source_build($project, $langcode, $filename = NULL) 'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)), 'url' => locale_translation_build_server_pattern($source, $source->server_pattern), ); - if (variable_get('locale_translate_file_directory', conf_path() . '/files/translations')) { + if (config('locale.settings')->get('translation.path')) { $files['local'] = (object) array( 'type' => 'local', 'directory' => 'translations://', diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index f01935a..0d612b3 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -788,6 +788,17 @@ function locale_update_8014() { } /** + * Moves locale translation directory settings from variable to config. + * + * @ingroup config_upgrade + */ +function locale_update_8015() { + update_variables_to_config('locale.settings', array( + 'locale_translate_file_directory' => 'translation.path', + )); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 59c13ec..52219ad 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -693,10 +693,10 @@ function locale_translate_english() { * Add interface translation directory setting to directories configuration. */ function locale_form_system_file_system_settings_alter(&$form, $form_state) { - $form['locale_translate_file_directory'] = array( + $form['translation_path'] = array( '#type' => 'textfield', '#title' => t('Interface translations directory'), - '#default_value' => variable_get('locale_translate_file_directory', conf_path() . '/files/translations'), + '#default_value' => config('locale.settings')->get('translation.path'), '#maxlength' => 255, '#description' => t('A local file system path where interface translation files are looked for. This directory must exist.'), '#after_build' => array('system_check_directory'), @@ -719,6 +719,10 @@ function locale_system_file_system_settings_submit(&$form, $form_state) { if ($form['locale_translate_file_directory']['#default_value'] != $form_state['values']['locale_translate_file_directory']) { locale_translation_clear_status(); } + + config('locale.settings') + ->set('translation.path', $form_state['values']['translation_path']) + ->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 93cdbf2..9b4f334 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -647,7 +647,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"); @@ -826,7 +826,7 @@ protected function prepareEnvironment() { $this->originalTheme = isset($GLOBALS['theme']) ? $GLOBALS['theme'] : NULL; // 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 = isset($user) ? clone $user : NULL; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 001e521..635bc74 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -368,7 +368,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; @@ -726,9 +726,14 @@ protected function setUp() { require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; install_drupal($settings); $this->rebuildContainer(); - foreach ($variables as $name => $value) { - variable_set($name, $value); - } + 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(); + config('locale.settings') + ->set('translation.path', $this->translation_files_directory) + ->save(); // Restore the original Simpletest batch. $batch = &batch_get(); diff --git a/core/modules/system/config/system.file.yml b/core/modules/system/config/system.file.yml new file mode 100644 index 0000000..e5bac32 --- /dev/null +++ b/core/modules/system/config/system.file.yml @@ -0,0 +1,10 @@ +allow_insecure_uploads: '0' +# chmod variables should be a string in PHP Octal Notation. +chmod: + directory: '0775' + file: '0664' +default_scheme: public +path: + private: '' + public: '' + temporary: '' diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/InstallerLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/InstallerLanguageTest.php index 9960d4c..ded17c3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/InstallerLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/InstallerLanguageTest.php @@ -24,7 +24,10 @@ public static function getInfo() { function setUp() { parent::setUp(); - variable_set('locale_translate_file_directory', drupal_get_path('module', 'simpletest') . '/files/translations'); + // The database is not available during this part of install. Use global + // $conf to override the installation translations directory path. + global $conf; + $conf['locale.settings']['translation.path'] = drupal_get_path('module', 'simpletest') . '/files/translations'; } /** 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..602a576 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 @@ 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'); @@ -122,10 +122,9 @@ 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', '')->save(); $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."); + $this->assertEqual(config('system.file')->get('path.temporary'), $tmp_directory); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php b/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php index b1d5c6d..5321fe9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php @@ -81,6 +81,11 @@ function assertSameFile($file1, $file2) { * Optional message. */ function assertFilePermissions($filepath, $expected_mode, $message = NULL) { + // Configuration system stores default modes as strings. + if (is_string($expected_mode)) { + // Convert string to octal. + $expected_mode = octdec($expected_mode); + } // Clear out PHP's file stat cache to be sure we see the current value. clearstatcache(TRUE, $filepath); @@ -116,6 +121,11 @@ function assertFilePermissions($filepath, $expected_mode, $message = NULL) { * Optional message. */ function assertDirectoryPermissions($directory, $expected_mode, $message = NULL) { + // Configuration system stores default modes as strings. + if (is_string($expected_mode)) { + // Convert string to octal. + $expected_mode = octdec($expected_mode); + } // Clear out PHP's file stat cache to be sure we see the current value. clearstatcache(TRUE, $directory); diff --git a/core/modules/system/lib/Drupal/system/Tests/File/NameMungingTest.php b/core/modules/system/lib/Drupal/system/Tests/File/NameMungingTest.php index b37123c..5e2579f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/NameMungingTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/NameMungingTest.php @@ -30,7 +30,7 @@ function setUp() { */ function testMunging() { // Disable insecure uploads. - variable_set('allow_insecure_uploads', 0); + config('system.file')->set('allow_insecure_uploads', 0)->save(); $munged_name = file_munge_filename($this->name, '', TRUE); $messages = drupal_get_messages(); $this->assertTrue(in_array(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $munged_name)), $messages['status']), 'Alert properly set when a file is renamed.'); @@ -38,11 +38,11 @@ function testMunging() { } /** - * If the allow_insecure_uploads variable evaluates to true, the file should + * If the allow_insecure_uploads setting evaluates to true, the file should * come out untouched, no matter how evil the filename. */ function testMungeIgnoreInsecure() { - variable_set('allow_insecure_uploads', 1); + config('system.file')->set('allow_insecure_uploads', 1)->save(); $munged_name = file_munge_filename($this->name, ''); $this->assertIdentical($munged_name, $this->name, format_string('The original filename (%original) matches the munged filename (%munged) when insecure uploads are enabled.', array('%munged' => $munged_name, '%original' => $this->name))); } 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..557c03f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileDirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileDirectoryTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..0dccd29 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileScanDirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileScanDirectoryTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..365c8bb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedCopyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedCopyTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..6e51f6b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..46160f5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedDeleteTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..678435b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedMoveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedMoveTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..e21b9ce 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedSaveDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileUnmanagedSaveDataTest.php @@ -26,7 +26,7 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('file_default_scheme', 'dummy-remote'); + parent::setUp('file_test'); + config('system.file')->set('default_scheme', 'dummy-remote')->save(); } } 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..62787f3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php @@ -67,6 +67,8 @@ function testGetInstanceByScheme() { * Test the URI and target functions. */ function testUriFunctions() { + $config = config('system.file'); + $instance = file_stream_wrapper_get_instance_by_uri($this->scheme . '://foo'); $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.'); @@ -80,10 +82,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->get('path.public'), 'Expected default directory path was returned.'); + $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.'); - variable_set('file_default_scheme', 'private'); + $config->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..be19842 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php @@ -23,6 +23,7 @@ public static function getInfo() { * Copy a normal file. */ function testNormal() { + $config = config('system.file'); // Create a file for testing $uri = $this->createUri(); @@ -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, $config->get('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, $config->get('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) @@ -64,6 +65,7 @@ function testNonExistent() { * Copy a file onto itself. */ function testOverwriteSelf() { + $config = config('system.file'); // Create a file for testing $uri = $this->createUri(); @@ -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, $config->get('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, $config->get('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..62d3ba9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php @@ -23,6 +23,7 @@ public static function getInfo() { * Move a normal file. */ function testNormal() { + $config = config('system.file'); // Create a file for testing $uri = $this->createUri(); @@ -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, $config->get('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, $config->get('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 d1de46e..9c0bbfd 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 ae54c2f..8bd1db5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php @@ -38,7 +38,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, ); } @@ -62,7 +62,7 @@ function testSecurity() { $php = $this->storageFactory->get('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 111e6b7..d8f599a 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/system.admin.inc b/core/modules/system/system.admin.inc index 46b4b9d..7838c3d 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -524,7 +524,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; @@ -1722,13 +1722,14 @@ function system_clear_page_cache_submit($form, &$form_state) { * Form builder; Configure the site file handling. * * @ingroup forms - * @see system_settings_form() + * @see system_file_system_settings_submit() */ function system_file_system_settings() { + $config = config('system.file'); $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->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'), @@ -1737,7 +1738,7 @@ 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->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'), @@ -1746,7 +1747,7 @@ function system_file_system_settings() { $form['file_temporary_path'] = array( '#type' => 'textfield', '#title' => t('Temporary directory'), - '#default_value' => variable_get('file_temporary_path', file_directory_temp()), + '#default_value' => $config->get('path.temporary'), '#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'), @@ -1756,18 +1757,35 @@ function system_file_system_settings() { foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) { $options[$scheme] = check_plain($info['description']); } - 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' => $config->get('default_scheme'), '#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); +} + +/** + * Save configuration values for file system. + * + * @ingroup forms + * @see system_file_system_settings() + */ +function system_file_system_settings_submit($form, &$form_state) { + $config = 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']); + + if(isset($form_state['values']['file_default_scheme'])) { + $config->set('default_scheme', $form_state['values']['file_default_scheme']); + } + $config->save(); } /** diff --git a/core/modules/system/system.install b/core/modules/system/system.install index affd779..d7ced05 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -305,26 +305,42 @@ function system_requirements($phase) { } // Test files directories. - // If we are installing Drupal, the settings.php file might not exist yet in - // the intended conf_path() directory, so don't require it. The conf_path() - // cache must also be reset in this case. - $require_settings = ($phase != 'install'); - $reset_cache = !$require_settings; - $directories = array( - variable_get('file_public_path', conf_path($require_settings, $reset_cache) . '/files'), - // 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), - ); + if ($phase != 'install') { + $filesystem_config = config('system.file'); + $directories = array( + $filesystem_config->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. + $filesystem_config->get('path.private'), + file_directory_temp(), + ); + } - // 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. + // During an install we need to make assumptions about the file system + // unless overrides are provided in settings.php. if ($phase == 'install') { - $directories[] = variable_get('file_temporary_path', FALSE); - } - else { - $directories[] = variable_get('file_temporary_path', file_directory_temp()); + global $conf; + $directories = array(); + if (!empty($conf['system.file']['path.public'])) { + $directories[] = $conf['system.file']['path.public']; + } + else { + // If we are installing Drupal, the settings.php file might not exist yet + // in the intended conf_path() directory, so don't require it. The + // conf_path() cache must also be reset in this case. + $directories[] = conf_path(FALSE, TRUE) . '/files'; + } + if (!empty($conf['system.file']['path.private'])) { + $directories[] = $conf['system.file']['path.private']; + } + if (!empty($conf['system.file']['path.temporary'])) { + $directories[] = $conf['system.file']['path.temporary']; + } + else { + // If the temporary directory is not overridden use an appropriate + // temporary path for the system. + $directories[] = file_directory_os_temp(); + } } // Check the config directory if it is defined in settings.php. If it isn't @@ -515,6 +531,13 @@ function system_install() { // Populate the cron key state variable. $cron_key = drupal_hash_base64(drupal_random_bytes(55)); state()->set('system.cron_key', $cron_key); + + // Populate default for public file path. + if (empty($GLOBALS['system.file.path.public'])) { + config('system.file') + ->set('path.public', conf_path(TRUE, TRUE) . '/files') + ->save(); + } } /** @@ -2293,6 +2316,23 @@ function system_update_8038() { } /** + * Moves site system settings from variable to config. + * + * @ingroup config_upgrade + */ +function system_update_8039() { + update_variables_to_config('system.file', array( + 'allow_insecure_uploads' => 'allow_insecure_uploads', + 'file_default_scheme' => 'default_scheme', + 'file_chmod_directory' => 'chmod.directory', + 'file_chmod_file' => 'chmod.file', + '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 1492cf0..8aa98ab 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2009,7 +2009,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/scripts/run-tests.sh b/core/scripts/run-tests.sh index e728932..4340cea 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.