diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 663d53b..5209ed3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3493,6 +3493,19 @@ function drupal_check_memory_limit($required, $memory_limit = NULL) { } /** + * Returns the public path directory + */ +function file_public_path() { + if ($test_prefix = drupal_valid_test_ua()) { + // @see Drupal\simpletest\WebTestBase::setUp() + return conf_path() . '/files/simpletest/' . substr($test_prefix, 10); + } + else { + return settings()->get('file_public_path', conf_path() . '/files'); + } +} + +/** * @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 ca18a2b..4684b97 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1874,7 +1874,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 956eafd..158a1c0 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -258,25 +258,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 da6a65f..d69c753 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -674,7 +674,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"); @@ -854,7 +854,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 = file_public_path(); $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 138bf34..e59bb1e 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -416,7 +416,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; @@ -802,7 +802,7 @@ protected function setUp() { NestedArray::setValue($GLOBALS['conf'], array_merge(array($config_base), explode('.', $name)), $value); } } - $GLOBALS['conf']['file_public_path'] = $this->public_files_directory; + $this->settingsSet('file_public_path', $this->public_files_directory); // Execute the non-interactive installer. require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; install_drupal($settings); @@ -850,7 +850,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. variable_set('mail_system', array('default-system' => 'Drupal\Core\Mail\VariableLog')); 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 e106e04..8fc0130 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 8cf14d5..fa768c0 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 6583d57..9792ab1 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -530,7 +530,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; @@ -1752,11 +1752,11 @@ function system_clear_page_cache_submit($form, &$form_state) { function system_file_system_settings() { $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'), + '#markup' => file_public_path(), '#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.'), + '#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'), '#after_build' => array('system_check_directory'), ); @@ -1806,8 +1806,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 cfc9a4e..271dff1 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 3609bd7..d9d8f7b 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -363,7 +363,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; @@ -487,7 +487,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.