Skip to content

Instantly share code, notes, and snippets.

@mbessolov mbessolov/BAP-18183 Secret

Created Feb 8, 2019
Embed
What would you like to do?
diff --git a/package/platform/src/Oro/Bundle/ActivityListBundle/Entity/Manager/ActivityListManager.php b/package/platform/src/Oro/Bundle/ActivityListBundle/Entity/Manager/ActivityListManager.php
index 38ff454131f7..d1fd737d03af 100644
--- a/package/platform/src/Oro/Bundle/ActivityListBundle/Entity/Manager/ActivityListManager.php
+++ b/package/platform/src/Oro/Bundle/ActivityListBundle/Entity/Manager/ActivityListManager.php
@@ -8,6 +8,7 @@
use Oro\Bundle\ActivityListBundle\Entity\Repository\ActivityListRepository;
use Oro\Bundle\ActivityListBundle\Event\ActivityListPreQueryBuildEvent;
use Oro\Bundle\ActivityListBundle\Model\ActivityListGroupProviderInterface;
+use Oro\Bundle\ActivityListBundle\Model\ActivityListProviderInterface;
use Oro\Bundle\ActivityListBundle\Provider\ActivityListChainProvider;
use Oro\Bundle\ActivityListBundle\Provider\ActivityListIdProvider;
use Oro\Bundle\ActivityListBundle\Tools\ActivityListEntityConfigDumperExtension;
@@ -197,11 +198,15 @@ public function getEntityViewModel(ActivityList $entity, $targetEntityData = [])
return null;
}
- $activity = $this->doctrineHelper->getEntity(
+ $activity = $this->doctrineHelper->getEntity(
$entity->getRelatedActivityClass(),
$entity->getRelatedActivityId()
);
+ if (!$activity) {
+ return null;
+ }
+
$ownerName = '';
$ownerId = '';
$owner = $entity->getOwner();
@@ -222,7 +227,7 @@ public function getEntityViewModel(ActivityList $entity, $targetEntityData = [])
}
}
- $relatedActivityEntities = $this->getRelatedActivityEntities($entity, $entityProvider);
+ $relatedActivityEntities = $this->getRelatedActivityEntities($entity, $entityProvider, $activity);
$numberOfComments = $this->commentManager->getCommentCount(
$entity->getRelatedActivityClass(),
$relatedActivityEntities
@@ -401,25 +406,23 @@ private function getGroupedActivityListIds($entity, $targetActivityClass, $targe
/**
* @param ActivityList $entity
- * @param object $entityProvider
+ * @param ActivityListProviderInterface $entityProvider
+ * @param $activity
*
* @return array
*/
- protected function getRelatedActivityEntities(ActivityList $entity, $entityProvider)
- {
- $relatedActivityEntities = [$entity];
- if ($entityProvider instanceof ActivityListGroupProviderInterface) {
- $relationEntity = $this->doctrineHelper->getEntity(
- $entity->getRelatedActivityClass(),
- $entity->getRelatedActivityId()
- );
- $relatedActivityEntities = $entityProvider->getGroupedEntities($relationEntity);
- if (count($relatedActivityEntities) === 0) {
- $relatedActivityEntities = [$entity];
- }
+ protected function getRelatedActivityEntities(
+ ActivityList $entity,
+ ActivityListProviderInterface $entityProvider,
+ $activity
+ ) {
+ if (!$entityProvider instanceof ActivityListGroupProviderInterface) {
+ return [$entity];
}
- return $relatedActivityEntities;
+ $relatedActivityEntities = $entityProvider->getGroupedEntities($activity);
+
+ return count($relatedActivityEntities) > 0 ? $relatedActivityEntities : [$entity];
}
/**
diff --git a/package/platform/src/Oro/Bundle/EmailBundle/Provider/EmailActivityListProvider.php b/package/platform/src/Oro/Bundle/EmailBundle/Provider/EmailActivityListProvider.php
index 38e439174476..cf8c56e37440 100644
--- a/package/platform/src/Oro/Bundle/EmailBundle/Provider/EmailActivityListProvider.php
+++ b/package/platform/src/Oro/Bundle/EmailBundle/Provider/EmailActivityListProvider.php
@@ -17,6 +17,7 @@
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;
use Oro\Bundle\EmailBundle\Entity\EmailUser;
use Oro\Bundle\EmailBundle\Entity\Provider\EmailThreadProvider;
+use Oro\Bundle\EmailBundle\Exception\InvalidArgumentException;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\EntityBundle\Provider\EntityNameResolver;
use Oro\Bundle\EntityConfigBundle\Config\ConfigManager;
@@ -35,7 +36,7 @@
* For the Email activity in the case when EmailAddress does not have owner(User|Organization),
* we are trying to extract Organization from the current logged user.
*
- * @todo Should be refactored in the BAP-8520
+ * Will be refactored in the BAP-8520
* @see EmailActivityListProvider::isApplicable
* @see EmailActivityListProvider::getOrganization
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
@@ -347,6 +348,19 @@ public function isCommentsEnabled($entityClass)
public function getGroupedEntities($entity, $associatedEntityClass = null, $associatedEntityId = null): array
{
/** @var Email $entity */
+ if (!$entity instanceof Email) {
+ throw new InvalidArgumentException(
+ sprintf(
+ 'Argument must be instance of "%s", "%s" given',
+ Email::class,
+ is_object($entity) ? ClassUtils::getClass($entity) : gettype($entity)
+ )
+ );
+ }
+
+ if (null === $entity->getThread()) {
+ return [];
+ }
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->doctrineRegistryLink->getService()
@@ -358,12 +372,10 @@ public function getGroupedEntities($entity, $associatedEntityClass = null, $asso
'WITH',
'a.relatedActivityId = e.id and a.relatedActivityClass = :class'
)
- ->setParameter('class', self::ACTIVITY_CLASS);
- if (null !== $entity->getThread()) {
- $queryBuilder
- ->andWhere('e.thread = :thread')
- ->setParameter('thread', $entity->getThread());
- }
+ ->andWhere('e.thread = :thread')
+ ->setParameter('class', self::ACTIVITY_CLASS)
+ ->setParameter('thread', $entity->getThread());
+
if ($associatedEntityClass && $associatedEntityId) {
$associationName = ExtendHelper::buildAssociationName(
$associatedEntityClass,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.