Loading core/lib/Drupal/Core/Asset/AssetDumper.php +1 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public function dump($data, $file_extension) { // generating a file that won't be used. if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) { try { if (!file_exists($uri . '.gz') && !$this->getFileSystem()->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) { if (!file_exists($uri . '.gz') && !$this->getFileSystem()->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FileSystemInterface::EXISTS_REPLACE)) { return FALSE; } } Loading core/lib/Drupal/Core/File/FileSystem.php +4 −4 Original line number Diff line number Diff line Loading @@ -446,10 +446,10 @@ public function move($source, $destination, $replace = self::EXISTS_RENAME) { * default scheme (file://) will be used. * @param int $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. * * @see \Drupal\Core\File\FileSystemInterface::copy() * @see \Drupal\Core\File\FileSystemInterface::move() Loading core/lib/Drupal/Core/File/FileSystemInterface.php +16 −14 Original line number Diff line number Diff line Loading @@ -281,8 +281,10 @@ public function validScheme($scheme); * - If file already exists in $destination either the call will error out, * replace the file or rename the file based on the $replace parameter. * - If the $source and $destination are equal, the behavior depends on the * $replace parameter. FILE_EXISTS_REPLACE will error out. * FILE_EXISTS_RENAME will rename the file until the $destination is unique. * $replace parameter. FileSystemInterface::EXISTS_REPLACE will replace the * existing file. FileSystemInterface::EXISTS_ERROR will error out. * FileSystemInterface::EXISTS_RENAME will rename the file until the * $destination is unique. * - Provides a fallback using realpaths if the move fails using stream * wrappers. This can occur because PHP's copy() function does not properly * support streams if open_basedir is enabled. See Loading @@ -295,10 +297,10 @@ public function validScheme($scheme); * URI may be a bare filepath (without a scheme). * @param int $replace * Replace behavior when the destination file already exists: * - FileManagerInterface::FILE_EXISTS_REPLACE - Replace the existing file. * - FileManagerInterface::FILE_EXISTS_RENAME - Append _{incrementing * number} until the filename is unique. * - FileManagerInterface::FILE_EXISTS_ERROR - Throw an exception. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Throw an exception. * * @return string * The path to the new file. Loading Loading @@ -367,10 +369,10 @@ public function deleteRecursive($path, callable $callback = NULL); * default scheme (public://) will be used. * @param int $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. * * @return string * The path to the new file. Loading @@ -396,10 +398,10 @@ public function move($source, $destination, $replace = self::EXISTS_RENAME); * wrapper URI. * @param int $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. * * @return string * A string with the path of the resulting file, or FALSE on error. Loading core/modules/file/file.module +44 −40 Original line number Diff line number Diff line Loading @@ -129,8 +129,9 @@ function file_load($fid, $reset = FALSE) { * - If file already exists in $destination either the call will error out, * replace the file or rename the file based on the $replace parameter. * - If the $source and $destination are equal, the behavior depends on the * $replace parameter. FILE_EXISTS_REPLACE will error out. FILE_EXISTS_RENAME * will rename the file until the $destination is unique. * $replace parameter. FileSystemInterface::EXISTS_REPLACE will error out. * FileSystemInterface::EXISTS_RENAME will rename the file until the * $destination is unique. * - Adds the new file to the files database. If the source file is a * temporary file, the resulting file will also be a temporary file. See * file_save_upload() for details on temporary files. Loading @@ -143,12 +144,13 @@ function file_load($fid, $reset = FALSE) { * @param int $replace * (optional) Replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. If a managed file with * the destination name exists, then its database entry will be updated. If * no database entry is found, then a new one will be created. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. If a * managed file with the destination name exists, then its database entry * will be updated. If no database entry is found, then a new one will be * created. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return \Drupal\file\FileInterface|false * File entity if the copy is successful, or FALSE in the event of an error. Loading @@ -156,7 +158,7 @@ function file_load($fid, $reset = FALSE) { * @see file_unmanaged_copy() * @see hook_file_copy() */ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { function file_copy(FileInterface $source, $destination = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ Loading @@ -181,7 +183,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E // If we are replacing an existing file re-use its database record. // @todo Do not create a new entity in order to update it. See // https://www.drupal.org/node/2241865. if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) { $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); if (count($existing_files)) { $existing = reset($existing_files); Loading @@ -192,7 +194,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E } // If we are renaming around an existing file (rather than a directory), // use its basename for the filename. elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) { elseif ($replace == FileSystemInterface::EXISTS_RENAME && is_file($destination)) { $file->setFilename($file_system->basename($destination)); } Loading Loading @@ -225,13 +227,14 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. If a managed file with * the destination name exists then its database entry will be updated and * $source->delete() called after invoking hook_file_move(). If no database * entry is found, then the source files record will be updated. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. If a * managed file with the destination name exists then its database entry * will be updated and $source->delete() called after invoking * hook_file_move(). If no database entry is found, then the source files * record will be updated. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return \Drupal\file\FileInterface|false * Resulting file entity for success, or FALSE in the event of an error. Loading @@ -239,7 +242,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E * @see \Drupal\Core\File\FileSystemInterface::move() * @see hook_file_move() */ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { function file_move(FileInterface $source, $destination = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ Loading @@ -263,7 +266,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E $file = clone $source; $file->setFileUri($uri); // If we are replacing an existing file re-use its database record. if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) { $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); if (count($existing_files)) { $existing = reset($existing_files); Loading @@ -274,7 +277,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E } // If we are renaming around an existing file (rather than a directory), // use its basename for the filename. elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) { elseif ($replace == FileSystemInterface::EXISTS_RENAME && is_file($destination)) { $file->setFilename(\Drupal::service('file_system')->basename($destination)); } Loading Loading @@ -551,19 +554,20 @@ function file_validate_image_resolution(FileInterface $file, $maximum_dimensions * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. If a managed file with * the destination name exists, then its database entry will be updated. If * no database entry is found, then a new one will be created. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. If a * managed file with the destination name exists, then its database entry * will be updated. If no database entry is found, then a new one will be * created. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return \Drupal\file\FileInterface|false * A file entity, or FALSE on error. * * @see file_unmanaged_save_data() */ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) { function file_save_data($data, $destination = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { $user = \Drupal::currentUser(); if (empty($destination)) { Loading @@ -589,7 +593,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM // If we are replacing an existing file re-use its database record. // @todo Do not create a new entity in order to update it. See // https://www.drupal.org/node/2241865. if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) { $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); if (count($existing_files)) { $existing = reset($existing_files); Loading @@ -600,7 +604,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM } // If we are renaming around an existing file (rather than a directory), // use its basename for the filename. elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) { elseif ($replace == FileSystemInterface::EXISTS_RENAME && is_file($destination)) { $file->setFilename(\Drupal::service('file_system')->basename($destination)); } Loading Loading @@ -778,10 +782,10 @@ function file_cron() { * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return array|\Drupal\file\FileInterface|null|false * An array of file entities or a single file entity if $delta != NULL. Each Loading @@ -797,7 +801,7 @@ function file_cron() { * @see https://www.drupal.org/project/drupal/issues/3069020 * @see https://www.drupal.org/project/drupal/issues/2482783 */ function _file_save_upload_from_form(array $element, FormStateInterface $form_state, $delta = NULL, $replace = FILE_EXISTS_RENAME) { function _file_save_upload_from_form(array $element, FormStateInterface $form_state, $delta = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { // Get all errors set before calling this method. This will also clear them // from $_SESSION. $errors_before = \Drupal::messenger()->deleteByType(MessengerInterface::TYPE_ERROR); Loading Loading @@ -877,10 +881,10 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return array|\Drupal\file\FileInterface|null|false * An array of file entities or a single file entity if $delta != NULL. Each Loading @@ -891,7 +895,7 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st * * @todo: move this logic to a service in https://www.drupal.org/node/2244513. */ function file_save_upload($form_field_name, $validators = [], $destination = FALSE, $delta = NULL, $replace = FILE_EXISTS_RENAME) { function file_save_upload($form_field_name, $validators = [], $destination = FALSE, $delta = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { static $upload_cache; $all_files = \Drupal::request()->files->get('files', []); Loading core/modules/file/src/Plugin/rest/resource/FileUploadResource.php +2 −2 Original line number Diff line number Diff line Loading @@ -265,8 +265,8 @@ public function post(Request $request, $entity_type_id, $bundle, $field_name) { $this->validate($file, $validators); // Move the file to the correct location after validation. Use // FILE_EXISTS_ERROR as the file location has already been determined above // in FileSystem::getDestinationFilename(). // FileSystemInterface::EXISTS_ERROR as the file location has already been // determined above in FileSystem::getDestinationFilename(). try { $this->fileSystem->move($temp_file_path, $file_uri, FileSystemInterface::EXISTS_ERROR); } Loading Loading
core/lib/Drupal/Core/Asset/AssetDumper.php +1 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public function dump($data, $file_extension) { // generating a file that won't be used. if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) { try { if (!file_exists($uri . '.gz') && !$this->getFileSystem()->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) { if (!file_exists($uri . '.gz') && !$this->getFileSystem()->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FileSystemInterface::EXISTS_REPLACE)) { return FALSE; } } Loading
core/lib/Drupal/Core/File/FileSystem.php +4 −4 Original line number Diff line number Diff line Loading @@ -446,10 +446,10 @@ public function move($source, $destination, $replace = self::EXISTS_RENAME) { * default scheme (file://) will be used. * @param int $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. * * @see \Drupal\Core\File\FileSystemInterface::copy() * @see \Drupal\Core\File\FileSystemInterface::move() Loading
core/lib/Drupal/Core/File/FileSystemInterface.php +16 −14 Original line number Diff line number Diff line Loading @@ -281,8 +281,10 @@ public function validScheme($scheme); * - If file already exists in $destination either the call will error out, * replace the file or rename the file based on the $replace parameter. * - If the $source and $destination are equal, the behavior depends on the * $replace parameter. FILE_EXISTS_REPLACE will error out. * FILE_EXISTS_RENAME will rename the file until the $destination is unique. * $replace parameter. FileSystemInterface::EXISTS_REPLACE will replace the * existing file. FileSystemInterface::EXISTS_ERROR will error out. * FileSystemInterface::EXISTS_RENAME will rename the file until the * $destination is unique. * - Provides a fallback using realpaths if the move fails using stream * wrappers. This can occur because PHP's copy() function does not properly * support streams if open_basedir is enabled. See Loading @@ -295,10 +297,10 @@ public function validScheme($scheme); * URI may be a bare filepath (without a scheme). * @param int $replace * Replace behavior when the destination file already exists: * - FileManagerInterface::FILE_EXISTS_REPLACE - Replace the existing file. * - FileManagerInterface::FILE_EXISTS_RENAME - Append _{incrementing * number} until the filename is unique. * - FileManagerInterface::FILE_EXISTS_ERROR - Throw an exception. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Throw an exception. * * @return string * The path to the new file. Loading Loading @@ -367,10 +369,10 @@ public function deleteRecursive($path, callable $callback = NULL); * default scheme (public://) will be used. * @param int $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. * * @return string * The path to the new file. Loading @@ -396,10 +398,10 @@ public function move($source, $destination, $replace = self::EXISTS_RENAME); * wrapper URI. * @param int $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} * until the filename is unique. * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. * * @return string * A string with the path of the resulting file, or FALSE on error. Loading
core/modules/file/file.module +44 −40 Original line number Diff line number Diff line Loading @@ -129,8 +129,9 @@ function file_load($fid, $reset = FALSE) { * - If file already exists in $destination either the call will error out, * replace the file or rename the file based on the $replace parameter. * - If the $source and $destination are equal, the behavior depends on the * $replace parameter. FILE_EXISTS_REPLACE will error out. FILE_EXISTS_RENAME * will rename the file until the $destination is unique. * $replace parameter. FileSystemInterface::EXISTS_REPLACE will error out. * FileSystemInterface::EXISTS_RENAME will rename the file until the * $destination is unique. * - Adds the new file to the files database. If the source file is a * temporary file, the resulting file will also be a temporary file. See * file_save_upload() for details on temporary files. Loading @@ -143,12 +144,13 @@ function file_load($fid, $reset = FALSE) { * @param int $replace * (optional) Replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. If a managed file with * the destination name exists, then its database entry will be updated. If * no database entry is found, then a new one will be created. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. If a * managed file with the destination name exists, then its database entry * will be updated. If no database entry is found, then a new one will be * created. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return \Drupal\file\FileInterface|false * File entity if the copy is successful, or FALSE in the event of an error. Loading @@ -156,7 +158,7 @@ function file_load($fid, $reset = FALSE) { * @see file_unmanaged_copy() * @see hook_file_copy() */ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { function file_copy(FileInterface $source, $destination = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ Loading @@ -181,7 +183,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E // If we are replacing an existing file re-use its database record. // @todo Do not create a new entity in order to update it. See // https://www.drupal.org/node/2241865. if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) { $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); if (count($existing_files)) { $existing = reset($existing_files); Loading @@ -192,7 +194,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E } // If we are renaming around an existing file (rather than a directory), // use its basename for the filename. elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) { elseif ($replace == FileSystemInterface::EXISTS_RENAME && is_file($destination)) { $file->setFilename($file_system->basename($destination)); } Loading Loading @@ -225,13 +227,14 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. If a managed file with * the destination name exists then its database entry will be updated and * $source->delete() called after invoking hook_file_move(). If no database * entry is found, then the source files record will be updated. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. If a * managed file with the destination name exists then its database entry * will be updated and $source->delete() called after invoking * hook_file_move(). If no database entry is found, then the source files * record will be updated. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return \Drupal\file\FileInterface|false * Resulting file entity for success, or FALSE in the event of an error. Loading @@ -239,7 +242,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E * @see \Drupal\Core\File\FileSystemInterface::move() * @see hook_file_move() */ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { function file_move(FileInterface $source, $destination = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ Loading @@ -263,7 +266,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E $file = clone $source; $file->setFileUri($uri); // If we are replacing an existing file re-use its database record. if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) { $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); if (count($existing_files)) { $existing = reset($existing_files); Loading @@ -274,7 +277,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E } // If we are renaming around an existing file (rather than a directory), // use its basename for the filename. elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) { elseif ($replace == FileSystemInterface::EXISTS_RENAME && is_file($destination)) { $file->setFilename(\Drupal::service('file_system')->basename($destination)); } Loading Loading @@ -551,19 +554,20 @@ function file_validate_image_resolution(FileInterface $file, $maximum_dimensions * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. If a managed file with * the destination name exists, then its database entry will be updated. If * no database entry is found, then a new one will be created. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. If a * managed file with the destination name exists, then its database entry * will be updated. If no database entry is found, then a new one will be * created. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return \Drupal\file\FileInterface|false * A file entity, or FALSE on error. * * @see file_unmanaged_save_data() */ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) { function file_save_data($data, $destination = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { $user = \Drupal::currentUser(); if (empty($destination)) { Loading @@ -589,7 +593,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM // If we are replacing an existing file re-use its database record. // @todo Do not create a new entity in order to update it. See // https://www.drupal.org/node/2241865. if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) { $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); if (count($existing_files)) { $existing = reset($existing_files); Loading @@ -600,7 +604,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM } // If we are renaming around an existing file (rather than a directory), // use its basename for the filename. elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) { elseif ($replace == FileSystemInterface::EXISTS_RENAME && is_file($destination)) { $file->setFilename(\Drupal::service('file_system')->basename($destination)); } Loading Loading @@ -778,10 +782,10 @@ function file_cron() { * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return array|\Drupal\file\FileInterface|null|false * An array of file entities or a single file entity if $delta != NULL. Each Loading @@ -797,7 +801,7 @@ function file_cron() { * @see https://www.drupal.org/project/drupal/issues/3069020 * @see https://www.drupal.org/project/drupal/issues/2482783 */ function _file_save_upload_from_form(array $element, FormStateInterface $form_state, $delta = NULL, $replace = FILE_EXISTS_RENAME) { function _file_save_upload_from_form(array $element, FormStateInterface $form_state, $delta = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { // Get all errors set before calling this method. This will also clear them // from $_SESSION. $errors_before = \Drupal::messenger()->deleteByType(MessengerInterface::TYPE_ERROR); Loading Loading @@ -877,10 +881,10 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st * @param int $replace * (optional) The replace behavior when the destination file already exists. * Possible values include: * - FILE_EXISTS_REPLACE: Replace the existing file. * - FILE_EXISTS_RENAME: (default) Append _{incrementing number} until the * filename is unique. * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * - FileSystemInterface::EXISTS_REPLACE: Replace the existing file. * - FileSystemInterface::EXISTS_RENAME: (default) Append * _{incrementing number} until the filename is unique. * - FileSystemInterface::EXISTS_ERROR: Do nothing and return FALSE. * * @return array|\Drupal\file\FileInterface|null|false * An array of file entities or a single file entity if $delta != NULL. Each Loading @@ -891,7 +895,7 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st * * @todo: move this logic to a service in https://www.drupal.org/node/2244513. */ function file_save_upload($form_field_name, $validators = [], $destination = FALSE, $delta = NULL, $replace = FILE_EXISTS_RENAME) { function file_save_upload($form_field_name, $validators = [], $destination = FALSE, $delta = NULL, $replace = FileSystemInterface::EXISTS_RENAME) { static $upload_cache; $all_files = \Drupal::request()->files->get('files', []); Loading
core/modules/file/src/Plugin/rest/resource/FileUploadResource.php +2 −2 Original line number Diff line number Diff line Loading @@ -265,8 +265,8 @@ public function post(Request $request, $entity_type_id, $bundle, $field_name) { $this->validate($file, $validators); // Move the file to the correct location after validation. Use // FILE_EXISTS_ERROR as the file location has already been determined above // in FileSystem::getDestinationFilename(). // FileSystemInterface::EXISTS_ERROR as the file location has already been // determined above in FileSystem::getDestinationFilename(). try { $this->fileSystem->move($temp_file_path, $file_uri, FileSystemInterface::EXISTS_ERROR); } Loading