Example #1
0
 /**
  * Populate owner to target entity based on integration configuration and entity's ownership type
  *
  * @param object      $entity
  * @param Integration $integration
  */
 public function populateChannelOwner($entity, Integration $integration)
 {
     $defaultUserOwner = $integration->getDefaultUserOwner();
     $className = ClassUtils::getClass($entity);
     $doctrineMetadata = $this->getEm()->getClassMetadata($className);
     $ownershipMetadata = $this->getMetadata($className);
     if ($defaultUserOwner && $ownershipMetadata->isBasicLevelOwned()) {
         $defaultUserOwner = $this->ensureNotDetached($defaultUserOwner);
         $doctrineMetadata->setFieldValue($entity, $ownershipMetadata->getOwnerFieldName(), $defaultUserOwner);
     }
     $defaultOrganization = $integration->getOrganization();
     if ($defaultOrganization && $ownershipMetadata->getGlobalOwnerFieldName()) {
         $defaultOrganization = $this->ensureNotDetached($defaultOrganization);
         $doctrineMetadata->setFieldValue($entity, $ownershipMetadata->getGlobalOwnerFieldName(), $defaultOrganization);
     }
 }
 /**
  * @dataProvider defaultIntegrationOwnerProvider
  *
  * @param Integration $integration
  * @param string      $ownerType
  * @param bool        $expectedReload
  * @param bool        $expectedSet
  * @param bool        $expectedSetOrganization
  */
 public function testPopulateChannelOwner(Integration $integration, $ownerType, $expectedReload, $expectedSet, $expectedSetOrganization = false)
 {
     $entity = new \stdClass();
     $owner = $integration->getDefaultUserOwner();
     $organization = $integration->getOrganization();
     $doctrineMetadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($doctrineMetadata));
     if ($expectedReload) {
         $this->uow->expects($this->once())->method('getEntityState')->with($this->identicalTo($owner))->will($this->returnValue(UnitOfWork::STATE_DETACHED));
         $this->em->expects($this->once())->method('find')->with($this->equalTo(get_class($owner)))->will($this->returnValue($owner));
     }
     $ownerMetadata = new OwnershipMetadata($ownerType, self::USER_OWNER_FIELD_NAME, self::USER_OWNER_COLUMN_NAME, self::ORGANIZATION_FIELD_NAME);
     $this->metadataProvider->expects($this->any())->method('getMetadata')->with(get_class($entity))->will($this->returnValue($ownerMetadata));
     if ($expectedSet) {
         $doctrineMetadata->expects($this->once())->method('setFieldValue')->with($this->identicalTo($entity), self::USER_OWNER_FIELD_NAME, $this->identicalTo($owner));
     } elseif ($expectedSetOrganization) {
         $doctrineMetadata->expects($this->once())->method('setFieldValue')->with($this->identicalTo($entity), self::ORGANIZATION_FIELD_NAME, $this->identicalTo($organization));
     } else {
         $doctrineMetadata->expects($this->never())->method('setFieldValue');
     }
     $this->helper->populateChannelOwner($entity, $integration);
 }
Example #3
0
 /**
  * @param Integration $integration
  */
 protected function updateToken(Integration $integration)
 {
     $securityContext = $this->getSecurityContext();
     $token = $securityContext->getToken();
     if (!$token) {
         $token = new ConsoleToken();
         $this->getSecurityContext()->setToken($token);
     }
     $token->setOrganizationContext($integration->getOrganization());
 }