Update and delete multi timesheets and tags (#1240)

This commit is contained in:
Kevin Papst
2019-11-15 01:25:31 +01:00
committed by GitHub
parent b4739f8f03
commit 94c28ebbc5
49 changed files with 1836 additions and 307 deletions

View File

@@ -48,6 +48,14 @@ final class UserIdLoader implements LoaderInterface
->getQuery()
->execute();
$qb = $em->createQueryBuilder();
$qb->select('PARTIAL u.{id}', 'preferences')
->from(User::class, 'u')
->leftJoin('u.preferences', 'preferences')
->andWhere($qb->expr()->in('u.id', $ids))
->getQuery()
->execute();
$teamIds = [];
foreach ($users as $user) {
foreach ($user->getTeams() as $team) {

View File

@@ -28,23 +28,14 @@ class UserQuery extends VisibilityQuery
]);
}
/**
* @return string|null
*/
public function getRole()
public function getRole(): ?string
{
return $this->role;
}
/**
* @param string|null $role
* @return UserQuery
*/
public function setRole($role)
public function setRole(?string $role): UserQuery
{
if (null === $role || false !== strpos($role, 'ROLE_')) {
$this->role = $role;
}
$this->role = $role;
return $this;
}

View File

@@ -159,4 +159,25 @@ class TagRepository extends EntityRepository
return $qb;
}
/**
* @param Tag[] $tags
* @throws \Exception
*/
public function multiDelete(iterable $tags): void
{
$em = $this->getEntityManager();
$em->beginTransaction();
try {
foreach ($tags as $tag) {
$em->remove($tag);
}
$em->flush();
$em->commit();
} catch (\Exception $ex) {
$em->rollback();
throw $ex;
}
}
}

View File

@@ -67,6 +67,27 @@ class TimesheetRepository extends EntityRepository
$entityManager->flush();
}
/**
* @param Timesheet[] $timesheets
* @throws \Exception
*/
public function deleteMultiple(iterable $timesheets): void
{
$em = $this->getEntityManager();
$em->beginTransaction();
try {
foreach ($timesheets as $timesheet) {
$em->remove($timesheet);
}
$em->flush();
$em->commit();
} catch (\Exception $ex) {
$em->rollback();
throw $ex;
}
}
/**
* @param Timesheet $timesheet
* @throws \Doctrine\ORM\ORMException
@@ -79,6 +100,27 @@ class TimesheetRepository extends EntityRepository
$entityManager->flush();
}
/**
* @param Timesheet[] $timesheets
* @throws \Exception
*/
public function saveMultiple(array $timesheets): void
{
$em = $this->getEntityManager();
$em->beginTransaction();
try {
foreach ($timesheets as $timesheet) {
$em->persist($timesheet);
}
$em->flush();
$em->commit();
} catch (\Exception $ex) {
$em->rollback();
throw $ex;
}
}
/**
* @param Timesheet $entry
* @return bool