diff --git a/core/includes/file.inc b/core/includes/file.inc index 133d64f..b334797 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); @@ -1126,9 +1127,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. @@ -1145,7 +1146,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 @@ -1494,7 +1495,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'; @@ -2113,13 +2114,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 @@ -2139,10 +2140,16 @@ 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'); + if (!$mode) { + $mode = 0775; + } } else { - $mode = variable_get('file_chmod_file', 0664); + $mode = config('system.file')->get('chmod.file'); + if (!$mode) { + $mode = 0664; + } } } @@ -2319,7 +2326,10 @@ 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 (!$mode) { + $mode = 0775; + } } if (!isset($context)) { @@ -2402,40 +2412,20 @@ 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 sting containing path to 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 @@ -2444,13 +2434,46 @@ function file_directory_temp() { $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 sting containing path to 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; +} + +/** * Examines a file entity and returns appropriate content headers for download. * * @param Drupal\Core\File\File $file diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 369e868..b66877b 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1210,9 +1210,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, '!install\.' . (!empty($langcode) ? preg_quote($langcode, '!') : '[^\.]+') . '\.po$!', array('recurse' => FALSE)); - return $files; + return file_scan_directory(install_translation_directory(), '!install\.' . (!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']['path.translations'])) { + $directory = $GLOBALS['conf']['locale.settings']['path.translations']; + } + else { + $directory = conf_path() . '/files/translations'; + } + return $directory; } /** @@ -1250,14 +1264,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 b331e4b..f5fb98b 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/image/image.field.inc b/core/modules/image/image.field.inc index 80b8fb8..40bbce3 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 574cc1b..e18840f 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php @@ -91,7 +91,7 @@ class ImageStylesPathAndUrlTest extends WebTestBase { // 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 new file mode 100644 index 0000000..2e3d6ac --- /dev/null +++ b/core/modules/locale/config/locale.settings.yml @@ -0,0 +1,2 @@ +path: + translations: public://translations diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php index a19351d..9db88ba 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php @@ -36,7 +36,7 @@ class LocaleFileImportStatus extends WebTestBase { $this->drupalLogin($admin_user); // Set the translation file directory. - variable_set('locale_translate_file_directory', drupal_get_path('module', 'locale') . '/tests'); + config('locale.settings')->set('path.translations', drupal_get_path('module', 'locale') . '/tests')->save(); } /** @@ -79,7 +79,7 @@ class LocaleFileImportStatus extends WebTestBase { * A file object of type stdClass. */ function mockImportedPoFile($langcode, $timestamp_difference = 0) { - $dir = variable_get('locale_translate_file_directory', drupal_get_path('module', 'locale') . '/tests'); + $dir = config('locale.settings')->get('path.translations'); $testfile_uri = $dir . '/test.' . $langcode . '.po'; $file = locale_translate_file_create($testfile_uri); @@ -191,7 +191,7 @@ class LocaleFileImportStatus extends WebTestBase { function testDeleteLanguage() { $dir = conf_path() . '/files/translations'; file_prepare_directory($dir, FILE_CREATE_DIRECTORY); - variable_set('locale_translate_file_directory', $dir); + config('locale.settings')->set('path.translations', $dir)->save(); $langcode = 'de'; $this->addLanguage($langcode); $file_uri = $dir . '/po_' . $this->randomName() . '.' . $langcode . '.po'; diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php index 589c555..e73cb80 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php @@ -37,7 +37,7 @@ class LocaleImportFunctionalTest extends WebTestBase { function setUp() { parent::setUp(); // Set the translation file directory. - variable_set('locale_translate_file_directory', drupal_get_path('module', 'locale') . '/tests'); + config('locale.settings')->set('path.translations', drupal_get_path('module', 'locale') . '/tests')->save(); $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->admin_user); diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 8a9c2fe..133f579 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -349,7 +349,7 @@ function locale_translate_batch_import_files($langcode = NULL, $finish_feedback * 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('path.translations'); return file_scan_directory($directory, '!' . (!empty($langcode) ? '\.' . preg_quote($langcode, '!') : '') . '\.po$!', array('recurse' => FALSE)); } diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index 334b401..a27f910 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -623,6 +623,17 @@ function locale_update_8010() { } /** + * Moves locale translation directory settings from variable to config. + * + * @ingroup config_upgrade + */ +function locale_update_8011() { + update_variables_to_config('locale.settings', array( + 'locale_translate_file_directory' => 'path.translations', + )); +} + +/** * @} 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 f7c22c1..380087a 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -553,10 +553,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['path_translations'] = 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('path.translations'), '#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'), @@ -565,6 +565,18 @@ function locale_form_system_file_system_settings_alter(&$form, $form_state) { if ($form['file_default_scheme']) { $form['file_default_scheme']['#weight'] = 20; } + $form['#submit'][] = 'locale_form_system_file_system_settings_submit'; +} + +/** + * Form builder submit handler; Handle submission for locale translation path. + * + * @ingroup forms + */ +function locale_form_system_file_system_settings_submit($form, &$form_state) { + config('locale.settings') + ->set('path.translations', $form_state['values']['path_translations']) + ->save(); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index f58e1de..501af24 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -530,15 +530,8 @@ abstract class TestBase { */ public function run(array $methods = array()) { $class = get_class($this); - if (variable_get('simpletest_verbose', TRUE)) { - // Initialize verbose debugging. - $this->verbose = TRUE; - $this->verboseDirectory = variable_get('file_public_path', conf_path() . '/files') . '/simpletest/verbose'; - if (file_prepare_directory($this->verboseDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->verboseDirectory . '/.htaccess')) { - file_put_contents($this->verboseDirectory . '/.htaccess', "\nExpiresActive Off\n\n"); - } - $this->verboseClassName = str_replace("\\", "_", $class); - } + simpletest_verbose(NULL, config('system.file')->get('path.public'), str_replace('\\', '_', $class)); + // HTTP auth settings (:) for the simpletest browser // when sending requests to the test site. $this->httpauth_method = variable_get('simpletest_httpauth_method', CURLAUTH_BASIC); @@ -691,7 +684,7 @@ abstract class TestBase { $this->originalConfigDirectory = $GLOBALS['config_directory_name']; // 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 = $user; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index bb2aef8..af6231f 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -313,7 +313,7 @@ abstract class WebTestBase extends TestBase { $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; @@ -617,9 +617,11 @@ abstract class WebTestBase extends TestBase { $this->preloadRegistry(); // 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(); // Set the 'simpletest_parent_profile' variable to add the parent profile's // search path to the child site's search paths. diff --git a/core/modules/system/config/system.file.yml b/core/modules/system/config/system.file.yml new file mode 100644 index 0000000..593431a --- /dev/null +++ b/core/modules/system/config/system.file.yml @@ -0,0 +1,9 @@ +allow_insecure_uploads: false +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 18d349c..c78f09b 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 @@ class InstallerLanguageTest extends WebTestBase { 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']['path.translations'] = 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 5d57bdf..6466660 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.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 @@ class DirectoryTest extends FileTestBase { */ 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, t('file_directory_temp() returned a non-empty value.')); - $setting = variable_get('file_temporary_path', ''); - $this->assertEqual($setting, $tmp_directory, t("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/NameMungingTest.php b/core/modules/system/lib/Drupal/system/Tests/File/NameMungingTest.php index 926a34a..565d7b4 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 @@ class NameMungingTest extends FileTestBase { */ function testMunging() { // Disable insecure uploads. - variable_set('allow_insecure_uploads', 0); + config('system.file')->set('allow_insecure_uploads', FALSE)->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']), t('Alert properly set when a file is renamed.')); @@ -42,7 +42,7 @@ class NameMungingTest extends FileTestBase { * come out untouched, no matter how evil the filename. */ function testMungeIgnoreInsecure() { - variable_set('allow_insecure_uploads', 1); + config('system.file')->set('allow_insecure_uploads', TRUE)->save(); $munged_name = file_munge_filename($this->name, ''); $this->assertIdentical($munged_name, $this->name, t('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 @@ class RemoteFileDirectoryTest extends DirectoryTest { } 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/RemoteFileSaveUploadTest.php b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileSaveUploadTest.php index 3e71f0a..fa86939 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileSaveUploadTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/RemoteFileSaveUploadTest.php @@ -26,7 +26,7 @@ class RemoteFileSaveUploadTest extends SaveUploadTest { } 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 @@ class RemoteFileScanDirectoryTest extends ScanDirectoryTest { } 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 @@ class RemoteFileUnmanagedCopyTest extends UnmanagedCopyTest { } 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 @@ class RemoteFileUnmanagedDeleteRecursiveTest extends UnmanagedDeleteRecursiveTes } 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 @@ class RemoteFileUnmanagedDeleteTest extends UnmanagedDeleteTest { } 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 @@ class RemoteFileUnmanagedMoveTest extends UnmanagedMoveTest { } 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 @@ class RemoteFileUnmanagedSaveDataTest extends UnmanagedSaveDataTest { } 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/SaveUploadTest.php b/core/modules/system/lib/Drupal/system/Tests/File/SaveUploadTest.php index 2cccaec..ebae00c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/SaveUploadTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/SaveUploadTest.php @@ -183,6 +183,7 @@ class SaveUploadTest extends FileHookTestBase { * 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( @@ -204,7 +205,7 @@ class SaveUploadTest extends FileHookTestBase { // 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', TRUE)->save(); // Reset the hook counters. file_test_reset(); @@ -218,7 +219,7 @@ class SaveUploadTest extends FileHookTestBase { $this->assertFileHooksCalled(array('validate', 'insert')); // Turn off insecure uploads. - variable_set('allow_insecure_uploads', 0); + $config->set('allow_insecure_uploads', 0)->save(); } /** @@ -226,7 +227,7 @@ class SaveUploadTest extends FileHookTestBase { */ function testHandleFileMunge() { // Ensure insecure uploads are disabled for this test. - variable_set('allow_insecure_uploads', 0); + config('system.file')->set('allow_insecure_uploads', FALSE)->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/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php index 0cbe2c0..ed907db 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 @@ class StreamWrapperTest extends WebTestBase { * 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), t('Got correct class type for dummy URI.')); @@ -80,10 +82,10 @@ class StreamWrapperTest extends WebTestBase { // Test file_build_uri() and // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath(). $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', t('Expected scheme was added.')); - $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), variable_get('file_public_path'), t('Expected default directory path was returned.')); - $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), variable_get('file_temporary_path'), t('Expected temporary directory path was returned.')); + $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), $config->get('path.public'), t('Expected default directory path was returned.')); + $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), t('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', t('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 5d5aa21..7641508 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 @@ class UnmanagedCopyTest extends FileTestBase { * Copy a normal file. */ function testNormal() { + $config = config('system.file'); // Create a file for testing $file = $this->createFile(); @@ -33,7 +34,7 @@ class UnmanagedCopyTest extends FileTestBase { $this->assertEqual($new_filepath, $desired_filepath, t('Returned expected filepath.')); $this->assertTrue(file_exists($file->uri), t('Original file remains.')); $this->assertTrue(file_exists($new_filepath), t('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 @@ class UnmanagedCopyTest extends FileTestBase { $this->assertNotEqual($newer_filepath, $desired_filepath, t('Returned expected filepath.')); $this->assertTrue(file_exists($file->uri), t('Original file remains.')); $this->assertTrue(file_exists($newer_filepath), t('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 @@ class UnmanagedCopyTest extends FileTestBase { * Copy a file onto itself. */ function testOverwriteSelf() { + $config = config('system.file'); // Create a file for testing $file = $this->createFile(); @@ -73,7 +75,7 @@ class UnmanagedCopyTest extends FileTestBase { $this->assertNotEqual($new_filepath, $file->uri, t('Copied file has a new name.')); $this->assertTrue(file_exists($file->uri), t('Original file exists after copying onto itself.')); $this->assertTrue(file_exists($new_filepath), t('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($file->uri, $file->uri, FILE_EXISTS_ERROR); @@ -91,6 +93,6 @@ class UnmanagedCopyTest extends FileTestBase { $this->assertNotEqual($new_filepath, $file->uri, t('Copied file has a new name.')); $this->assertTrue(file_exists($file->uri), t('Original file exists after copying onto itself.')); $this->assertTrue(file_exists($new_filepath), t('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 4e5c8c4..f68a06e 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 @@ class UnmanagedMoveTest extends FileTestBase { * Move a normal file. */ function testNormal() { + $config = config('system.file'); // Create a file for testing $file = $this->createFile(); @@ -33,7 +34,7 @@ class UnmanagedMoveTest extends FileTestBase { $this->assertEqual($new_filepath, $desired_filepath, t('Returned expected filepath.')); $this->assertTrue(file_exists($new_filepath), t('File exists at the new location.')); $this->assertFalse(file_exists($file->uri), t('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 @@ class UnmanagedMoveTest extends FileTestBase { $this->assertNotEqual($newer_filepath, $desired_filepath, t('Returned expected filepath.')); $this->assertTrue(file_exists($newer_filepath), t('File exists at the new location.')); $this->assertFalse(file_exists($new_filepath), t('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 6494b86..695354d 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, t('Unnamed file saved correctly.')); $this->assertEqual('asdf.txt', drupal_basename($filepath), t('File was named correctly.')); $this->assertEqual($contents, file_get_contents($filepath), t('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 @@ class FileTransferTest extends WebTestBase { $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/System/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php index f1e0f22..f8279ed 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 @@ class ThemeTest extends WebTestBase { 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 @@ class ThemeTest extends WebTestBase { 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 @@ class ThemeTest extends WebTestBase { 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 @@ class ThemeTest extends WebTestBase { // 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 2e424ad..f3a6304 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -516,7 +516,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; @@ -1806,13 +1806,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'), @@ -1821,7 +1822,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'), @@ -1830,7 +1831,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'), @@ -1840,18 +1841,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 0e42214..65c8efb 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -305,26 +305,51 @@ 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') { + $config_installed = db_table_exists('config'); + if ($phase == 'update' && !$config_installed) { + // Updating from 7 to 8. + // @TODO + // Use new functions from http://drupal.org/node/1348162 to load Drupal 7 + // variables or use Drupal 7 defaults to create $directories array. + } + else { + $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 at install time - // 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 temporary directory not overriden use an appropriate temporary for + // the system. + $directories[] = file_directory_os_temp(); + } } // Check the config directory if it is defined in settings.php. If it isn't @@ -519,6 +544,13 @@ function system_install() { config('system.cron') ->set('key', $cron_key) ->save(); + + // 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(); + } } /** @@ -2045,6 +2077,23 @@ function system_update_8016() { 'maintenance_mode_message' => 'message', )); } +/** + * Moves site system settings from variable to config. + * + * @ingroup config_upgrade + */ +function system_update_8017() { + 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". diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 983c317..a439b30 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1855,7 +1855,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/system/tests/modules/file_test/lib/Drupal/file_test/DummyStreamWrapper.php b/core/modules/system/tests/modules/file_test/lib/Drupal/file_test/DummyStreamWrapper.php index 0651f37..4836f09 100644 --- a/core/modules/system/tests/modules/file_test/lib/Drupal/file_test/DummyStreamWrapper.php +++ b/core/modules/system/tests/modules/file_test/lib/Drupal/file_test/DummyStreamWrapper.php @@ -16,7 +16,7 @@ use Drupal\Core\StreamWrapper\LocalStream; */ class DummyStreamWrapper extends LocalStream { function getDirectoryPath() { - return variable_get('stream_public_path', 'sites/default/files'); + return 'sites/default/files'; } /** diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index b71ea8d..2629c1f 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -460,7 +460,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.