clone of github.com/decent-newsroom/newsroom
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

27 lines
742 B

<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
class UserEntityRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry, private readonly EntityManagerInterface $entityManager)
{
parent::__construct($registry, User::class);
}
public function findOrCreateByUniqueField(User $user): User
{
$entity = $this->findOneBy(['npub' => $user->getNpub()]);
if ($entity) {
$user->setId($entity->getId());
}
$this->entityManager->persist($user);
return $user;
}
}