Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gaydamaka created an issue. See original summary.

gaydamaka’s picture

Status: Active » Needs review
hass’s picture

Issue tags: +Needs tests
spheresh’s picture

It works for me! Thanks @gaydamaka.
I also agree that direct request to the database is very light

but I think to use a user_load_by_name function is better by two reasons:
- This function gets an Entity Storage service which is Entity Storage Interface implementation.
- This solves possible problems in case User Storage will be overridden by one of the modules.

but another side this function load a fully-loaded user object that is not really needed for us in this case.

hass’s picture

Status: Needs review » Needs work

We always always always need to use the drupal API.

Ronald van Belzen’s picture

I am unable to reproduce this error.

However, looking at patch #2, I started wondering whether the following instruction should be used in the function realname_update() at all?

$account->setUsername($realname);
hass’s picture

Status: Needs work » Postponed (maintainer needs more info)

Whatever I'm trying here I cannot reproduce the SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry. It's nearly impossible to know what user is the right one, but it all works without errors. Can you document the repro, please?

hass’s picture

There may be a simple solution here. Something already done in D7.

'value' => t('@realname (@id)', ['@realname' => $account->getDisplayName(), '@id' => $account->id()]),
'label' => t('@realname', ['@realname' => $account->getDisplayName()]),

We may change label to show the username or ID in brackets. In D7 it was the username.

With ID:

'value' => t('@realname (@id)', ['@realname' => $account->getDisplayName(), '@id' => $account->id()]),
'label' => t('@realname (@id)', ['@realname' => $account->getDisplayName(), '@id' => $account->id()]),

and with username (I think this is better usability than just a number):

'value' => t('@realname (@id)', ['@realname' => $account->getDisplayName(), '@id' => $account->id()]),
'label' => t('@realname (@username)', ['@realname' => $account->getDisplayName(), '@username' => $account->getAccountName()]),

This would be just a usability enhancement, not a solution for the SQL issue reported.

hass’s picture

getAccountName() returns empty value on Anonymous. Need to investigate.

hass’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Related issues: +#2881524: getAccountName() returns no username for Anonymous user

Above changes are in RC1 and opened a follow up #2881524: getAccountName() returns no username for Anonymous user.

As I'm not able to repro the duplicate entry situation, I'm closing as cannot repro. If you know - how to repro, please reopen with step by step instructions.