stream noteRelate

This commit is contained in:
Yuri Kuznetsov
2019-11-21 11:09:57 +02:00
parent 927a580dce
commit c415ce677d
2 changed files with 35 additions and 37 deletions
+2 -37
View File
@@ -371,48 +371,13 @@ class Stream extends \Espo\Core\Hooks\Base
if (
$this->getMetadata()->get(['entityDefs', $entityType, 'links', $link, 'audited'])
) {
$n = $this->getEntityManager()->getRepository('Note')->where(array(
'type' => 'Relate',
'parentId' => $entity->id,
'parentType' => $entityType,
'relatedId' => $foreignEntity->id,
'relatedType' => $foreignEntity->getEntityType()
))->findOne();
if (!$n) {
$note = $this->getEntityManager()->getEntity('Note');
$note->set(array(
'type' => 'Relate',
'parentId' => $entity->id,
'parentType' => $entityType,
'relatedId' => $foreignEntity->id,
'relatedType' => $foreignEntity->getEntityType()
));
$this->getEntityManager()->saveEntity($note);
}
$this->getStreamService()->noteRelate($foreignEntity, $entityType, $entity->id);
}
$foreignLink = $entity->getRelationParam($link, 'foreign');
if ($this->getMetadata()->get(['entityDefs', $foreignEntity->getEntityType(), 'links', $foreignLink, 'audited'])) {
$n = $this->getEntityManager()->getRepository('Note')->where(array(
'type' => 'Relate',
'parentId' => $foreignEntity->id,
'parentType' => $foreignEntity->getEntityType(),
'relatedId' => $entity->id,
'relatedType' => $entityType
))->findOne();
if (!$n) {
$note = $this->getEntityManager()->getEntity('Note');
$note->set(array(
'type' => 'Relate',
'parentId' => $foreignEntity->id,
'parentType' => $foreignEntity->getEntityType(),
'relatedId' => $entity->id,
'relatedType' => $entityType
));
$this->getEntityManager()->saveEntity($note);
}
$this->getStreamService()->noteRelate($entity, $foreignEntity->getEntityType(), $foreignEntity->id);
}
}
}
+33
View File
@@ -1321,6 +1321,39 @@ class Stream extends \Espo\Core\Services\Base
$this->getEntityManager()->saveEntity($note, $o);
}
public function noteRelate(Entity $entity, $parentType, $parentId, array $options = [])
{
$entityType = $entity->getEntityType();
$existing = $this->getEntityManager()->getRepository('Note')->select(['id'])->where([
'type' => 'Relate',
'parentId' => $parentId,
'parentType' => $parentType,
'relatedId' => $entity->id,
'relatedType' => $entityType,
])->findOne();
if ($existing) return false;
$note = $this->getEntityManager()->getEntity('Note');
$note->set([
'type' => 'Relate',
'parentId' => $parentId,
'parentType' => $parentType,
'relatedType' => $entityType,
'relatedId' => $entity->id,
]);
$this->processNoteTeamsUsers($note, $entity);
$o = [];
if (!empty($options['createdById'])) {
$o['createdById'] = $options['createdById'];
}
$this->getEntityManager()->saveEntity($note, $o);
}
public function noteAssign(Entity $entity, array $options = [])
{
$note = $this->getEntityManager()->getEntity('Note');