Unverified Commit b99b499e authored by alexpott's avatar alexpott

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

parent 2e30a3c2
......@@ -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);
}
......
......@@ -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;
......
......@@ -98,9 +98,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$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);
}
......
......@@ -145,9 +145,9 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
$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);
}
......
<?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('', ''));
}
}
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