/**
  * @param Ticket $ticket
  * @return void
  */
 private function processDeleteTicket(Ticket $ticket)
 {
     $attachments = $ticket->getAttachments();
     foreach ($attachments as $attachment) {
         $this->attachmentManager->deleteAttachment($attachment);
     }
     $this->ticketRepository->remove($ticket);
     $this->dispatchWorkflowEvent($this->doctrineRegistry, $this->dispatcher, $ticket);
 }
 public function testDeleteTicketByKey()
 {
     $this->ticket->expects($this->any())->method('getAttachments')->will($this->returnValue(array($this->attachment())));
     $this->ticketRepository->expects($this->once())->method('getByTicketKey')->with(new TicketKey('DT', 1))->will($this->returnValue($this->ticket));
     $this->ticketRepository->expects($this->once())->method('remove')->with($this->equalTo($this->ticket));
     $this->attachmentManager->expects($this->exactly(count($this->ticket->getAttachments())))->method('deleteAttachment')->with($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Attachment\\Attachment'));
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('DELETE'), $this->equalTo($this->ticket))->will($this->returnValue(true));
     $this->ticketService->deleteTicketByKey(self::DUMMY_TICKET_KEY);
 }
 /**
  * @param Ticket $ticket
  * @return void
  */
 private function processDeleteTicket(Ticket $ticket)
 {
     $attachments = $ticket->getAttachments();
     $ticket->delete();
     foreach ($attachments as $attachment) {
         $this->attachmentManager->deleteAttachment($attachment);
     }
     $this->dispatchEvents($ticket);
     $this->ticketRepository->remove($ticket);
 }
 /**
  * Remove Attachment from Comment
  * @param RemoveCommentAttachmentCommand $command
  * @return void
  * @throws \RuntimeException if Comment does not exists or Comment has no particular attachment
  */
 public function removeAttachmentFromComment(RemoveCommentAttachmentCommand $command)
 {
     $comment = $this->loadCommentBy($command->commentId);
     $this->isGranted('EDIT', $comment);
     $attachment = $comment->getAttachment($command->attachmentId);
     if (!$attachment) {
         throw new \RuntimeException('Attachment loading failed. Comment has no such attachment.');
     }
     $comment->removeAttachment($attachment);
     $this->commentRepository->store($comment);
     $this->attachmentManager->deleteAttachment($attachment);
 }
 /**
  * @test
  */
 public function thatCommentCreatesWithAttachments()
 {
     $author = $this->createAuthor();
     $ticket = $this->createDummyTicket();
     $this->messageReferenceRepository->expects($this->once())->method('getReferenceByMessageId')->with($this->equalTo(self::DUMMY_MESSAGE_ID))->will($this->returnValue($this->messageReference));
     $this->messageReference->expects($this->once())->method('getTicket')->will($this->returnValue($ticket));
     $this->commentFactory->expects($this->once())->method('create')->with($this->equalTo(self::DUMMY_COMMENT_CONTENT), $this->equalTo($ticket), $this->equalTo($author))->will($this->returnValue($this->comment));
     $this->attachmentManager->expects($this->once())->method('createNewAttachment')->with($this->equalTo(self::DUMMY_FILENAME), $this->equalTo(self::DUMMY_FILE_CONTENT), $this->equalTo($this->comment));
     $this->ticketRepository->expects($this->once())->method('store')->with($this->equalTo($ticket));
     $this->messageReferenceService->createCommentForTicket(self::DUMMY_COMMENT_CONTENT, (string) $author, self::DUMMY_MESSAGE_ID, $this->attachments());
     $this->assertCount(1, $ticket->getComments());
     $this->assertEquals($this->comment, $ticket->getComments()->get(0));
 }
 /**
  * @test
  */
 public function thatAttachmentRemovesFromComment()
 {
     $attachment = new Attachment(new File('some/path/file.ext'));
     $this->commentRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_COMMENT_ID))->will($this->returnValue($this->comment));
     $this->comment->expects($this->once())->method('getAttachment')->with($this->equalTo(1))->will($this->returnValue($attachment));
     $this->comment->expects($this->once())->method('removeAttachment')->with($this->equalTo($attachment));
     $this->attachmentManager->expects($this->once())->method('deleteAttachment')->with($this->equalTo($attachment));
     $this->commentRepository->expects($this->once())->method('store')->with($this->equalTo($this->comment));
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo($this->comment))->will($this->returnValue(true));
     $removeCommentAttachmentCommand = new RemoveCommentAttachmentCommand();
     $removeCommentAttachmentCommand->attachmentId = 1;
     $removeCommentAttachmentCommand->commentId = self::DUMMY_COMMENT_ID;
     $this->service->removeAttachmentFromComment($removeCommentAttachmentCommand);
 }
 /**
  * Remove Attachment from Comment
  * @param RemoveCommentAttachmentCommand $command
  * @param boolean $flush
  * @return void
  *
  * @throws ForbiddenException
  * @throws CommentNotFoundException
  * @throws AttachmentNotFoundException
  */
 public function removeAttachmentFromComment(RemoveCommentAttachmentCommand $command, $flush = false)
 {
     $comment = $this->loadCommentBy($command->commentId);
     $this->isGranted('EDIT', $comment);
     $attachment = $comment->getAttachment($command->attachmentId);
     if (empty($attachment)) {
         throw new AttachmentNotFoundException();
     }
     $comment->removeAttachment($attachment);
     $this->registry->getManager()->persist($comment);
     $this->attachmentManager->deleteAttachment($attachment);
     if (true === $flush) {
         $this->registry->getManager()->flush();
     }
 }
 /**
  * @param array $attachments
  * @param AttachmentHolder $attachmentHolder
  */
 private function createAttachments(array $attachments, AttachmentHolder $attachmentHolder)
 {
     foreach ($attachments as $attachment) {
         $this->attachmentManager->createNewAttachment($attachment->getName(), $attachment->getContent(), $attachmentHolder);
     }
 }