public function isDefaultBranch(Branch $branch)
 {
     $defaultBranchId = $this->manager->get('diamante_email_processing.default_branch');
     if (empty($defaultBranchId)) {
         return false;
     }
     return (int) $defaultBranchId === $branch->getId();
 }
 /**
  * @param Branch $branch
  * @return bool
  */
 public function isDefault($branch)
 {
     if (!$branch instanceof Branch) {
         return false;
     }
     $defaultBranchId = $this->systemSettings->getDefaultBranchId();
     if (!$defaultBranchId || is_null($branch->getId())) {
         return false;
     }
     return $defaultBranchId == $branch->getId();
 }
 /**
  * @param Branch|null $branch
  * @param User|null   $reporter
  *
  * @return CreateTicketCommand
  */
 public function createCreateTicketCommand(Branch $branch = null, User $reporter = null)
 {
     $command = new CreateTicketCommand();
     if ($branch) {
         $command->branch = $branch;
         if ($branch->getDefaultAssignee()) {
             $command->assignee = $branch->getDefaultAssignee();
         }
     }
     if ($reporter) {
         $command->reporter = $reporter;
     }
     return $command;
 }
 /**
  * Updates DB Schema. Changes from Diamante only will be applied for current schema. Other bundles updating skips
  * @throws \Exception if there are no changes in entities
  */
 protected function updateDbSchema()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $event = $em->getEventManager();
     $sm = $em->getConnection()->getSchemaManager();
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $entitiesMetadata = array($em->getClassMetadata(\Diamante\DeskBundle\Entity\Branch::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Ticket::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Comment::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Attachment::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\BranchEmailConfiguration::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\MessageReference::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\TicketHistory::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\WatcherList::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\TicketTimeline::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Audit::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\AuditField::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Article::getClassName()));
     $event->disableListeners();
     $currentSchema = $sm->createSchema();
     $schemaFromMetadata = $schemaTool->getSchemaFromMetadata($allMetadata);
     $entitiesSchema = $schemaTool->getSchemaFromMetadata($entitiesMetadata);
     $entitiesTables = $entitiesSchema->getTables();
     $entitiesTableName = array_keys($entitiesTables);
     $currentDiamanteSchema = $this->getTargetSchema($currentSchema, $entitiesTableName);
     $diamanteSchemaFromMetadata = $this->getTargetSchema($schemaFromMetadata, $entitiesTableName);
     $comparator = new Comparator();
     $diff = $comparator->compare($currentDiamanteSchema, $diamanteSchemaFromMetadata);
     $toUpdate = $diff->toSql($em->getConnection()->getDatabasePlatform());
     if (empty($toUpdate)) {
         throw new \Exception('No new updates found. DiamanteDesk is up to date!');
     }
     $conn = $em->getConnection();
     foreach ($toUpdate as $sql) {
         $conn->executeQuery($sql);
     }
 }
 /**
  * Get list of Diamante tables to purge data from
  *
  * @return array
  */
 protected function getTablesList()
 {
     $entitiesMetadata = array($this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Branch::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\BranchEmailConfiguration::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Ticket::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Comment::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Attachment::getClassName()));
     $toPurge = array();
     /** @var $entity \Doctrine\ORM\Mapping\ClassMetadata */
     foreach ($entitiesMetadata as $entity) {
         $tableName = $entity->getTableName();
         $toPurge[] = $tableName;
     }
     return $toPurge;
 }
 public function testRenderBranch()
 {
     $tags = array(array('id' => 1, 'name' => 'Branch Tag'));
     $renderTagResult = '<span class="tag-inline">Branch Tag</span>';
     $this->registry->expects($this->once())->method('getRepository')->will($this->returnValue($this->sharedRepository));
     $this->tagManager->expects($this->once())->method('loadTagging')->will($this->returnValue($this->tagManager));
     $this->twig->expects($this->once())->method('render')->will($this->returnValue($renderTagResult));
     $this->sharedRepository->expects($this->once())->method('get')->will($this->returnValue($this->branch));
     $this->branch->expects($this->once())->method('getTags')->will($this->returnValue($this->commonCollection));
     $this->commonCollection->expects($this->once())->method('getValues')->will($this->returnValue($tags));
     $branchResult = $this->renderTagExtensionExtension->renderTag($this->twig, 1, 'branch');
     $this->assertEquals($renderTagResult, $branchResult);
 }
 public function testProcessWhenMessageWithoutReferenceWithoutDefaultBranch()
 {
     $message = new Message(self::DUMMY_UNIQUE_ID, self::DUMMY_MESSAGE_ID, self::DUMMY_SUBJECT, self::DUMMY_CONTENT, $this->getDummyFrom(), self::DUMMY_MESSAGE_TO);
     $assigneeId = 1;
     $diamanteUser = $this->getReporter(1);
     $this->userService->expects($this->once())->method('getUserByEmail')->with($this->equalTo(self::DUMMY_MESSAGE_FROM))->will($this->returnValue($diamanteUser));
     $this->configManager->expects($this->once())->method('get')->with($this->equalTo('diamante_desk.default_branch'))->will($this->returnValue(1));
     $this->branchService->expects($this->once())->method('getBranch')->with($this->equalTo(1))->will($this->returnValue($this->defaultBranch));
     $this->defaultBranch->expects($this->any())->method('getDefaultAssigneeId')->will($this->returnValue($assigneeId));
     $reporter = $this->getReporter($diamanteUser->getId());
     $this->messageReferenceService->expects($this->once())->method('createTicket')->with($this->equalTo($message->getMessageId()), self::DUMMY_BRANCH_ID, $message->getSubject(), $message->getContent(), $reporter, $assigneeId);
     $this->ticketStrategy->process($message);
 }
 /**
  * Get list of Diamante tables to purge data from
  *
  * @return array
  */
 protected function getTablesList()
 {
     $entitiesMetadata = array($this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Branch::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\BranchEmailConfiguration::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Ticket::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Comment::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\Attachment::getClassName()), $this->entityManager->getClassMetadata(\Diamante\DeskBundle\Entity\TicketHistory::getClassName()), $this->entityManager->getClassMetadata('\\Oro\\Bundle\\TagBundle\\Entity\\Tag'), $this->entityManager->getClassMetadata('\\Oro\\Bundle\\TagBundle\\Entity\\Tagging'));
     $toPurge = array();
     $quoteStrategy = new DefaultQuoteStrategy();
     /** @var $entity \Doctrine\ORM\Mapping\ClassMetadata */
     foreach ($entitiesMetadata as $entity) {
         $tableName = $entity->getTableName();
         $toPurge[] = $tableName;
         foreach ($entity->getAssociationMappings() as $assoc) {
             if (isset($assoc['joinTable'])) {
                 $toPurge[] = $quoteStrategy->getJoinTableName($assoc, $entity, $this->dbPlatform);
             }
         }
     }
     return $toPurge;
 }
 public function __construct($id, $name, $description, Logo $logo = null, $tags = null)
 {
     parent::__construct($name, $description, $logo, $tags);
     $this->id = $id;
 }