mirror of
https://github.com/tchapi/davis.git
synced 2025-04-21 21:11:59 +02:00
Fix shared calendar deletion (#103)
This commit is contained in:
parent
c6adff0a3a
commit
2001e9c450
@ -442,7 +442,7 @@ class AdminController extends AbstractController
|
||||
*/
|
||||
public function calendarShares(ManagerRegistry $doctrine, string $username, string $calendarid, TranslatorInterface $trans)
|
||||
{
|
||||
$instances = $doctrine->getRepository(CalendarInstance::class)->findSharedInstancesOfInstance($calendarid);
|
||||
$instances = $doctrine->getRepository(CalendarInstance::class)->findSharedInstancesOfInstance($calendarid, true);
|
||||
|
||||
$response = [];
|
||||
foreach ($instances as $instance) {
|
||||
@ -535,9 +535,19 @@ class AdminController extends AbstractController
|
||||
foreach ($instance->getCalendar()->getChanges() ?? [] as $change) {
|
||||
$entityManager->remove($change);
|
||||
}
|
||||
$entityManager->remove($instance->getCalendar());
|
||||
|
||||
// Remove the original calendar instance
|
||||
$entityManager->remove($instance);
|
||||
|
||||
// Remove shared instances
|
||||
$sharedInstances = $doctrine->getRepository(CalendarInstance::class)->findSharedInstancesOfInstance($instance->getCalendar()->getId(), false);
|
||||
foreach ($sharedInstances as $sharedInstance) {
|
||||
$entityManager->remove($sharedInstance);
|
||||
}
|
||||
|
||||
// Finally remove the calendar itself
|
||||
$entityManager->remove($instance->getCalendar());
|
||||
|
||||
$entityManager->flush();
|
||||
$this->addFlash('success', $trans->trans('calendar.deleted'));
|
||||
|
||||
|
@ -23,17 +23,25 @@ class CalendarInstanceRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* @return CalendarInstance[] Returns an array of CalendarInstance objects
|
||||
*/
|
||||
public function findSharedInstancesOfInstance(int $calendarId)
|
||||
public function findSharedInstancesOfInstance(int $calendarId, bool $withCalendar = false)
|
||||
{
|
||||
return $this->createQueryBuilder('c')
|
||||
$query = $this->createQueryBuilder('c')
|
||||
->leftJoin(Principal::class, 'p', \Doctrine\ORM\Query\Expr\Join::WITH, 'c.principalUri = p.uri')
|
||||
->addSelect('p.displayName', 'p.email')
|
||||
->where('c.calendar = :id')
|
||||
->setParameter('id', $calendarId)
|
||||
->andWhere('c.access != :ownerAccess')
|
||||
->setParameter('ownerAccess', CalendarInstance::ACCESS_OWNER)
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
->setParameter('ownerAccess', CalendarInstance::ACCESS_OWNER);
|
||||
|
||||
if ($withCalendar) {
|
||||
// Returns CalendarInstances as arrays, with displayName and email of the owner
|
||||
return $query->addSelect('p.displayName', 'p.email')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
} else {
|
||||
// Returns CalendarInstances as objects
|
||||
return $query->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user