Replace all global $user and $GLOBALS['user']. All places in History module should be fixed (except tests see #2150857: Remove references to global $user in History module tests.).

core/modules/history/history.module: global $user;
core/modules/history/history.module: global $user;
core/modules/history/lib/Drupal/history/Plugin/views/field/HistoryUserTimestamp.php: global $user;
core/modules/history/lib/Drupal/history/Plugin/views/field/HistoryUserTimestamp.php: global $user;
core/modules/history/lib/Drupal/history/Plugin/views/field/HistoryUserTimestamp.php: global $user;
core/modules/history/lib/Drupal/history/Plugin/views/filter/HistoryUserTimestamp.php: global $user;

Comments

m1r1k’s picture

Status: Active » Needs review
StatusFileSize
new3.62 KB

Here is the patch:

Status: Needs review » Needs work

The last submitted patch, history-remove-global-user-from-history-module-2061927-1.patch, failed testing.

kscheirer’s picture

Status: Needs work » Postponed

I think we need Drupal::currentUser() to get in first, then we can take care of this.

andypost’s picture

Status: Postponed » Needs work
Issue tags: +Needs reroll

Now we should use current_user service

m1r1k’s picture

$GLOBALS['user'] = $account;

We have such weird stuff here. How should it be handled by "current_user" service?

Also looks like History has wrong tests, I will post more info here.

andypost’s picture

joelpittet’s picture

Assigned: m1r1k » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll, -CodeSprintCIS
StatusFileSize
new2.84 KB
new3.83 KB

re-rolled with currentUser service.

Jumping on here because this fixes registry_rebuild error messages in drush:) Thanks for creating this and the meta!

I had to revert the $GLOBAL['user'] for simple test to pass, and seems that is an issue, see note at the bottom of the change request. @see https://drupal.org/node/2032447

Status: Needs review » Needs work

The last submitted patch, 2061927-7-global-user-history.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

#7: 2061927-7-global-user-history.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 2061927-7-global-user-history.patch, failed testing.

joelpittet’s picture

Hmm, so UI tests pass though testbot cli tests fail. Anybody pointers?

m1r1k’s picture

I found 3 points last time:

  1. global $user; inside theme.inc
  2. global $user; inside views module
  3. History has bad Web tests, so it works wrong even before patch, because tests expect wrong results

Also I haven't had errors in Drupal\rdf\Tests\StandardProfileTest before ...

joelpittet’s picture

@m1r1k thanks, yeah seems getting access to the service in the command line is failing. I'm sure all the failures are related. The web UI run on the tests isn't having much of a problem.

The changes were from the 'new' change request so if you look at the interdiff, not much changed.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new2.6 KB

re-roll with #2053489: Standardize on \Drupal throughout core

I expect this to fail tests again because nothing has really changed to fix it and it fails on the CLI locally but the Web UI passes with no issues on the tests.

Status: Needs review » Needs work

The last submitted patch, 2061927-14-global-user-history.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2061927-14-global-user-history.patch, failed testing.

andypost’s picture

core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php: $GLOBALS['user'] = $account;
this should be fixed first

Also related #2105123-18: Add a currentUser() method to plugin base classes that need it that was rolled back

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new730 bytes
new3.17 KB

Removed $GLOBALS['user'] as mentioned in #18. It's not needed because the user is set with the line above in $this->drupalLogin($account);

Status: Needs review » Needs work

The last submitted patch, 2061927-18-global-user-history.patch, failed testing.

andypost’s picture

  1. +++ b/core/modules/history/history.module
    @@ -99,7 +99,7 @@ function history_read_multiple($nids) {
    -  global $user;
    +  $user = \Drupal::currentUser();
    ...
       if (!isset($account)) {
         $account = $user;
    

    Suppose $account = \Drupal::currentUser(); is much better

  2. +++ b/core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php
    @@ -49,7 +49,6 @@ public function testHandlers() {
    -    $GLOBALS['user'] = $account;
    

    somehow this is needed!?

joelpittet’s picture

@andypost have a look at those lines you pointed out again. #21

1) The first one says 'if' there is no $account use the $global $user. So if $account isn't passed through, look for the default on the request.

2) The $GLOBALS['user'] is set in drupalLogin as I noted in #19

andypost’s picture

yep.
1) let's clean-up $user variable
2) the tests are broken without this change... not sure why

joelpittet’s picture

@andypost sorry if there is a misunderstanding but

  1. I don't understand in what that needs 'clean-up', there are two different variable names for a reason.
  2. This issue's very purpose is to remove/replace global $user and $GLOBAL['user'] and the drupalLogin function does the work of setting the current_user service so it doesn't need to be done again here.

Have a look at this issue that could solve why this meta with such simple changes is falling flat.
#1858196: [meta] Leverage Symfony Session components

joelpittet’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2061927-18-global-user-history.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

linking meta

joelpittet’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: 2061927-18-global-user-history.patch, failed testing.

internetdevels’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.72 KB
new2.22 KB

Lets see.

Status: Needs review » Needs work

The last submitted patch, 29: drupal-removeglobaluserfromhistorymodule-2061927-29.patch, failed testing.

joelpittet’s picture

Even though the fails didn't change, I like the changes:)

There seems to be issues with how sessions are created.

joelpittet’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 29: drupal-removeglobaluserfromhistorymodule-2061927-29.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review
Parent issue: » #2047951: [META] Remove calls to deprecated global $user and $GLOBALS['user']
StatusFileSize
new865 bytes
new3.39 KB

@InternetDevels thanks, that looks nicer and I found one more.

Status: Needs review » Needs work

The last submitted patch, 34: 2061927-34global-user-history.patch, failed testing.

joelpittet’s picture

StatusFileSize
new2.83 KB
new736 bytes

So this should pass all tests. I removed the conversion within the test that was failing.

This is because of this in the Change Record

"NOTE: The global $user variable still exists as it is necessary for certain portions of the installer and simpletest..."

I'm not sure if this needs a follow-up for that on the meta?

joelpittet’s picture

Status: Needs work » Needs review
areke’s picture

Status: Needs review » Reviewed & tested by the community

I didn't find anymore $user variables that needed to be removed, so this looks good.

joelpittet’s picture

@areke thanks for RTBCing this. I'll leave it as so because I think it should go in as is because of that Change Record but I would like to get an answer on what to do with those simpletests(see interdiff from last patch). Maybe I can ask Crell.

joelpittet’s picture

Moved the test $GLOBALS['user'] removal to a separate issue:
#2150857: Remove references to global $user in History module tests. and updated issue summary.

webchick’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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