dombg
dombg

Reputation: 331

TYPO3 8.7: findByEmail function of frontenduserrepository returns null

In my module of my custom Extension I'm trying to change the db value of a fe_user. In fact I'm trying to change the email and the username. But when I use the given TYPO3 FrontendUserRepo the function findByEmail returns null. The Email $_POST['email'] is passed correctly and I tried hardcoding a valid email as well, it didn't work.

In Controller:

Imports:

use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;

Injection of FrontendUserRepo as attribute of class:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
 * @inject
 */
protected $frontendUserRepository;

...

In action:

$frontendUser =  $this->frontendUserRepository->findByEmail($_POST['email_old']);
$frontendUser->setUsername($_POST['email']);
$frontendUser->setEmail($_POST['email']);

Upvotes: 1

Views: 462

Answers (3)

Felix
Felix

Reputation: 5629

A possible solution for this issue could be:

$querySettings = $this->FrontendUserRepository->createQuery()->getQuerySettings();
       // don't add the pid constraint
       $querySettings->setRespectStoragePage(FALSE);
       $this->FrontendUserRepository->setDefaultQuerySettings($querySettings);

in this case you didn't need a second storage pid

Upvotes: 1

Rudy Gnodde
Rudy Gnodde

Reputation: 4565

This is most likely because the storagePid hasn't been set to the folder with the frontend users. Set the storagePid for your extension to the folder with the frontend users. This can be done in TypoScript using: module.tx_yourextension.persistence.storagePid = ...

If your users are in a different folder than the rest of the records used by the extensions, you can set multiple uids comma separated. If you create new records you will need to set which uid each record type should be saved:

module.tx_yourextensions.persistence {
  storagePid = [uid1],[uid2]
  Vendor\YourExtension\Domain\Model\YourModel {
    newRecordStoragePid = [uid1]
  }
  TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
    newRecordStoragePid = [uid2]
  }
}

Upvotes: 2

StatiX
StatiX

Reputation: 874

You need to save the object after setting the attribute. Here is a way to do this :

$frontendUserRepository->update($frontendUser);

Upvotes: 0

Related Questions