Commit 9aa7d13c authored by alexpott's avatar alexpott

Issue #3023015 by Berdir, kim.pepper, tinko, mikelutz: Replace usages of...

Issue #3023015 by Berdir, kim.pepper, tinko, mikelutz: Replace usages of deprecated constants in file.inc
parent f31214d7
......@@ -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;
}
}
......
......@@ -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()
......
......@@ -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
......@@ -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.
......@@ -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.
......@@ -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.
......
This diff is collapsed.
......@@ -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);
}
......
......@@ -77,7 +77,7 @@ protected function setUp() {
$file_system = \Drupal::service('file_system');
// Upload with replace to guarantee there's something there.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
......@@ -153,7 +153,7 @@ public function testHandleExtension() {
// _file_save_upload_from_form() to only allow ".foo".
$extensions = 'foo';
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -173,7 +173,7 @@ public function testHandleExtension() {
$extensions = 'foo ' . $this->imageExtension;
// Now tell _file_save_upload_from_form() to allow the extension of our test image.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -191,7 +191,7 @@ public function testHandleExtension() {
// Now tell _file_save_upload_from_form() to allow any extension.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
'allow_all_extensions' => TRUE,
];
......@@ -214,7 +214,7 @@ public function testHandleDangerousFile() {
// Allow the .php extension and make sure it gets renamed to .txt for
// safety. Also check to make sure its MIME type was changed.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload][]' => $file_system->realpath($this->phpfile->uri),
'is_image_file' => FALSE,
'extensions' => 'php',
......@@ -325,7 +325,7 @@ public function testExistingReplace() {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
......@@ -343,7 +343,7 @@ public function testExistingError() {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$edit = [
'file_test_replace' => FILE_EXISTS_ERROR,
'file_test_replace' => FileSystemInterface::EXISTS_ERROR,
'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
......
......@@ -72,7 +72,7 @@ protected function setUp() {
// Upload with replace to guarantee there's something there.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
......@@ -173,7 +173,7 @@ public function testHandleExtension() {
// file_save_upload() to only allow ".foo".
$extensions = 'foo';
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -193,7 +193,7 @@ public function testHandleExtension() {
$extensions = 'foo ' . $this->imageExtension;
// Now tell file_save_upload() to allow the extension of our test image.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -211,7 +211,7 @@ public function testHandleExtension() {
// Now tell file_save_upload() to allow any extension.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'allow_all_extensions' => TRUE,
];
......@@ -232,7 +232,7 @@ public function testHandleDangerousFile() {
// Allow the .php extension and make sure it gets renamed to .txt for
// safety. Also check to make sure its MIME type was changed.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->phpfile->uri),
'is_image_file' => FALSE,
'extensions' => 'php',
......@@ -339,7 +339,7 @@ public function testExistingRename() {
*/
public function testExistingReplace() {
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'file_test_replace' => FileSystemInterface::EXISTS_REPLACE,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
......@@ -356,7 +356,7 @@ public function testExistingReplace() {
*/
public function testExistingError() {
$edit = [
'file_test_replace' => FILE_EXISTS_ERROR,
'file_test_replace' => FileSystemInterface::EXISTS_ERROR,
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\file\Kernel;
use Drupal\Core\File\FileSystemInterface;
use Drupal\file\Entity\File;
/**
......@@ -21,7 +22,7 @@ public function testNormal() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_copy(clone $source, $desired_uri, FILE_EXISTS_ERROR);
$result = file_copy(clone $source, $desired_uri, FileSystemInterface::EXISTS_ERROR);
// Check the return status and that the contents changed.
$this->assertTrue($result, 'File copied successfully.');
......@@ -52,7 +53,7 @@ public function testExistingRename() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_copy(clone $source, $target->getFileUri(), FILE_EXISTS_RENAME);
$result = file_copy(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_RENAME);
// Check the return status and that the contents changed.
$this->assertTrue($result, 'File copied successfully.');
......@@ -92,7 +93,7 @@ public function testExistingReplace() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_copy(clone $source, $target->getFileUri(), FILE_EXISTS_REPLACE);
$result = file_copy(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_REPLACE);
// Check the return status and that the contents changed.
$this->assertTrue($result, 'File copied successfully.');
......@@ -119,8 +120,7 @@ public function testExistingReplace() {
}
/**
* Test that copying over an existing file fails when FILE_EXISTS_ERROR is
* specified.
* Test that copying over an existing file fails when instructed to do so.
*/
public function testExistingError() {
$contents = $this->randomMachineName(10);
......@@ -130,7 +130,7 @@ public function testExistingError() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_copy(clone $source, $target->getFileUri(), FILE_EXISTS_ERROR);
$result = file_copy(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_ERROR);
// Check the return status and that the contents were not changed.
$this->assertFalse($result, 'File copy failed.');
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\file\Kernel;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\File\FileSystemInterface;
use Drupal\file\Entity\File;
/**
......@@ -22,7 +23,7 @@ public function testNormal() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_move(clone $source, $desired_filepath, FILE_EXISTS_ERROR);
$result = file_move(clone $source, $desired_filepath, FileSystemInterface::EXISTS_ERROR);
// Check the return status and that the contents changed.
$this->assertTrue($result, 'File moved successfully.');
......@@ -54,7 +55,7 @@ public function testExistingRename() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_move(clone $source, $target->getFileUri(), FILE_EXISTS_RENAME);
$result = file_move(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_RENAME);
// Check the return status and that the contents changed.
$this->assertTrue($result, 'File moved successfully.');
......@@ -89,7 +90,7 @@ public function testExistingReplace() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_move(clone $source, $target->getFileUri(), FILE_EXISTS_REPLACE);
$result = file_move(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_REPLACE);
// Look at the results.
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of file were overwritten.');
......@@ -119,7 +120,7 @@ public function testExistingReplaceSelf() {
// Copy the file over itself. Clone the object so we don't have to worry
// about the function changing our reference copy.
$result = file_move(clone $source, $source->getFileUri(), FILE_EXISTS_REPLACE);
$result = file_move(clone $source, $source->getFileUri(), FileSystemInterface::EXISTS_REPLACE);
$this->assertFalse($result, 'File move failed.');
$this->assertEqual($contents, file_get_contents($source->getFileUri()), 'Contents of file were not altered.');
......@@ -132,8 +133,7 @@ public function testExistingReplaceSelf() {
}
/**
* Test that moving onto an existing file fails when FILE_EXISTS_ERROR is
* specified.
* Test that moving onto an existing file fails when instructed to do so.
*/
public function testExistingError() {
$contents = $this->randomMachineName(10);
......@@ -143,7 +143,7 @@ public function testExistingError() {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
$result = file_move(clone $source, $target->getFileUri(), FILE_EXISTS_ERROR);
$result = file_move(clone $source, $target->getFileUri(), FileSystemInterface::EXISTS_ERROR);
// Check the return status and that the contents did not change.
$this->assertFalse($result, 'File move failed.');
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\file\Kernel;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\file\Entity\File;
/**
......@@ -71,7 +72,7 @@ public function testExistingRename() {
$existing = $this->createFile();
$contents = $this->randomMachineName(8);
$result = file_save_data($contents, $existing->getFileUri(), FILE_EXISTS_RENAME);
$result = file_save_data($contents, $existing->getFileUri(), FileSystemInterface::EXISTS_RENAME);
$this->assertTrue($result, 'File saved successfully.');
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
......@@ -101,7 +102,7 @@ public function testExistingReplace() {
$existing = $this->createFile();
$contents = $this->randomMachineName(8);
$result = file_save_data($contents, $existing->getFileUri(), FILE_EXISTS_REPLACE);
$result = file_save_data($contents, $existing->getFileUri(), FileSystemInterface::EXISTS_REPLACE);
$this->assertTrue($result, 'File saved successfully.');
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
......@@ -130,8 +131,8 @@ public function testExistingError() {
$existing = $this->createFile(NULL, $contents);
// Check the overwrite error.
$result = file_save_data('asdf', $existing->getFileUri(), FILE_EXISTS_ERROR);
$this->assertFalse($result, 'Overwriting a file fails when FILE_EXISTS_ERROR is specified.');
$result = file_save_data('asdf', $existing->getFileUri(), FileSystemInterface::EXISTS_ERROR);
$this->assertFalse($result, 'Overwriting a file fails when FileSystemInterface::EXISTS_ERROR is specified.');
$this->assertEqual($contents, file_get_contents($existing->getFileUri()), 'Contents of existing file were unchanged.');
// Check that no hooks were called while failing.
......
......@@ -4,6 +4,7 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\File\FileSystemInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -43,7 +44,7 @@ public function testDefaultImages() {
for ($i = 1; $i <= 10; $i++) {
$filename = $this->randomMachineName() . "$i";
$desired_filepath = 'public://' . $filename;
\Drupal::service('file_system')->copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR);
\Drupal::service('file_system')->copy($files[0]->uri, $desired_filepath, FileSystemInterface::EXISTS_ERROR);
$file = File::create(['uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename]);
$file->save();
}
......
......@@ -187,8 +187,8 @@ public function handleFileUploadForField(FieldDefinitionInterface $field_definit
}
// 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);
}
......
......@@ -5,6 +5,7 @@
* Batch process to check the availability of remote or local po files.
*/
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Url;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\RequestInterface;
......@@ -293,7 +294,7 @@ function locale_translation_http_check($uri) {
* File object if download was successful. FALSE on failure.
*/
function locale_translation_download_source($source_file, $directory = 'temporary://') {
if ($uri = system_retrieve_file($source_file->uri, $directory, FALSE, FILE_EXISTS_REPLACE)) {
if ($uri = system_retrieve_file($source_file->uri, $directory, FALSE, FileSystemInterface::EXISTS_REPLACE)) {
$file = clone($source_file);
$file->type = LOCALE_TRANSLATION_LOCAL;
$file->uri = $uri;
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\locale\Functional;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Tests\BrowserTestBase;
/**
......@@ -33,8 +34,8 @@ protected function setUp() {
$this->drupalLogin($this->adminUser);
// Copy test po files to the translations directory.
\Drupal::service('file_system')->copy(__DIR__ . '/../../../tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE);
\Drupal::service('file_system')->copy(__DIR__ . '/../../../tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE);
\Drupal::service('file_system')->copy(__DIR__ . '/../../../tests/test.de.po', 'translations://', FileSystemInterface::EXISTS_REPLACE);
\Drupal::service('file_system')->copy(__DIR__ . '/../../../tests/test.xx.po', 'translations://', FileSystemInterface::EXISTS_REPLACE);
}
/**
......
......@@ -5,6 +5,7 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Url;
use Drupal\Core\Database\Database;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Language\LanguageInterface;
......@@ -46,8 +47,8 @@ protected function setUp() {
// Copy test po files to the translations directory.
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$file_system->copy(__DIR__ . '/../../../tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE);
$file_system->copy(__DIR__ . '/../../../tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE);
$file_system->copy(__DIR__ . '/../../../tests/test.de.po', 'translations://', FileSystemInterface::EXISTS_REPLACE);
$file_system->copy(__DIR__ . '/../../../tests/test.xx.po', 'translations://', FileSystemInterface::EXISTS_REPLACE);
$this->adminUser = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages']);
$this->adminUserAccessSiteReports = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages', 'access site reports']);
......
......@@ -167,7 +167,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
* @param string $destination
* The destination path or URI.
* @param int $replace
* (optional) FILE_EXISTS_REPLACE (default) or FILE_EXISTS_RENAME.
* (optional) FileSystemInterface::EXISTS_REPLACE (default) or
* FileSystemInterface::EXISTS_RENAME.
*
* @return string|bool
* File destination on success, FALSE on failure.
......
......@@ -1354,10 +1354,10 @@ function system_time_zones($blank = NULL, $grouped = FALSE) {
* registered in the database.
* @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 mixed
* One of these possibilities:
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Archiver\ArchiverManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\FileTransfer\Local;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -157,7 +158,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
elseif (!empty($all_files['project_upload'])) {
$validators = ['file_validate_extensions' => [$this->archiverManager->getExtensions()]];
if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) {
if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FileSystemInterface::EXISTS_REPLACE))) {
// Failed to upload the file. file_save_upload() calls
// \Drupal\Core\Messenger\MessengerInterface::addError() on failure.
return;
......
......@@ -38,6 +38,7 @@
use Drupal\Core\Url;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
......@@ -226,7 +227,7 @@ function update_manager_file_get($url) {
$local = $cache_directory . '/' . \Drupal::service('file_system')->basename($parsed_url['path']);
if (!file_exists($local) || update_delete_file_if_stale($local)) {
return system_retrieve_file($url, $local, FALSE, FILE_EXISTS_REPLACE);
return system_retrieve_file($url, $local, FALSE, FileSystemInterface::EXISTS_REPLACE);
}
else {
return $local;
......
......@@ -156,9 +156,9 @@ public function testFileCreateNewFilepath() {
*
* If a file exists, ::getDestinationFilename($destination, $replace) will
* either return:
* - the existing filepath, if $replace is FILE_EXISTS_REPLACE
* - a new filepath if FILE_EXISTS_RENAME
* - an error (returning FALSE) if FILE_EXISTS_ERROR.
* - the existing filepath, if $replace is FileSystemInterface::EXISTS_REPLACE
* - a new filepath if FileSystemInterface::EXISTS_RENAME
* - an error (returning FALSE) if FileSystemInterface::EXISTS_ERROR.
* If the file doesn't currently exist, then it will simply return the
* filepath.
*/
......
......@@ -2,6 +2,8 @@
namespace Drupal\KernelTests\Core\File;
use Drupal\Core\File\FileSystemInterface;
/**
* Tests the file_unmanaged_save_data() function.
*
......@@ -21,7 +23,7 @@ public function testFileSaveData() {
$file_system = \Drupal::service('file_system');
// Provide a filename.
$filepath = $file_system->saveData($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
$filepath = $file_system->saveData($contents, 'public://asdf.txt', FileSystemInterface::EXISTS_REPLACE);
$this->assertTrue($filepath, 'Unnamed file saved correctly.');
$this->assertEqual('asdf.txt', \Drupal::service('file_system')->basename($filepath), 'File was named correctly.');
$this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment