/** * @dataProvider tagIdsProvider */ public function testDeleteTaggingByParams($tagIds, $entityName, $recordId, $createdBy, $expectedCallArg) { $repo = $this->getMockBuilder('Oro\\Bundle\\TagBundle\\Entity\\Repository\\TagRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->once())->method('deleteTaggingByParams')->with($expectedCallArg, $entityName, $recordId, $createdBy); $this->em->expects($this->once())->method('getRepository')->will($this->returnValue($repo)); $this->manager->deleteTaggingByParams($tagIds, $entityName, $recordId, $createdBy); }
/** * Update Branch * * @param Command\BranchCommand $branchCommand * @return int */ public function updateBranch(Command\BranchCommand $branchCommand) { $this->isGranted('EDIT', 'Entity:DiamanteDeskBundle:Branch'); /** * @var $branch \Diamante\DeskBundle\Model\Branch\Branch */ $branch = $this->branchRepository->get($branchCommand->id); if ($branchCommand->defaultAssignee) { $assignee = $this->userService->getByUser(new User($branchCommand->defaultAssignee, User::TYPE_ORO)); } else { $assignee = null; } /** @var \Symfony\Component\HttpFoundation\File\File $file */ $file = null; if ($branchCommand->isRemoveLogo()) { $this->branchLogoHandler->remove($branch->getLogo()); $file = new Logo(); } elseif ($branchCommand->logoFile) { if ($branch->getLogo()) { $this->branchLogoHandler->remove($branch->getLogo()); } $logo = $this->handleLogoUpload($branchCommand->logoFile); $file = new Logo($logo->getFilename(), $branchCommand->logoFile->getClientOriginalName()); } $branch->update($branchCommand->name, $branchCommand->description, $assignee, $file); $this->branchRepository->store($branch); //TODO: Refactor tag manipulations. $this->tagManager->deleteTaggingByParams($branch->getTags(), get_class($branch), $branch->getId()); $tags = $branchCommand->tags; $tags['owner'] = $tags['all']; $branch->setTags($tags); $this->tagManager->saveTagging($branch); return $branch->getId(); }
/** * Update Ticket * * @param UpdateTicketCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Ticket * @throws \RuntimeException if unable to load required ticket and assignee */ public function updateTicket(UpdateTicketCommand $command) { \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput'); $ticket = $this->loadTicketById($command->id); $this->isGranted('EDIT', $ticket); $reporter = $ticket->getReporter(); if ((string) $command->reporter !== (string) $reporter) { $reporter = $command->reporter; } $assignee = null; if ($command->assignee) { $assignee = $ticket->getAssignee(); $currentAssigneeId = empty($assignee) ? null : $assignee->getId(); if ($command->assignee != $currentAssigneeId) { $assignee = $this->userService->getByUser(new User((int) $command->assignee, User::TYPE_ORO)); } } $ticket->update($command->subject, $command->description, $reporter, new Priority($command->priority), new Status($command->status), new Source($command->source), $assignee); if (is_array($command->attachmentsInput) && false === empty($command->attachmentsInput)) { foreach ($command->attachmentsInput as $each) { $this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $ticket); } } $this->ticketRepository->store($ticket); $this->tagManager->deleteTaggingByParams($ticket->getTags(), get_class($ticket), $ticket->getId()); $tags = $command->tags; $tags['owner'] = $tags['all']; $ticket->setTags($tags); $this->tagManager->saveTagging($ticket); $this->dispatchEvents($ticket); return $ticket; }