duplicate with links
This commit is contained in:
@@ -37,6 +37,8 @@ class TargetList extends \Espo\Services\Record
|
||||
{
|
||||
protected $noEditAccessRequiredLinkList = ['accounts', 'contacts', 'leads', 'users'];
|
||||
|
||||
protected $duplicatingLinkList = ['accounts', 'contacts', 'leads', 'users'];
|
||||
|
||||
public function loadAdditionalFields(Entity $entity)
|
||||
{
|
||||
parent::loadAdditionalFields($entity);
|
||||
|
||||
@@ -81,6 +81,8 @@ class Record extends \Espo\Core\Services\Base
|
||||
|
||||
protected $checkForDuplicatesInUpdate = false;
|
||||
|
||||
protected $duplicatingLinkList = [];
|
||||
|
||||
const FOLLOWERS_LIMIT = 4;
|
||||
|
||||
public function __construct()
|
||||
@@ -542,6 +544,7 @@ class Record extends \Espo\Core\Services\Base
|
||||
|
||||
if ($this->storeEntity($entity)) {
|
||||
$this->afterCreate($entity, $data);
|
||||
$this->afterCreateProcessDuplicating($entity, $data);
|
||||
$this->prepareEntityForOutput($entity);
|
||||
return $entity;
|
||||
}
|
||||
@@ -549,7 +552,6 @@ class Record extends \Espo\Core\Services\Base
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
|
||||
public function updateEntity($id, $data)
|
||||
{
|
||||
unset($data['deleted']);
|
||||
@@ -1501,7 +1503,33 @@ class Record extends \Espo\Core\Services\Base
|
||||
}
|
||||
}
|
||||
|
||||
$attributes['_duplicatingEntityId'] = $id;
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
protected function afterCreateProcessDuplicating(Entity $entity, $data)
|
||||
{
|
||||
if (isset($data['_duplicatingEntityId'])) {
|
||||
$this->duplicateLinks($entity, $data['_duplicatingEntityId']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function duplicateLinks(Entity $entity, $duplicatingEntityId)
|
||||
{
|
||||
if (!$duplicatingEntityId) return;
|
||||
$duplicatingEntity = $this->getEntityManager()->getEntity($entity->getEntityType(), $duplicatingEntityId);
|
||||
if (!$duplicatingEntity) return;
|
||||
if (!$this->getAcl()->check($duplicatingEntity, 'read')) return;
|
||||
|
||||
$repository = $this->getRepository();
|
||||
|
||||
foreach ($this->duplicatingLinkList as $link) {
|
||||
$linkedList = $repository->findRelated($duplicatingEntity, $link);
|
||||
foreach ($linkedList as $linked) {
|
||||
$repository->relate($entity, $link, $linked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user