Part of #2047951: [META] Remove calls to deprecated global $user and $GLOBALS['user']

core/modules/file/file.module:

function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
  global $user;
function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
  global $user;
function file_file_download($uri, $field_type = 'file') {
  global $user;
function file_save_upload($form_field_name, $validators = array(), $destination = FALSE, $delta = NULL, $replace = FILE_EXISTS_RENAME) {
  global $user;

core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php:

function testFileValidateSize() {
    global $user;
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sergeypavlenko’s picture

Title: Remove references to global user variable in file module » Remove calls to deprecated global $user in file module
sergeypavlenko’s picture

Assigned: sergeypavlenko » Unassigned
Status: Active » Needs review
FileSize
4.09 KB

Fix. Needs review.

sergeypavlenko’s picture

FileSize
4.09 KB

Removed \ with some functions.

andypost’s picture

Status: Needs review » Needs work
@@ -390,7 +390,7 @@ function file_validate_extensions(File $file, $extensions) {
-  global $user;
+  $account = Drupal::request()->attributes->get('_account');

@@ -398,7 +398,7 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
-  if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($user->id()) + $file->getSize()) > $user_limit) {
+  if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($account->id()) + $file->getSize()) > $user_limit) {

@@ -508,7 +508,7 @@ function file_validate_image_resolution(File $file, $maximum_dimensions = 0, $mi
-  global $user;
+  $account = Drupal::request()->attributes->get('_account');

@@ -523,7 +523,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
-      'uid' => $user->id(),
+      'uid' => $account->id(),

@@ -607,7 +607,7 @@ function file_theme() {
-  global $user;
+  $account = Drupal::request()->attributes->get('_account');

@@ -633,7 +633,7 @@ function file_file_download($uri, $field_type = 'file') {
-  if (empty($references) && ($file->isPermanent() || $file->getOwner()->id() != $user->id())) {
+  if (empty($references) && ($file->isPermanent() || $file->getOwner()->id() != $account->id())) {

@@ -765,7 +765,7 @@ function file_cron() {
-  global $user;
+  $account = Drupal::request()->attributes->get('_account');

@@ -824,7 +824,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
-      'uid' => $user->id(),
+      'uid' => $account->id(),

Please do not change the variable name. Leave $user as it was

@@ -129,7 +129,7 @@ function testFileValidateNameLength() {
-    global $user;
+    $user = \Drupal::request()->attributes->get('_account');

This should be $this->container->get('request')->....

sergeypavlenko’s picture

Status: Needs work » Needs review
FileSize
2.31 KB

Fix. Thank you!

Status: Needs review » Needs work

The last submitted patch, 2061895-5.patch, failed testing.

sergeypavlenko’s picture

Status: Needs work » Needs review
FileSize
2.25 KB

Fix.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Nice

catch’s picture

Status: Reviewed & tested by the community » Postponed
sergeypavlenko’s picture

Crell’s picture

Status: Needs review » Reviewed & tested by the community

#10 looks correct to me, pending bot approval.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed aafee28 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Edit desc.