updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
+78 -51
View File
@@ -5,11 +5,13 @@
* API for handling file uploads and server file management.
*/
use Drupal\Component\FileSystem\FileSystem as ComponentFileSystem;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\PhpStorage\FileStorage;
use Drupal\Component\Utility\Bytes;
use Drupal\Core\File\FileSystem;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\StreamWrapper\PrivateStream;
@@ -18,6 +20,8 @@ use Drupal\Core\StreamWrapper\PrivateStream;
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::CHMOD_DIRECTORY.
*
* @see https://www.drupal.org/node/2418133
*/
const FILE_CHMOD_DIRECTORY = FileSystem::CHMOD_DIRECTORY;
@@ -26,6 +30,8 @@ const FILE_CHMOD_DIRECTORY = FileSystem::CHMOD_DIRECTORY;
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::CHMOD_FILE.
*
* @see https://www.drupal.org/node/2418133
*/
const FILE_CHMOD_FILE = FileSystem::CHMOD_FILE;
@@ -75,6 +81,8 @@ const FILE_STATUS_PERMANENT = 1;
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::uriScheme().
*
* @see https://www.drupal.org/node/2418133
*/
function file_uri_scheme($uri) {
return \Drupal::service('file_system')->uriScheme($uri);
@@ -85,6 +93,8 @@ function file_uri_scheme($uri) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::validScheme().
*
* @see https://www.drupal.org/node/2418133
*/
function file_stream_wrapper_valid_scheme($scheme) {
return \Drupal::service('file_system')->validScheme($scheme);
@@ -365,7 +375,7 @@ function file_save_htaccess($directory, $private = TRUE, $force_overwrite = FALS
return drupal_chmod($htaccess_path, 0444);
}
else {
$variables = array('%directory' => $directory, '@htaccess' => $htaccess_lines);
$variables = ['%directory' => $directory, '@htaccess' => $htaccess_lines];
\Drupal::logger('security')->error("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <pre><code>@htaccess</code></pre>", $variables);
return FALSE;
}
@@ -384,6 +394,8 @@ function file_save_htaccess($directory, $private = TRUE, $force_overwrite = FALS
*
* @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
* Use \Drupal\Component\PhpStorage\FileStorage::htaccessLines().
*
* @see https://www.drupal.org/node/2418133
*/
function file_htaccess_lines($private = TRUE) {
return FileStorage::htaccessLines($private);
@@ -454,7 +466,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
$real_destination = drupal_realpath($destination) ?: $destination;
// Perform the copy operation.
if (!@copy($real_source, $real_destination)) {
\Drupal::logger('file')->error('The specified file %file could not be copied to %destination.', array('%file' => $source, '%destination' => $destination));
\Drupal::logger('file')->error('The specified file %file could not be copied to %destination.', ['%file' => $source, '%destination' => $destination]);
return FALSE;
}
// Set the permissions on the new file.
@@ -499,12 +511,12 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E
// Assert that the source file actually exists.
if (!file_exists($source)) {
// @todo Replace drupal_set_message() calls with exceptions instead.
drupal_set_message(t('The specified file %file could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $original_source)), 'error');
drupal_set_message(t('The specified file %file could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.', ['%file' => $original_source]), 'error');
if (($realpath = drupal_realpath($original_source)) !== FALSE) {
$logger->notice('File %file (%realpath) could not be moved/copied because it does not exist.', array('%file' => $original_source, '%realpath' => $realpath));
$logger->notice('File %file (%realpath) could not be moved/copied because it does not exist.', ['%file' => $original_source, '%realpath' => $realpath]);
}
else {
$logger->notice('File %file could not be moved/copied because it does not exist.', array('%file' => $original_source));
$logger->notice('File %file could not be moved/copied because it does not exist.', ['%file' => $original_source]);
}
return FALSE;
}
@@ -525,8 +537,8 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E
$dirname = drupal_dirname($destination);
if (!file_prepare_directory($dirname)) {
// The destination is not valid.
$logger->notice('File %file could not be moved/copied because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname));
drupal_set_message(t('The specified file %file could not be moved/copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', array('%file' => $original_source)), 'error');
$logger->notice('File %file could not be moved/copied because the destination directory %destination is not configured correctly.', ['%file' => $original_source, '%destination' => $dirname]);
drupal_set_message(t('The specified file %file could not be moved/copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', ['%file' => $original_source]), 'error');
return FALSE;
}
}
@@ -534,8 +546,8 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E
// Determine whether we can perform this operation based on overwrite rules.
$destination = file_destination($destination, $replace);
if ($destination === FALSE) {
drupal_set_message(t('The file %file could not be moved/copied because a file by that name already exists in the destination directory.', array('%file' => $original_source)), 'error');
$logger->notice('File %file could not be moved/copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $original_source, '%destination' => $destination));
drupal_set_message(t('The file %file could not be moved/copied because a file by that name already exists in the destination directory.', ['%file' => $original_source]), 'error');
$logger->notice('File %file could not be moved/copied because a file by that name already exists in the destination directory (%destination)', ['%file' => $original_source, '%destination' => $destination]);
return FALSE;
}
@@ -543,8 +555,8 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E
$real_source = drupal_realpath($source);
$real_destination = drupal_realpath($destination);
if ($source == $destination || ($real_source !== FALSE) && ($real_source == $real_destination)) {
drupal_set_message(t('The specified file %file was not moved/copied because it would overwrite itself.', array('%file' => $source)), 'error');
$logger->notice('File %file could not be moved/copied because it would overwrite itself.', array('%file' => $source));
drupal_set_message(t('The specified file %file was not moved/copied because it would overwrite itself.', ['%file' => $source]), 'error');
$logger->notice('File %file could not be moved/copied because it would overwrite itself.', ['%file' => $source]);
return FALSE;
}
// Make sure the .htaccess files are present.
@@ -650,7 +662,7 @@ function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXIST
// implemented. It's not necessary to use drupal_unlink() as the Windows
// issue has already been resolved above.
if (!@copy($real_source, $real_destination) || !@unlink($real_source)) {
\Drupal::logger('file')->error('The specified file %file could not be moved to %destination.', array('%file' => $source, '%destination' => $destination));
\Drupal::logger('file')->error('The specified file %file could not be moved to %destination.', ['%file' => $source, '%destination' => $destination]);
return FALSE;
}
}
@@ -719,7 +731,7 @@ function file_munge_filename($filename, $extensions, $alerts = TRUE) {
$filename = $new_filename . '.' . $final_extension;
if ($alerts && $original != $filename) {
drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $filename)));
drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $filename]));
}
}
@@ -760,7 +772,7 @@ function file_create_filename($basename, $directory) {
$basename = preg_replace('/[\x00-\x1F]/u', '_', $basename);
if (substr(PHP_OS, 0, 3) == 'WIN') {
// These characters are not allowed in Windows filenames
$basename = str_replace(array(':', '*', '?', '"', '<', '>', '|'), '_', $basename);
$basename = str_replace([':', '*', '?', '"', '<', '>', '|'], '_', $basename);
}
// A URI or path may already have a trailing slash or look like "public://".
@@ -808,7 +820,7 @@ function file_create_filename($basename, $directory) {
* @see \Drupal\file\FileUsage\FileUsageBase::delete()
*/
function file_delete($fid) {
return file_delete_multiple(array($fid));
return file_delete_multiple([$fid]);
}
/**
@@ -850,18 +862,18 @@ function file_unmanaged_delete($path) {
}
$logger = \Drupal::logger('file');
if (is_dir($path)) {
$logger->error('%path is a directory and cannot be removed using file_unmanaged_delete().', array('%path' => $path));
$logger->error('%path is a directory and cannot be removed using file_unmanaged_delete().', ['%path' => $path]);
return FALSE;
}
// Return TRUE for non-existent file, but log that nothing was actually
// deleted, as the current state is the intended result.
if (!file_exists($path)) {
$logger->notice('The file %path was not deleted because it does not exist.', array('%path' => $path));
$logger->notice('The file %path was not deleted because it does not exist.', ['%path' => $path]);
return TRUE;
}
// We cannot handle anything other than files and directories. Log an error
// for everything else (sockets, symbolic links, etc).
$logger->error('The file %path is not of a recognized type so it was not deleted.', array('%path' => $path));
$logger->error('The file %path is not of a recognized type so it was not deleted.', ['%path' => $path]);
return FALSE;
}
@@ -917,6 +929,8 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::moveUploadedFile().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_move_uploaded_file($filename, $uri) {
return \Drupal::service('file_system')->moveUploadedFile($filename, $uri);
@@ -978,7 +992,7 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX
* @param $options
* An associative array of additional options, with the following elements:
* - 'nomask': The preg_match() regular expression for files to be excluded.
* There is no default.
* Defaults to the 'file_scan_ignore_directories' setting.
* - 'callback': The callback function to call for each match. There is no
* default callback.
* - 'recurse': When TRUE, the directory scan will recurse the entire tree
@@ -997,29 +1011,44 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX
* An associative array (keyed on the chosen key) of objects with 'uri',
* 'filename', and 'name' properties corresponding to the matched files.
*/
function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
function file_scan_directory($dir, $mask, $options = [], $depth = 0) {
// Merge in defaults.
$options += array(
$options += [
'callback' => 0,
'recurse' => TRUE,
'key' => 'uri',
'min_depth' => 0,
);
];
// Normalize $dir only once.
if ($depth == 0) {
$dir = file_stream_wrapper_uri_normalize($dir);
$dir_has_slash = (substr($dir, -1) === '/');
}
$options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri';
$files = array();
// Allow directories specified in settings.php to be ignored. You can use this
// to not check for files in common special-purpose directories. For example,
// node_modules and bower_components. Ignoring irrelevant directories is a
// performance boost.
if (!isset($options['nomask'])) {
$ignore_directories = Settings::get('file_scan_ignore_directories', []);
array_walk($ignore_directories, function(&$value) {
$value = preg_quote($value, '/');
});
$default_nomask = '/^' . implode('|', $ignore_directories) . '$/';
}
$options['key'] = in_array($options['key'], ['uri', 'filename', 'name']) ? $options['key'] : 'uri';
$files = [];
// Avoid warnings when opendir does not have the permissions to open a
// directory.
if (is_dir($dir)) {
if ($handle = @opendir($dir)) {
while (FALSE !== ($filename = readdir($handle))) {
// Skip this file if it matches the nomask or starts with a dot.
if ($filename[0] != '.' && !(isset($options['nomask']) && preg_match($options['nomask'], $filename))) {
if ($filename[0] != '.'
&& !(isset($options['nomask']) && preg_match($options['nomask'], $filename))
&& !(!empty($default_nomask) && preg_match($default_nomask, $filename))
) {
if ($depth == 0 && $dir_has_slash) {
$uri = "$dir$filename";
}
@@ -1050,7 +1079,7 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
closedir($handle);
}
else {
\Drupal::logger('file')->error('@dir can not be opened', array('@dir' => $dir));
\Drupal::logger('file')->error('@dir can not be opened', ['@dir' => $dir]);
}
}
@@ -1086,6 +1115,8 @@ function file_upload_max_size() {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::chmod().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_chmod($uri, $mode = NULL) {
return \Drupal::service('file_system')->chmod($uri, $mode);
@@ -1096,6 +1127,8 @@ function drupal_chmod($uri, $mode = NULL) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::unlink().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_unlink($uri, $context = NULL) {
return \Drupal::service('file_system')->unlink($uri, $context);
@@ -1106,6 +1139,8 @@ function drupal_unlink($uri, $context = NULL) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::realpath().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_realpath($uri) {
return \Drupal::service('file_system')->realpath($uri);
@@ -1116,6 +1151,8 @@ function drupal_realpath($uri) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::dirname().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_dirname($uri) {
return \Drupal::service('file_system')->dirname($uri);
@@ -1126,6 +1163,8 @@ function drupal_dirname($uri) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::basename().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_basename($uri, $suffix = NULL) {
return \Drupal::service('file_system')->basename($uri, $suffix);
@@ -1137,6 +1176,8 @@ function drupal_basename($uri, $suffix = NULL) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::mkdir().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
return \Drupal::service('file_system')->mkdir($uri, $mode, $recursive, $context);
@@ -1147,6 +1188,8 @@ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::rmdir().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_rmdir($uri, $context = NULL) {
return \Drupal::service('file_system')->rmdir($uri, $context);
@@ -1157,6 +1200,8 @@ function drupal_rmdir($uri, $context = NULL) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\File\FileSystem::tempnam().
*
* @see https://www.drupal.org/node/2418133
*/
function drupal_tempnam($directory, $prefix) {
return \Drupal::service('file_system')->tempnam($directory, $prefix);
@@ -1173,7 +1218,7 @@ function file_directory_temp() {
if (empty($temporary_directory)) {
// Needs set up.
$config = \Drupal::configFactory()->getEditable('system.file');
$temporary_directory = file_directory_os_temp();
$temporary_directory = ComponentFileSystem::getOsTemporaryDirectory();
if (empty($temporary_directory)) {
// If no directory has been found default to 'files/tmp'.
@@ -1198,32 +1243,14 @@ function file_directory_temp() {
*
* @return mixed
* A string containing the path to the temporary directory.
*
* @deprecated in Drupal 8.3.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal\Component\FileSystem\FileSystem::getOsTemporaryDirectory().
*
* @see https://www.drupal.org/node/2418133
*/
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;
return ComponentFileSystem::getOsTemporaryDirectory();
}
/**