diff -u b/core/includes/file.inc b/core/includes/file.inc --- b/core/includes/file.inc +++ b/core/includes/file.inc @@ -2412,38 +2412,17 @@ } /** - * 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() { $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_system_temp(); if (empty($temporary_directory)) { // If no directory has been found default to 'files/tmp'. $temporary_directory = $config->get('path.public') . '/tmp'; @@ -2462,6 +2441,39 @@ } /** + * Discovers a writable system-appropriate temporary directory. + * + * @return + * A sting containing path to temporary directory. + */ +function file_directory_system_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 -u b/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php b/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php --- b/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php @@ -21,7 +21,7 @@ public function getDirectoryPath() { $temporary_path = config('system.file')->get('path.temporary'); if (empty($temporary_path)) { - $temporary_path = sys_get_temp_dir(); + $temporary_path = file_directory_system_temp(); } return $temporary_path; } reverted: --- b/core/modules/aggregator/lib/Drupal/aggregator/Tests/ImportOpmlTest.php +++ a/core/modules/aggregator/lib/Drupal/aggregator/Tests/ImportOpmlTest.php @@ -53,7 +53,6 @@ 'files[upload]' => $path, 'remote' => file_create_url($path), ); - $this->verbose("alex: " . config('system.file')->get('path.temporary')); $this->drupalPost('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertRaw(t('You must either upload a file or enter a URL.'), t('Error if both fields are filled.')); diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -306,18 +306,28 @@ // Test files directories. 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(), - ); + $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(), + ); + } } - else { - // During an install we need to make assumptions about the file system - // unless overrides are provided in settings.php. + + // During an install we need to make assumptions about the file system + // unless overrides are provided in settings.php. + if ($phase == 'install') { $directories = array(); if (!empty($GLOBALS['system.file.path.public'])) { $directories[] = $GLOBALS['system.file.path.public']; @@ -335,7 +345,9 @@ $directories[] = $GLOBALS['system.file.path.temporary']; } else { - $directories[] = sys_get_temp_dir(); + // If temporary directory not overriden use an appropriate temporary for + // the system. + $directories[] = file_directory_system_temp(); } }