/** * {@inheritdoc} */ protected function beforeProcessEntity($entity) { if ($entity instanceof OriginAwareInterface) { /** @var Channel $channel */ $channel = $this->databaseHelper->getEntityReference($entity->getChannel()); $this->ownerHelper->populateChannelOwner($entity, $channel); } return parent::beforeProcessEntity($entity); }
/** * @param StrategyEvent $event */ public function onProcessAfter(StrategyEvent $event) { $entity = $event->getEntity(); if ($entity instanceof GitHubIssue && $entity->getAssignedTo()) { // Add activity to the related Partner entity /** @var GitHubAccount $githubAccount */ $githubAccount = $entity->getAssignedTo(); $this->activityManager->addActivityTarget($entity, $githubAccount->getPartner()); // Populate entity owner from the Integration settings $this->defaultOwnerHelper->populateChannelOwner($entity, $entity->getChannel()); } }
/** * {@inheritdoc} */ protected function executeAction($context) { $entity = $this->contextAccessor->getValue($context, $this->attribute); if (!is_object($entity)) { throw new InvalidParameterException(sprintf('Action "%s" expects an entity in parameter "attribute", %s is given.', self::NAME, gettype($entity))); } $integration = $this->contextAccessor->getValue($context, $this->integration); if (!$integration instanceof Integration) { throw new InvalidParameterException(sprintf('Action "%s" expects %s in parameter "integration", %s is given.', self::NAME, 'Oro\\Bundle\\IntegrationBundle\\Entity\\Channel', is_object($integration) ? get_class($integration) : gettype($integration))); } $this->defaultOwnerHelper->populateChannelOwner($entity, $integration); }
/** * @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); }