/** * action delete * * @param Reservation $reservation * @return void */ public function deleteAction(Reservation $reservation) { $this->addFlashMessage($this->translate('message.reservation.delete.success')); if ($participants = $reservation->getParticipants()) { foreach ($participants as $participant) { $this->personRepository->remove($participant); } } if ($company = $reservation->getCompany()) { $this->companyRepository->remove($company); } if ($contact = $reservation->getContact()) { $this->contactRepository->remove($contact); } $this->reservationRepository->remove($reservation); $this->session->clean(); }
/** * Delete expired reservations * I.e. reservations of status new which are older then a given minAge * * @param boolean $dryRun * @param int $age Age in seconds * @return int */ protected function deleteInvalidReservations($dryRun, $age) { $reservations = $this->getInvalidReservations($age); $deletedCount = 0; if (!$dryRun) { /** @var Reservation $reservation */ foreach ($reservations as $reservation) { /** @var Schedule $lesson */ if ($lesson = $reservation->getLesson()) { /** @var Person $participants */ if ($participants = $reservation->getParticipants()) { foreach ($participants as $participant) { $lesson->removeParticipant($participant); $this->personRepository->remove($participant); } } } $this->reservationRepository->remove($reservation); $deletedCount++; } } return $dryRun ? count($reservations) : $deletedCount; }