diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 1109452..39620c6 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3492,6 +3492,21 @@ function drupal_check_memory_limit($required, $memory_limit = NULL) { } /** + * Returns the public path directory + */ +function file_public_path() { + $base_path = settings()->get('file_public_path', conf_path() . '/files'); + if ($test_prefix = drupal_valid_test_ua()) { + // Append the testing suffix unless already given. + // @see Drupal\simpletest\WebTestBase::setUp() + if (strpos($base_path, '/simpletest/' . substr($test_prefix, 10)) === FALSE) { + return $base_path . '/simpletest/' . substr($test_prefix, 10); + } + } + return $base_path; +} + +/** * @defgroup lock Locking mechanisms * @{ * Functions to coordinate long-running operations across requests. diff --git a/core/includes/file.inc b/core/includes/file.inc index ea41955..c566bb0 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1856,7 +1856,7 @@ function file_directory_temp() { if (empty($temporary_directory)) { // If no directory has been found default to 'files/tmp'. - $temporary_directory = variable_get('file_public_path', conf_path() . '/files') . '/tmp'; + $temporary_directory = file_public_path() . '/tmp'; // Windows accepts paths with either slash (/) or backslash (\), but will // not accept a path which contains both a slash and a backslash. Since diff --git a/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php b/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php index 2952488..db29ac6 100644 --- a/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php @@ -49,8 +49,7 @@ static function get($name) { $configuration['bin'] = $name; } if (!isset($configuration['directory'])) { - $path = isset($conf['file_public_path']) ? $conf['file_public_path'] : conf_path() . '/files'; - $configuration['directory'] = DRUPAL_ROOT . "/$path/php"; + $configuration['directory'] = DRUPAL_ROOT . '/' . file_public_path() . '/php'; } return new $class($configuration); } diff --git a/core/lib/Drupal/Core/StreamWrapper/PublicStream.php b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php index 207b77a..cdbfe5b 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 file_public_path(); } /** diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php index 644781e..b71f141 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php @@ -75,7 +75,7 @@ function setUp() { function testImageSource() { global $base_url; - $public_files_path = variable_get('file_public_path', conf_path() . '/files'); + $public_files_path = file_public_path(); $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.module b/core/modules/image/image.module index 7be1abd..11b1528 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -262,25 +262,6 @@ function image_permission() { } /** - * Implements hook_form_FORM_ID_alter(). - */ -function image_form_system_file_system_settings_alter(&$form, &$form_state) { - $form['#submit'][] = 'image_system_file_system_settings_submit'; -} - -/** - * Form submission handler for system_file_system_settings(). - * - * Adds a menu rebuild after the public file path has been changed, so that the - * menu router item depending on that file path will be regenerated. - */ -function image_system_file_system_settings_submit($form, &$form_state) { - if ($form['file_public_path']['#default_value'] !== $form_state['values']['file_public_path']) { - state()->set('menu_rebuild_needed', TRUE); - } -} - -/** * Implements hook_file_download(). * * Control the access to files underneath the styles directory. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php index e5dccbd..fbd4ecb 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php @@ -188,7 +188,7 @@ private function setTranslationFiles() { state()->set('locale.test_projects_alter', TRUE); // Setup the environment. - $public_path = variable_get('file_public_path', conf_path() . '/files'); + $public_path = file_public_path(); $this->setTranslationsDirectory($public_path . '/local'); $config->set('translation.default_filename', '%project-%version.%language._po')->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 88e581c..0754196 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.module +++ b/core/modules/locale/tests/modules/locale_test/locale_test.module @@ -42,7 +42,7 @@ 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 . file_public_path() . '/remote/'; // Completely replace the project data with a set of test projects. $base_url = url(); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 35af531..29b5fe3 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -681,7 +681,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 = file_public_path() . '/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"); @@ -861,7 +861,9 @@ 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'); + // Use the original files directory to avoid nesting it within an existing + // simpletest directory if a test is executed within a test. + $this->originalFileDirectory = settings()->get('file_public_directory', conf_path() . '/files'); $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 4e7b6b1..6046069 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -410,7 +410,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, file_public_path()); } $this->generatedTestFiles = TRUE; @@ -843,7 +843,6 @@ protected function setUp() { } $config->save(); } - variable_set('file_public_path', $this->public_files_directory); // Use the test mail class instead of the default mail handler class. config('system.mail')->set('interface.default', 'Drupal\Core\Mail\VariableLog')->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/File/ConfigTest.php b/core/modules/system/lib/Drupal/system/Tests/File/ConfigTest.php index 7314365..36de9d9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/ConfigTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/ConfigTest.php @@ -37,7 +37,6 @@ function testFileConfigurationPage() { // upon form submission. $file_path = $this->public_files_directory; $fields = array( - 'file_public_path' => $file_path . '/file_config_page_test/public', 'file_private_path' => $file_path . '/file_config_page_test/private', 'file_temporary_path' => $file_path . '/file_config_page_test/temporary', 'file_default_scheme' => 'private', 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 c17dcb7..6c62464 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php @@ -82,7 +82,7 @@ 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('public')->getDirectoryPath(), file_public_path(), '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.'); $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/FileTransfer/FileTransferTest.php b/core/modules/system/lib/Drupal/system/Tests/FileTransfer/FileTransferTest.php index 080e8fd..a29ee98 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 . '/'. file_public_path()); } 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 f636849..f4a1ab7 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:/' => file_public_path())); $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:/' => file_public_path())); } // 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 = file_public_path() . '/' . $input; } $this->assertEqual((string) $elements[0], $implicit_public_file); $this->assertEqual((string) $elements[1], $explicit_file); @@ -131,9 +131,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', + file_public_path() . '/whatever.png', // Semi-absolute path to non-existing file in public filesystem. - '/' . variable_get('file_public_path', conf_path() . '/files') . '/whatever.png', + '/' . file_public_path() . '/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 5203747..0eb8cb7 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -532,7 +532,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:/' => file_public_path())); } elseif ($key) { $local_file = drupal_get_path('theme', $key) . '/' . $default; @@ -1763,12 +1763,11 @@ function system_clear_page_cache_submit($form, &$form_state) { function system_file_system_settings($form, $form_state) { $config = config('system.file'); $form['file_public_path'] = array( - '#type' => 'textfield', + '#type' => 'item', '#title' => t('Public file system path'), - '#default_value' => variable_get('file_public_path', conf_path() . '/files'), - '#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'), + '#default_value' => file_public_path(), + '#markup' => file_public_path(), + '#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. This must be changed in settings.php'), ); $form['file_private_path'] = array( @@ -1817,8 +1816,6 @@ function system_file_system_settings_submit($form, &$form_state) { $config = config('system.file') ->set('path.private', $form_state['values']['file_private_path']) ->set('path.temporary', $form_state['values']['file_temporary_path']); - variable_set('file_public_path', $form_state['values']['file_public_path']); - if(isset($form_state['values']['file_default_scheme'])) { $config->set('default_scheme', $form_state['values']['file_default_scheme']); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index a93a124..5efa1a7 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -306,7 +306,7 @@ function system_requirements($phase) { if ($phase != 'install') { $filesystem_config = config('system.file'); $directories = array( - variable_get('file_public_path', conf_path() . '/files'), + file_public_path(), // 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'), @@ -319,8 +319,8 @@ function system_requirements($phase) { if ($phase == 'install') { global $conf; $directories = array(); - if (!empty($conf['file_public_path'])) { - $directories[] = $conf['file_public_path']; + if ($file_public_path = settings()->get('file_public_path')) { + $directories[] = $file_public_path; } else { // If we are installing Drupal, the settings.php file might not exist yet diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index a736492..bb1b199 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -394,7 +394,7 @@ function simpletest_script_execute_batch($test_classes) { echo 'FATAL ' . $child['class'] . ': test runner returned a non-zero error code (' . $status['exitcode'] . ').' . "\n"; if ($args['die-on-fail']) { list($db_prefix, ) = simpletest_last_test_get($child['test_id']); - $public_files = variable_get('file_public_path', conf_path() . '/files'); + $public_files = file_public_path(); $test_directory = $public_files . '/simpletest/' . substr($db_prefix, 10); echo 'Simpletest database and files kept and test exited immediately on fail so should be reproducible if you change settings.php to use the database prefix '. $db_prefix . ' and config directories in '. $test_directory . "\n"; $args['keep-results'] = TRUE; @@ -563,7 +563,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 = file_public_path(); $test_directory = $public_files . '/simpletest/' . substr($db_prefix, 10); if (is_dir($test_directory)) { // Output the error_log. diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 7fcda31..46dcb68 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -444,6 +444,15 @@ # $settings['allow_authorize_operations'] = FALSE; /** + * Public file path: + * + * 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. + */ +# $settings['file_public_path'] = 'sites/default/files'; + +/** * Base URL (optional). * * If Drupal is generating incorrect URLs on your site, which could