Release 2.21.0 (#5014)
This commit is contained in:
@@ -91,6 +91,9 @@ class ActivityRepository extends EntityRepository
|
||||
return $this->count([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
private function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = [], bool $globalsOnly = false): void
|
||||
{
|
||||
$permissions = $this->getPermissionCriteria($qb, $user, $teams, $globalsOnly);
|
||||
@@ -99,6 +102,9 @@ class ActivityRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
private function getPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = [], bool $globalsOnly = false): Andx
|
||||
{
|
||||
$andX = $qb->expr()->andX();
|
||||
|
||||
@@ -14,35 +14,45 @@ use App\Entity\User;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* @extends \Doctrine\ORM\EntityRepository<Bookmark>
|
||||
* @extends EntityRepository<Bookmark>
|
||||
*/
|
||||
class BookmarkRepository extends EntityRepository
|
||||
{
|
||||
/** @var array<string, array<string, array<string, Bookmark>>> */
|
||||
private array $userCache = [];
|
||||
|
||||
public function saveBookmark(Bookmark $bookmark)
|
||||
public function saveBookmark(Bookmark $bookmark): void
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($bookmark);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->clearCache($bookmark->getUser());
|
||||
if ($bookmark->getUser()) {
|
||||
$this->clearCache($bookmark->getUser());
|
||||
}
|
||||
}
|
||||
|
||||
private function clearCache(User $user): void
|
||||
private function clearCache(?User $user): void
|
||||
{
|
||||
if ($user === null || $user->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$key = 'user_' . $user->getId();
|
||||
if (\array_key_exists($key, $this->userCache)) {
|
||||
unset($this->userCache[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteBookmark(Bookmark $bookmark)
|
||||
public function deleteBookmark(Bookmark $bookmark): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->remove($bookmark);
|
||||
$em->flush();
|
||||
$this->clearCache($bookmark->getUser());
|
||||
|
||||
if ($bookmark->getUser()) {
|
||||
$this->clearCache($bookmark->getUser());
|
||||
}
|
||||
}
|
||||
|
||||
public function getSearchDefaultOptions(User $user, string $name): ?Bookmark
|
||||
@@ -59,7 +69,7 @@ class BookmarkRepository extends EntityRepository
|
||||
$this->userCache[$key] = [];
|
||||
$all = $this->findBy(['user' => $user->getId()]);
|
||||
foreach ($all as $item) {
|
||||
$this->userCache[$key][$item->getType()][mb_substr($item->getName(), 0, 50)] = $item;
|
||||
$this->userCache[$key][$item->getType()][mb_substr($item->getName() ?? '__DEFAULT__', 0, 50)] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,9 @@ class CustomerRepository extends EntityRepository
|
||||
return $this->count([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
public function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = []): void
|
||||
{
|
||||
$permissions = $this->getPermissionCriteria($qb, $user, $teams);
|
||||
@@ -87,6 +90,9 @@ class CustomerRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
private function getPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = []): Andx
|
||||
{
|
||||
$andX = $qb->expr()->andX();
|
||||
@@ -349,6 +355,9 @@ class CustomerRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<CustomerComment>
|
||||
*/
|
||||
public function getComments(Customer $customer): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
@@ -83,13 +83,14 @@ class InvoiceRepository extends EntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
/** @var array{'counter': int|numeric-string}|null $result */
|
||||
$result = $qb->getQuery()->getOneOrNullResult();
|
||||
|
||||
if ($result === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $result['counter'];
|
||||
return (int) $result['counter'];
|
||||
}
|
||||
|
||||
public function getCounterForDay(\DateTimeInterface $date, ?Customer $customer = null, ?User $user = null): int
|
||||
@@ -137,7 +138,10 @@ class InvoiceRepository extends EntityRepository
|
||||
return $this->count([]);
|
||||
}
|
||||
|
||||
private function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = [])
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
private function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = []): void
|
||||
{
|
||||
// make sure that all queries without a user see all projects
|
||||
if (null === $user && empty($teams)) {
|
||||
|
||||
@@ -71,7 +71,7 @@ final class TimesheetLoader implements LoaderInterface
|
||||
|
||||
if ($this->fullyHydrated) {
|
||||
$customerIds = array_filter(array_unique(array_map(function (Project $project) {
|
||||
return $project->getCustomer()->getId();
|
||||
return $project->getCustomer()?->getId();
|
||||
}, $projects)), function ($value) { return $value !== null; });
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
|
||||
@@ -13,6 +13,7 @@ use Pagerfanta\Adapter\AdapterInterface;
|
||||
|
||||
/**
|
||||
* @template-covariant T
|
||||
* @extends AdapterInterface<T>
|
||||
*/
|
||||
interface PaginatorInterface extends AdapterInterface
|
||||
{
|
||||
|
||||
@@ -85,6 +85,9 @@ class ProjectRepository extends EntityRepository
|
||||
return $this->count([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
public function addPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = []): void
|
||||
{
|
||||
$permissions = $this->getPermissionCriteria($qb, $user, $teams);
|
||||
@@ -93,6 +96,9 @@ class ProjectRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Team> $teams
|
||||
*/
|
||||
private function getPermissionCriteria(QueryBuilder $qb, ?User $user = null, array $teams = []): Andx
|
||||
{
|
||||
$andX = $qb->expr()->andX();
|
||||
@@ -429,6 +435,9 @@ class ProjectRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<ProjectComment>
|
||||
*/
|
||||
public function getComments(Project $project): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
@@ -40,12 +40,12 @@ trait RepositorySearchTrait
|
||||
|
||||
private function addSearchTerm(QueryBuilder $qb, BaseQuery $query): void
|
||||
{
|
||||
if (!$query->hasSearchTerm()) {
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
|
||||
if ($searchTerm === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
|
||||
if (!$this->supportsMetaFields() && !$searchTerm->hasSearchTerm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,9 @@ final class TimesheetResult
|
||||
return $this->statisticCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<Timesheet>
|
||||
*/
|
||||
public function toIterable(): iterable
|
||||
{
|
||||
return $this->query->toIterable();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Repository\Paginator\QueryPaginator;
|
||||
use App\Repository\Query\TagFormTypeQuery;
|
||||
use App\Repository\Query\TagQuery;
|
||||
@@ -131,7 +132,11 @@ class TagRepository extends EntityRepository
|
||||
{
|
||||
$qb = $this->createQueryBuilder('tag');
|
||||
|
||||
$qb->select('tag.id, tag.name, tag.color, tag.visible, SIZE(tag.timesheets) as amount');
|
||||
$qb1 = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb1->from(Timesheet::class, 't')->select('COUNT(tags)')->innerJoin('t.tags', 'tags')->where('tags.id = tag.id');
|
||||
|
||||
$qb->select('tag.id, tag.name, tag.color, tag.visible');
|
||||
$qb->addSelect('(' . $qb1->getDQL() . ') as amount');
|
||||
|
||||
$orderBy = $query->getOrderBy();
|
||||
$orderBy = match ($orderBy) {
|
||||
@@ -149,8 +154,8 @@ class TagRepository extends EntityRepository
|
||||
|
||||
$qb->addOrderBy($orderBy, $query->getOrder());
|
||||
|
||||
if ($query->hasSearchTerm()) {
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
if ($searchTerm !== null) {
|
||||
$searchAnd = $qb->expr()->andX();
|
||||
|
||||
if ($searchTerm->hasSearchTerm()) {
|
||||
|
||||
@@ -117,14 +117,14 @@ class UserRepository extends EntityRepository implements UserLoaderInterface, Us
|
||||
*/
|
||||
public function findOneBy(array $criteria, array $orderBy = null): ?object
|
||||
{
|
||||
if (\count($criteria) === 1 && isset($criteria['username'])) {
|
||||
if (\count($criteria) === 1 && isset($criteria['username']) && \is_string($criteria['username'])) {
|
||||
return $this->loadUserByIdentifier($criteria['username']);
|
||||
}
|
||||
|
||||
return parent::findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
public function findByUsername($username): ?User
|
||||
public function findByUsername(string $username): ?User
|
||||
{
|
||||
return parent::findOneBy(['username' => $username]);
|
||||
}
|
||||
@@ -321,9 +321,9 @@ class UserRepository extends EntityRepository implements UserLoaderInterface, Us
|
||||
$qb->setParameter('system', $query->getSystemAccount(), Types::BOOLEAN);
|
||||
}
|
||||
|
||||
if ($query->hasSearchTerm()) {
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
if ($searchTerm !== null) {
|
||||
$searchAnd = $qb->expr()->andX();
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
|
||||
foreach ($searchTerm->getSearchFields() as $metaName => $metaValue) {
|
||||
$qb->leftJoin('u.preferences', 'meta');
|
||||
|
||||
Reference in New Issue
Block a user