Issue #3021458 by kim.pepper, voleger: Properly deprecate drupal_move_uploaded_file()

8.7.x
Alex Pott 2018-12-23 18:46:15 +01:00
parent 2e30a3c2ae
commit b99b499e70
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
5 changed files with 37 additions and 7 deletions

View File

@ -934,6 +934,7 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) {
* @see https://www.drupal.org/node/2418133
*/
function drupal_move_uploaded_file($filename, $uri) {
@trigger_error('drupal_move_uploaded_file() is deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::moveUploadedFile(). See https://www.drupal.org/node/2418133.', E_USER_DEPRECATED);
return \Drupal::service('file_system')->moveUploadedFile($filename, $uri);
}

View File

@ -1055,7 +1055,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va
}
$file->setFileUri($file->destination);
if (!drupal_move_uploaded_file($file_info->getRealPath(), $file->getFileUri())) {
if (!\Drupal::service('file_system')->moveUploadedFile($file_info->getRealPath(), $file->getFileUri())) {
\Drupal::messenger()->addError(t('File upload error. Could not move uploaded file.'));
\Drupal::logger('file')->notice('Upload error. Could not move uploaded file %file to destination %destination.', ['%file' => $file->getFilename(), '%destination' => $file->getFileUri()]);
return FALSE;

View File

@ -98,9 +98,9 @@ class FileTestForm implements FormInterface {
$validators['file_validate_extensions'] = [$form_state->getValue('extensions')];
}
// The test for drupal_move_uploaded_file() triggering a warning is
// unavoidable. We're interested in what happens afterwards in
// file_save_upload().
// The test for \Drupal::service('file_system')->moveUploadedFile()
// triggering a warning is unavoidable. We're interested in what happens
// afterwards in file_save_upload().
if (\Drupal::state()->get('file_test.disable_error_collection')) {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
}

View File

@ -145,9 +145,9 @@ class FileTestSaveUploadFromForm extends FormBase {
$validators['file_validate_extensions'] = [$form_state->getValue('extensions')];
}
// The test for drupal_move_uploaded_file() triggering a warning is
// unavoidable. We're interested in what happens afterwards in
// _file_save_upload_from_form().
// The test for \Drupal::service('file_system')->moveUploadedFile()
// triggering a warning is unavoidable. We're interested in what happens
// afterwards in _file_save_upload_from_form().
if ($this->state->get('file_test.disable_error_collection')) {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
}

View File

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\Core\File;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests deprecations in file.inc.
*
* @group File
* @group legacy
*/
class FileSystemDeprecationTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['system'];
/**
* @expectedDeprecation drupal_move_uploaded_file() is deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::moveUploadedFile(). See https://www.drupal.org/node/2418133.
*/
public function testDeprecatedFileMoveUploadedFile() {
$this->assertNotNull(drupal_move_uploaded_file('', ''));
}
}