mirror of
https://github.com/jbcr/ezmigrationbundle.git
synced 2026-03-25 17:32:05 +01:00
26 lines
614 B
PHP
26 lines
614 B
PHP
<?php
|
|
|
|
namespace Kaliop\eZMigrationBundle\Core;
|
|
|
|
/**
|
|
* NB: needs a class member 'repository'
|
|
*/
|
|
trait RepositoryUserSetterTrait
|
|
{
|
|
/**
|
|
* Helper method to log in a user that can make changes to the system.
|
|
* @param int $userId
|
|
* @return int id of the previously logged in user
|
|
*/
|
|
protected function loginUser($userId)
|
|
{
|
|
$previousUser = $this->repository->getCurrentUser();
|
|
|
|
if ($userId != $previousUser->id) {
|
|
$this->repository->setCurrentUser($this->repository->getUserService()->loadUser($userId));
|
|
}
|
|
|
|
return $previousUser->id;
|
|
}
|
|
}
|