TYPO3 7.6 load backend user info

159 Views Asked by At

I've added my own scheduler task to the TYPO3 that will, for example, create new page if necessary. The scheduler runs by a special _cli_scheduler user and if I create new pages with it, other editors may not see it.

I'm using the DataHandler (former TCE) to create new pages. The start() method accepts an optional parameter - alternative user object that will be used as a creator of the page.

Having uid of an editor user, how can I fully instantiate the \TYPO3\CMS\Core\Authentication\BackendUserAuthentication object which then I provide to the DataHandler::start()?

I was thinking of using the object manager to get new instance of the mentioned class and just set the uid on it, but the DataHandler checks some other properties of the BackendUserAuthentication object, like permissions, etc.

What is the correct way for getting BackendUserAuthentication object will all user data? Is there any factory or a repository I could use?

1

There are 1 best solutions below

0
On BEST ANSWER

No one was able to help me with this, so I started digging. After some reverse engineering I have found a complete way for loading any backend user as long as you know their ID. I have created a read-only repository with the following method:


public function fetchById($userId)
{
    /** @var BackendUserAuthentication $user */
    $user = $this->objectManager->get(BackendUserAuthentication::class);
    $user->setBeUserByUid($userId);
    $user->resetUC();
    $user->fetchGroupData();
    $user->getFileStorages();
    $user->workspaceInit();
    $user->setDefaultWorkspace();

    return $user;
}

It will do the following:

  • Load user record from database and store it internally in the $user property
  • Load the UC of the user
  • Load user/group permissions
  • Initialize file storage
  • Initialize workspace

I've dumped user created by this method and compared with the currently logged-in user and it seems that all necessary properties have been set up.

Please let me know if I missed something.