remove roles from users when role is deleted (#1640)

This commit is contained in:
Kevin Papst
2020-04-15 15:44:28 +02:00
committed by GitHub
parent 57254bf175
commit 4254c2590a
3 changed files with 54 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
namespace App\Repository;
use App\Entity\Role;
use App\Entity\User;
use App\Repository\Loader\UserLoader;
use App\Repository\Paginator\LoaderPaginator;
@@ -170,6 +171,28 @@ class UserRepository extends EntityRepository implements UserLoaderInterface
}
}
/**
* @param string $role
* @return User[]
* @internal
*/
public function findUsersWithRole(string $role): array
{
if ($role === User::ROLE_USER) {
return $this->findAll();
}
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->select('u')
->from(User::class, 'u')
->andWhere('u.roles LIKE :role');
$qb->setParameter('role', '%' . $role . '%');
return $qb->getQuery()->getResult();
}
private function getQueryBuilderForQuery(UserQuery $query): QueryBuilder
{
$qb = $this->getEntityManager()->createQueryBuilder();